Skip to content

Commit

Permalink
added themed-type option
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityblast committed Sep 27, 2010
1 parent 3c3eede commit a7aea2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ You can specify the template engine with `--engine=name` option, where name can

If you have something like `map.resource :dashboard` in your `routes.rb` file, you can use the `--type=text` to generate a view with just text:

script/generate themed homes --type=text
rails g web_app_theme:themed dashboards --themed-type=text

If you want to show form error messages inside the generated forms, use the following code inside your `environment.rb`

Expand Down
22 changes: 15 additions & 7 deletions lib/generators/web_app_theme/themed/themed_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ThemedGenerator < Rails::Generators::Base
class_option :layout, :type => :string, :desc => 'Specify the layout name'
class_option :engine, :type => :string, :default => 'erb', :desc => 'Specify the template engine'
class_option :will_paginate, :type => :boolean, :default => false, :desc => 'Specify if you use will_paginate'
class_option :themed_type, :type => :string, :default => 'crud', :desc => 'Specify the themed type, crud or text. Default is crud'

def initialize(args, *options)
super(args, *options)
Expand Down Expand Up @@ -82,14 +83,21 @@ def extract_modules(name)

def generate_views
views = {
'view_tables.html.erb' => File.join('app/views', @controller_file_path, "index.html.#{options.engine}"),
'view_new.html.erb' => File.join('app/views', @controller_file_path, "new.html.#{options.engine}"),
'view_edit.html.erb' => File.join('app/views', @controller_file_path, "edit.html.#{options.engine}"),
'view_form.html.erb' => File.join('app/views', @controller_file_path, "_form.html.#{options.engine}"),
'view_show.html.erb' => File.join('app/views', @controller_file_path, "show.html.#{options.engine}"),
'view_sidebar.html.erb' => File.join('app/views', @controller_file_path, "_sidebar.html.#{options.engine}")
'crud' => {
'view_tables.html.erb' => File.join('app/views', @controller_file_path, "index.html.#{options.engine}"),
'view_new.html.erb' => File.join('app/views', @controller_file_path, "new.html.#{options.engine}"),
'view_edit.html.erb' => File.join('app/views', @controller_file_path, "edit.html.#{options.engine}"),
'view_form.html.erb' => File.join('app/views', @controller_file_path, "_form.html.#{options.engine}"),
'view_show.html.erb' => File.join('app/views', @controller_file_path, "show.html.#{options.engine}"),
'view_sidebar.html.erb' => File.join('app/views', @controller_file_path, "_sidebar.html.#{options.engine}")
},
'text' => {
'view_text.html.erb' => File.join('app/views', @controller_file_path, "show.html.#{options.engine}"),
'view_sidebar.html.erb' => File.join('app/views', @controller_file_path, "_sidebar.html.#{options.engine}")
}
}
options.engine == 'haml' ? generate_haml_views(views) : generate_erb_views(views)
selected_views = views[options.themed_type]
options.engine == 'haml' ? generate_haml_views(selected_views) : generate_erb_views(selected_views)
end

def generate_erb_views(views)
Expand Down

0 comments on commit a7aea2b

Please sign in to comment.