lib/glimmer/rake_task/scaffold.rb in glimmer-dsl-libui-0.9.4 vs lib/glimmer/rake_task/scaffold.rb in glimmer-dsl-libui-0.9.5

- old
+ new

@@ -153,11 +153,11 @@ mkdir 'app' write "app/#{file_name(app_name)}.rb", app_main_file(app_name) mkdir_p "app/#{file_name(app_name)}/model" mkdir_p "app/#{file_name(app_name)}/view" custom_window(class_name(app_name), current_dir_name, window_type, custom_window_class_name: 'Application') - application_model(current_dir_name) + app_model(current_dir_name) mkdir_p 'icons/windows' icon_file = "icons/windows/#{human_name(app_name)}.ico" cp File.expand_path('../../../../icons/scaffold_app.ico', __FILE__), icon_file puts "Created #{current_dir_name}/#{icon_file}" @@ -366,11 +366,11 @@ puts 'Run `rake` to execute specs.' puts 'Run `rake build` to build gem.' puts 'Run `rake release` to release into rubygems.org once ready.' end - def application_model(current_dir_name) + def app_model(current_dir_name) model_name = 'Greeting' namespace ||= current_dir_name root_dir = File.exist?('app') ? 'app' : 'lib' parent_dir = "#{root_dir}/#{file_name(namespace)}/model" return puts("The file '#{parent_dir}/#{file_name(model_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(model_name)}.rb") @@ -702,17 +702,25 @@ ## Add options like the following to configure CustomControl by outside consumers # # options :custom_text, :background_color # option :foreground_color, default: :red + + # Replace example options with your own options + option :model + option :attributes ## Use before_body block to pre-initialize variables to use in body # # - # before_body do - # - # end + before_body do + # Replace example code with your own before_body code + default_model_attributes = [:first_name, :last_name, :email] + default_model_class = Struct.new(*default_model_attributes) + self.model ||= default_model_class.new + self.attributes ||= default_model_attributes + end ## Use after_body block to setup observers for controls in body # # after_body do # @@ -723,12 +731,17 @@ ## If you want to add a window as the top-most control, ## consider creating a custom window instead ## (Glimmer::LibUI::CustomWindow offers window convenience methods, like show and hide) # body { - # Replace example content below with custom control content - label { - background :red + # Replace example content (model_form custom control) with your own custom control content. + form { + attributes.each do |attribute| + entry { |e| + label attribute.to_s.underscore.split('_').map(&:capitalize).join(' ') + text <=> [model, attribute] + } + end } } end end