class Bootswatch::Generators::ThemedGenerator

Public Class Methods

new(args, *options) click to toggle source
Calls superclass method
# File lib/generators/bootswatch/themed/themed_generator.rb, line 13
def initialize(args, *options)
  super(args, *options)
  initialize_views_variables
end

Public Instance Methods

copy_views() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 18
def copy_views
  generate_views
end

Protected Instance Methods

columns() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 55
def columns
  begin
    excluded_column_names = %w[id created_at updated_at]
    @model_name.constantize.columns.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
  rescue NoMethodError
    @model_name.constantize.fields.collect{|c| c[1]}.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type.to_s)}
  end
end
controller_routing_path() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 31
def controller_routing_path
  @controller_routing_path
end
ext() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 90
def ext
  ::Rails.application.config.generators.options[:rails][:template_engine] || :erb
end
extract_modules(name) click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 64
def extract_modules(name)
  modules = name.include?('/') ? name.split('/') : name.split('::')
  name    = modules.pop
  path    = modules.map { |m| m.underscore }
  file_path = (path + [name.underscore]).join('/')
  nesting = modules.map { |m| m.camelize }.join('::')
  [name, path, file_path, nesting, modules.size]
end
form_builder() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 94
def form_builder
  defined?(::SimpleForm) ? 'simple_form/' : ''
end
generate_erb(views) click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 84
def generate_erb(views)
  views.each do |template_name, output_path|
    template template_name, output_path
  end
end
generate_views() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 73
def generate_views
  views = {
    "index.html.#{ext}"                 => File.join('app/views', @controller_file_path, "index.html.#{ext}"),
    "new.html.#{ext}"                   => File.join('app/views', @controller_file_path, "new.html.#{ext}"),
    "edit.html.#{ext}"                  => File.join('app/views', @controller_file_path, "edit.html.#{ext}"),
    "#{form_builder}_form.html.#{ext}"  => File.join('app/views', @controller_file_path, "_form.html.#{ext}"),
    "show.html.#{ext}"                  => File.join('app/views', @controller_file_path, "show.html.#{ext}")}
  selected_views = views
  options.engine == generate_erb(selected_views)
end
initialize_views_variables() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 24
def initialize_views_variables
  @base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(controller_path)
  @controller_routing_path = @controller_file_path.gsub(/\//, '_')
  @model_name = @controller_class_nesting + "::#{@base_name.singularize.camelize}" unless @model_name
  @model_name = @model_name.camelize
end
model_name() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 39
def model_name
  @model_name
end
plural_model_name() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 43
def plural_model_name
  @model_name.pluralize
end
plural_resource_name() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 51
def plural_resource_name
  resource_name.pluralize
end
resource_name() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 47
def resource_name
  @model_name.demodulize.underscore
end
singular_controller_routing_path() click to toggle source
# File lib/generators/bootswatch/themed/themed_generator.rb, line 35
def singular_controller_routing_path
  @controller_routing_path.singularize
end