Class: Infold::Views::IndexGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/infold/views/index_generator.rb

Instance Method Summary collapse

Instance Method Details

#csv_fileObject



33
34
35
# File 'lib/generators/infold/views/index_generator.rb', line 33

def csv_file
  template "views/index.csv.ruby", Rails.root.join("app/views/admin/#{name.underscore.pluralize}/index.csv.ruby"), force: true
end

#index_fileObject



21
22
23
# File 'lib/generators/infold/views/index_generator.rb', line 21

def index_file
  template "views/index.haml", Rails.root.join("app/views/admin/#{name.underscore.pluralize}/index.html.haml"), force: true
end

#index_row_fileObject



25
26
27
# File 'lib/generators/infold/views/index_generator.rb', line 25

def index_row_file
  template "views/_index_row.haml", Rails.root.join("app/views/admin/#{name.underscore.pluralize}/_index_row.html.haml"), force: true
end

#index_turbo_frame_fileObject



29
30
31
# File 'lib/generators/infold/views/index_generator.rb', line 29

def index_turbo_frame_file
  template "views/index.html+turbo_frame.haml", Rails.root.join("app/views/admin/#{name.underscore.pluralize}/index.html+turbo_frame.haml"), force: true
end

#setupObject



12
13
14
15
16
17
18
19
# File 'lib/generators/infold/views/index_generator.rb', line 12

def setup
  resource_name = name.camelize.singularize
  db_schema_file = Rails.root.join('db/schema.rb')
  db_schema = DbSchema.new(File.exist?(db_schema_file) ? File.read(db_schema_file) : nil)
  yaml = YAML.load_file(Rails.root.join("config/infold/#{resource_name.underscore}.yml"))
  resource = YamlReader.generate_resource(resource_name, yaml, db_schema)
  @writer = IndexWriter.new(resource)
end