class Fullstack::Admin::ScaffoldGenerator

Public Instance Methods

add_routes() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 15
def add_routes
  routes_rb = Rails.root.join('config', 'routes.rb') 
  
  altered_lines = []
  File.open(routes_rb) do |file|
    lines = file.read.split("\n")
    lines.each do |line|
      if line =~ /^ \s* namespace \s+ :#{scope} \s+ do /x
        leading_space = line.match(/^(\s*)/)[1] + "  "
        line = [line,  "#{leading_space}resources :#{plural_name}, :except => [:show]"].join("\n")
      end
      altered_lines << line
    end
  end
  
  File.open(routes_rb, 'w') do |file|
   file.write(altered_lines.join("\n"))
  end
  
  say("addedd 'resources :#{plural_name}, :except => [:show]' to namespace ':#{scope}' in routes.rb")
end
append_to_menu() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 46
      def append_to_menu
        placeholder_text = "FULLSTACK_PLACEHOLDER"
        gsub_file(Rails.root.join('app', 'views', scope, "shared", "_nav.html.erb"), /\<\!-- #{placeholder_text} --\>\n/) do
<<-str
      <%= nav_item t('active_record.models.#{plural_name}', :default => "#{controller_class_name}"), #{scope}_#{plural_name}_path %>
      <!-- #{placeholder_text} -->
          
str
        end
      end
create_controller_files() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 11
def create_controller_files
  template 'controller.rb', File.join("app/controllers/", scope, "#{file_name.pluralize}_controller.rb")
end
create_views() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 37
def create_views
  if options[:views]
    directory('views', Rails.root.join('app', 'views', scope, plural_name))
    if has_timestamps? || title_column
      template "_filter.html.erb", Rails.root.join('app', 'views', scope, plural_name, "_filter.html.erb")
    end
  end
end

Protected Instance Methods

class_name() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 59
def class_name
  name.singularize.camelize
end
collection_name() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 104
def collection_name
  file_name.pluralize
end
content?() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 116
def content?
  options[:content]
end
controller_class_name() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 92
def controller_class_name
  class_name.pluralize
end
file_name() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 108
def file_name
  name
end
has_timestamps?() click to toggle source

def inputs

exclude_attributes = model.protected_attributes.to_a + %W(created_at updated_at slug)    
columns = model.columns_hash.map {|k, v| [k, v.type]}.delete_if {|k, t| exclude_attributes.include?(k)}

end

# File lib/generators/fullstack/admin/scaffold_generator.rb, line 84
def has_timestamps?
  model.columns_hash["created_at"]
end
model() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 112
def model
  class_name.constantize
end
plural_name() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 67
def plural_name
  name.pluralize
end
resource_class_name() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 96
def resource_class_name
  class_name.singularize
end
resource_name() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 100
def resource_name
  file_name.singularize
end
scope() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 63
def scope
  @scope ||= "admin"
end
scope_class() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 75
def scope_class
  scope.camelize
end
singular_name() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 71
def singular_name
  name.singularize
end
title_column() click to toggle source
# File lib/generators/fullstack/admin/scaffold_generator.rb, line 88
def title_column
  ( model.column_names.map {|c| } & %W(title name label browser_title seo_title seo_name key claim email) ).first
end