Class: Flexi::Generators::LayoutGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/flexi/layout/layout_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



13
14
15
# File 'lib/generators/flexi/layout/layout_generator.rb', line 13

def app_name
  @app_name
end

#container_classObject (readonly)

Returns the value of attribute container_class.



13
14
15
# File 'lib/generators/flexi/layout/layout_generator.rb', line 13

def container_class
  @container_class
end

Instance Method Details

#add_stylesheetsObject



26
27
28
29
30
31
32
33
# File 'lib/generators/flexi/layout/layout_generator.rb', line 26

def add_stylesheets
  copy_file 'layout.css', 'app/assets/stylesheets/layout.css'
  if File.exist?('app/assets/stylesheets/application.css')
    insert_into_file "app/assets/stylesheets/application.css", " *= require layout\n", :after => "require_self\n"
  else
    copy_file "application.css", "app/assets/stylesheets/application.css"
  end
end

#copy_additional_filesObject



35
36
37
38
39
40
41
42
# File 'lib/generators/flexi/layout/layout_generator.rb', line 35

def copy_additional_files
  copy_file 'layout_helper.rb', 'app/helpers/layout_helper.rb'
  copy_file 'error_messages_helper.rb', 'app/helpers/error_messages_helper.rb'
  copy_file '_flash.html.erb', 'app/views/shared/_flash.html.erb'
  template '_sidebar.html.erb', 'app/views/layouts/_sidebar.html.erb'
  template '_navbar.html.erb', 'app/views/layouts/_navbar.html.erb'
  copy_file '_user_dropdown.html.erb', 'app/views/layouts/_user_dropdown.html.erb'
end

#generate_layoutObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/flexi/layout/layout_generator.rb', line 15

def generate_layout
  app = ::Rails.application
  @app_name = app.class.to_s.split("::").first
  @container_class = layout_type == "fluid" ? "container-fluid" : "container"
  template "layout.html.erb", "app/views/layouts/#{layout_name}.html.erb"
  generate "controller", "#{dashboard_name} index"
  remove_file "app/views/#{dashboard_name}/index.html.erb"
  copy_file "#{dashboard_name}.html.erb", "app/views/dashboard/index.html.erb"
  route "root :to => '#{dashboard_name}#index'"
end