root/lang/ruby/scaflute/scaflute.rb @ 30256

Revision 30256, 1.4 kB (checked in by rikeda, 6 years ago)

モジュール分離

Line 
1require 'erb'
2
3require 'script/string.rb'
4require 'script/table.rb'
5require 'script/column.rb'
6require 'script/schema.rb'
7require 'script/dfprop.rb'
8
9# DBFlute が生成したスキーマ情報を元に、
10# Teeda 用の CRUD ページを生成する scaffold スクリプト(予定)。
11
12module Main
13  def self.run()
14    tables = Schema.read_xml('templates/project-schema-sample.xml')
15    tables.each() do |table|
16      $table = table
17      $table.javaPackage = 'com.sample'
18      exec_file('templates/dxo.erb', "result/java/#{table.javaClass}Dxo.java")
19      exec_file('templates/page.erb', "result/java/Abstract#{table.javaClass}Page.java")
20      exec_file('templates/list.erb', "result/html/#{table.javaProperty}List.html")
21      exec_file('templates/list_page.erb', "result/java/#{table.javaClass}ListPage.java")
22      exec_file('templates/edit.erb', "result/html/#{table.javaProperty}Edit.html")
23      exec_file('templates/edit_page.erb', "result/java/#{table.javaClass}EditPage.java")
24      exec_file('templates/confirm.erb', "result/html/#{table.javaProperty}Confirm.html")
25      exec_file('templates/confirm_page.erb', "result/java/#{table.javaClass}ConfirmPage.java")
26    end
27  end
28
29private
30
31  def self.exec_file(file_name, output)
32    File.open(file_name, 'r') do |input|
33      str = input.read()
34      erb = ERB.new(str, nil, '-')
35      File.open(output, 'w+') do |f|
36        f.puts(erb.result)
37      end
38    end
39  end
40end
41
42Main.run()
Note: See TracBrowser for help on using the browser.