Class: Humdrum::Generators::LayoutGenerator

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

Instance Method Summary collapse

Instance Method Details

#application_nameObject

def config

args = options.dup
args.config_file ||= '.csvconverter.yaml'

config = YAML::load File.open(args[:file], 'r')

end



36
37
38
# File 'lib/rails/generators/humdrum/layout/layout_generator.rb', line 36

def application_name
  options.application_name
end

#frameworkObject



40
41
42
# File 'lib/rails/generators/humdrum/layout/layout_generator.rb', line 40

def framework
  options.framework
end

#generate_controllersObject



141
142
143
144
145
# File 'lib/rails/generators/humdrum/layout/layout_generator.rb', line 141

def generate_controllers
  template "controllers/application_controller.rb", "app/controllers/application_controller.rb"
  template "controllers/welcome_controller.rb", "app/controllers/welcome_controller.rb" unless options.skip_welcome_page?
  template "controllers/layout_name_controller.rb", "app/controllers/#{layout_name}_controller.rb"
end

#generate_graphicsObject

TODO - This section has to be optimized. All the assets should be organized under the framework folders. We should also use fontawesome irrespective of what the framework is



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rails/generators/humdrum/layout/layout_generator.rb', line 98

def generate_graphics
  unless options.skip_graphics?
    copy_file "images/favicon.ico", "app/assets/images/favicon.ico"
    case framework
    when "bootstrap3"
      #copy_file "images/glyphicons-halflings.png", "app/assets/images/glyphicons-halflings.png"
      #copy_file "images/glyphicons-halflings-white.png", "app/assets/images/glyphicons-halflings-white.png"
    when "bootstrap2"
      copy_file "images/glyphicons-halflings.png", "app/assets/images/glyphicons-halflings.png"
      copy_file "images/glyphicons-halflings-white.png", "app/assets/images/glyphicons-halflings-white.png"
    when "gumby"
      directory "images/fonts", "app/assets/images/fonts"
    end
  end
end

#generate_helpersObject



114
115
116
117
118
119
120
121
# File 'lib/rails/generators/humdrum/layout/layout_generator.rb', line 114

def generate_helpers
  template "helpers/title_helper.rb", "app/helpers/title_helper.rb"
  template "helpers/navigation_helper.rb", "app/helpers/navigation_helper.rb"
  template "helpers/meta_tags_helper.rb", "app/helpers/meta_tags_helper.rb"
  template "helpers/display_helper.rb", "app/helpers/display_helper.rb"
  template "helpers/params_parser_helper.rb", "app/helpers/params_parser_helper.rb"
  template "helpers/flash_helper.rb", "app/helpers/flash_helper.rb"
end

#generate_javascriptsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rails/generators/humdrum/layout/layout_generator.rb', line 78

def generate_javascripts
  unless options.skip_javascript?
    template "javascripts/application.js", "app/assets/javascripts/application.js"
    template "javascripts/validations/#{framework}/main.js", "app/assets/javascripts/validations/main.js"
    copy_file "javascripts/modernizr.2.6.2.js", "app/assets/javascripts/modernizr.2.6.2.js"
    case framework
    when "bootstrap3"
      copy_file "javascripts/bootstrap3/bootstrap.min.js", "app/assets/javascripts/bootstrap.min.js"
      copy_file "javascripts/bootstrap3/utilities.js", "app/assets/javascripts/utilities.js"
    when "bootstrap2"
      copy_file "javascripts/bootstrap2/bootstrap.min.js", "app/assets/javascripts/bootstrap.min.js"
      copy_file "javascripts/bootstrap2/utilities.js", "app/assets/javascripts/utilities.js"
    when "gumby"
      copy_file "javascripts/gumby/gumby.min.js", "app/assets/javascripts/gumby.min.js"
    end
  end
end

#generate_layoutObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/rails/generators/humdrum/layout/layout_generator.rb', line 123

def generate_layout
  
  template "views/#{framework}/layouts/application.html.erb", "app/views/layouts/application.html.erb" 
  template "views/#{framework}/layouts/application/_header.html.erb", "app/views/layouts/application/_header.html.erb"
  template "views/#{framework}/layouts/application/_footer.html.erb", "app/views/layouts/application/_footer.html.erb"
  template "views/#{framework}/layouts/application/_navbar.html.erb", "app/views/layouts/application/_navbar.html.erb"
  
  template "views/#{framework}/layouts/common/_flash_message.html.erb", "app/views/layouts/common/_flash_message.html.erb"
  template "views/#{framework}/layouts/common/_meta_tags.html.erb", "app/views/layouts/common/_meta_tags.html.erb"
  template "views/#{framework}/layouts/common/_overlays.html.erb", "app/views/layouts/common/_overlays.html.erb"
  
  template "views/#{framework}/layouts/layout_name.html.erb", "app/views/layouts/#{layout_name}.html.erb" 
  template "views/#{framework}/layouts/layout_name/_header.html.erb", "app/views/layouts/#{layout_name}/_header.html.erb"
  template "views/#{framework}/layouts/layout_name/_footer.html.erb", "app/views/layouts/#{layout_name}/_footer.html.erb"
  template "views/#{framework}/layouts/layout_name/_navbar.html.erb", "app/views/layouts/#{layout_name}/_navbar.html.erb"
    
end

#generate_routesObject



162
163
164
# File 'lib/rails/generators/humdrum/layout/layout_generator.rb', line 162

def generate_routes
  route("root :to => 'welcome#index'") unless options.skip_welcome_page
end

#generate_stylesheetsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rails/generators/humdrum/layout/layout_generator.rb', line 44

def generate_stylesheets
  unless options.skip_stylesheet?
    
    template "stylesheets/application.css", "app/assets/stylesheets/application.css"
    
    case framework
    when "bootstrap3"
      
      # Copy bootstrap css file
      copy_file "stylesheets/bootstrap3/bootstrap.css", "app/assets/stylesheets/bootstrap.css"
      
      # Its named overrides-bootstrap so that it loads after bootstrap.css
      copy_file "stylesheets/bootstrap3/overrides-bootstrap.css", "app/assets/stylesheets/overrides-bootstrap.css"
    when "bootstrap2"
      
      # Copy bootstrap css file
      copy_file "stylesheets/bootstrap2/bootstrap.css", "app/assets/stylesheets/bootstrap.css"
      copy_file "stylesheets/bootstrap2/bootstrap-responsive.css", "app/assets/stylesheets/bootstrap-responsive.css"
      
      # Its named overrides-bootstrap so that it loads after bootstrap.css
      copy_file "stylesheets/bootstrap2/overrides-bootstrap.css", "app/assets/stylesheets/overrides-bootstrap.css"
    when "gumby"
      
      # Copy gumby css file
      copy_file "stylesheets/gumby/gumby.css", "app/assets/stylesheets/gumby.css"
      copy_file "stylesheets/gumby/gumby-pagination.css", "app/assets/stylesheets/gumby-pagination.css"
      
      # Its named overrides-gumby so that it loads after gumby.css
      copy_file "stylesheets/gumby/overrides-gumby.css", "app/assets/stylesheets/overrides-gumby.css"
    end
    
  end
end

#generate_viewsObject



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/rails/generators/humdrum/layout/layout_generator.rb', line 147

def generate_views
  template "views/#{framework}/welcome/index.html.erb", "app/views/welcome/index.html.erb" unless options.skip_welcome_page?
  
  # Copy kaminari templates
  unless options.skip_kaminari?
    template "views/#{framework}/kaminari/_first_page.html.erb", "app/views/kaminari/_first_page.html.erb"
    template "views/#{framework}/kaminari/_gap.html.erb", "app/views/kaminari/_gap.html.erb"
    template "views/#{framework}/kaminari/_last_page.html.erb", "app/views/kaminari/_last_page.html.erb"
    template "views/#{framework}/kaminari/_next_page.html.erb", "app/views/kaminari/_next_page.html.erb"
    template "views/#{framework}/kaminari/_page.html.erb", "app/views/kaminari/_page.html.erb"
    template "views/#{framework}/kaminari/_paginator.html.erb", "app/views/kaminari/_paginator.html.erb"
    template "views/#{framework}/kaminari/_prev_page.html.erb", "app/views/kaminari/_prev_page.html.erb"
  end
end