flexi_generators 0.2.10 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +29 -0
  5. data/Rakefile +2 -16
  6. data/flexi_generators.gemspec +17 -114
  7. data/lib/flexi_generators.rb +11 -0
  8. data/lib/generators/flexi/config/config_generator.rb +25 -0
  9. data/lib/generators/flexi/config/templates/field_error.rb +9 -0
  10. data/lib/generators/flexi/config/templates/inflector_portuguese.rb +62 -0
  11. data/lib/generators/flexi/config/templates/pt-BR.yml +224 -0
  12. data/lib/generators/flexi/config/templates/will_paginate.rb +26 -0
  13. data/lib/generators/flexi/install/install_generator.rb +28 -0
  14. data/lib/generators/flexi/install/templates/application.css +15 -0
  15. data/lib/generators/flexi/install/templates/application.js +16 -0
  16. data/lib/generators/flexi/layout/layout_generator.rb +46 -0
  17. data/lib/generators/flexi/layout/templates/_flash.html.erb +4 -0
  18. data/lib/generators/flexi/layout/templates/_navbar.html.erb +6 -0
  19. data/lib/generators/flexi/layout/templates/_sidebar.html.erb +16 -0
  20. data/lib/generators/flexi/layout/templates/_user_dropdown.html.erb +11 -0
  21. data/lib/generators/flexi/layout/templates/application.css +16 -0
  22. data/lib/generators/flexi/layout/templates/dashboard.html.erb +49 -0
  23. data/lib/generators/flexi/layout/templates/error_messages_helper.rb +33 -0
  24. data/lib/generators/flexi/layout/templates/layout.css +8 -0
  25. data/lib/generators/flexi/layout/templates/layout.html.erb +76 -0
  26. data/lib/generators/flexi/layout/templates/layout_helper.rb +47 -0
  27. data/lib/generators/flexi/scaffold/scaffold_generator.rb +24 -109
  28. data/lib/generators/flexi/scaffold/templates/_form.html.erb +22 -0
  29. data/lib/generators/flexi/scaffold/templates/edit.html.erb +1 -0
  30. data/lib/generators/flexi/scaffold/templates/index.html.erb +36 -0
  31. data/lib/generators/flexi/scaffold/templates/new.html.erb +1 -0
  32. data/lib/generators/flexi/scaffold/templates/show.html.erb +21 -0
  33. data/lib/twitter-bootstrap/engine.rb +6 -0
  34. data/lib/twitter-bootstrap/railtie.rb +6 -0
  35. data/lib/twitter-bootstrap/version.rb +5 -0
  36. data/lib/version.rb +3 -0
  37. data/vendor/assets/images/glyphicons-halflings-white.png +0 -0
  38. data/vendor/assets/images/glyphicons-halflings.png +0 -0
  39. data/vendor/assets/javascripts/bootstrap.js +1825 -0
  40. data/vendor/assets/stylesheets/bootstrap-responsive.css +815 -0
  41. data/vendor/assets/stylesheets/bootstrap.css +4983 -0
  42. metadata +51 -89
  43. data/README.textile +0 -64
  44. data/VERSION +0 -1
  45. data/lib/generators/flexi.rb +0 -16
  46. data/lib/generators/flexi/auth/USAGE +0 -5
  47. data/lib/generators/flexi/auth/auth_generator.rb +0 -122
  48. data/lib/generators/flexi/auth/templates/authentication.rb +0 -55
  49. data/lib/generators/flexi/auth/templates/authlogic_session.rb +0 -2
  50. data/lib/generators/flexi/auth/templates/fixtures.yml +0 -24
  51. data/lib/generators/flexi/auth/templates/migration.rb +0 -16
  52. data/lib/generators/flexi/auth/templates/sessions_controller.rb +0 -26
  53. data/lib/generators/flexi/auth/templates/sessions_helper.rb +0 -2
  54. data/lib/generators/flexi/auth/templates/tests/testunit/sessions_controller.rb +0 -20
  55. data/lib/generators/flexi/auth/templates/tests/testunit/user.rb +0 -4
  56. data/lib/generators/flexi/auth/templates/tests/testunit/users_controller.rb +0 -23
  57. data/lib/generators/flexi/auth/templates/user.rb +0 -3
  58. data/lib/generators/flexi/auth/templates/users_controller.rb +0 -43
  59. data/lib/generators/flexi/auth/templates/users_helper.rb +0 -2
  60. data/lib/generators/flexi/auth/templates/views/erb/_error_messages.html.erb +0 -11
  61. data/lib/generators/flexi/auth/templates/views/erb/_menu.html.erb +0 -16
  62. data/lib/generators/flexi/auth/templates/views/erb/application.html.erb +0 -39
  63. data/lib/generators/flexi/auth/templates/views/erb/edit.html.erb +0 -24
  64. data/lib/generators/flexi/auth/templates/views/erb/index.html.erb +0 -27
  65. data/lib/generators/flexi/auth/templates/views/erb/login.html.erb +0 -22
  66. data/lib/generators/flexi/auth/templates/views/erb/new.html.erb +0 -24
  67. data/lib/generators/flexi/auth/templates/views/erb/show.html.erb +0 -16
  68. data/lib/generators/flexi/prepare/USAGE +0 -6
  69. data/lib/generators/flexi/prepare/prepare_generator.rb +0 -68
  70. data/lib/generators/flexi/prepare/templates/add.png +0 -0
  71. data/lib/generators/flexi/prepare/templates/admin_home_controller.rb +0 -6
  72. data/lib/generators/flexi/prepare/templates/admin_home_index.html.erb +0 -16
  73. data/lib/generators/flexi/prepare/templates/application.css +0 -279
  74. data/lib/generators/flexi/prepare/templates/application_helper.rb +0 -44
  75. data/lib/generators/flexi/prepare/templates/back.png +0 -0
  76. data/lib/generators/flexi/prepare/templates/bg.png +0 -0
  77. data/lib/generators/flexi/prepare/templates/bg2.png +0 -0
  78. data/lib/generators/flexi/prepare/templates/boxheader.gif +0 -0
  79. data/lib/generators/flexi/prepare/templates/btn-bg-hover.png +0 -0
  80. data/lib/generators/flexi/prepare/templates/btn-bg.png +0 -0
  81. data/lib/generators/flexi/prepare/templates/custom_field_error.rb +0 -12
  82. data/lib/generators/flexi/prepare/templates/delete.png +0 -0
  83. data/lib/generators/flexi/prepare/templates/edit.png +0 -0
  84. data/lib/generators/flexi/prepare/templates/inflector_portuguese.rb +0 -60
  85. data/lib/generators/flexi/prepare/templates/login.css +0 -142
  86. data/lib/generators/flexi/prepare/templates/login.html.erb +0 -26
  87. data/lib/generators/flexi/prepare/templates/logo.png +0 -0
  88. data/lib/generators/flexi/prepare/templates/menu.png +0 -0
  89. data/lib/generators/flexi/prepare/templates/messages/Thumbs.db +0 -0
  90. data/lib/generators/flexi/prepare/templates/messages/error.png +0 -0
  91. data/lib/generators/flexi/prepare/templates/messages/info.png +0 -0
  92. data/lib/generators/flexi/prepare/templates/messages/success.png +0 -0
  93. data/lib/generators/flexi/prepare/templates/messages/tip.png +0 -0
  94. data/lib/generators/flexi/prepare/templates/messages/warning.png +0 -0
  95. data/lib/generators/flexi/prepare/templates/pt-BR.yml +0 -206
  96. data/lib/generators/flexi/prepare/templates/routes.rb +0 -3
  97. data/lib/generators/flexi/prepare/templates/show.png +0 -0
  98. data/lib/generators/flexi/prepare/templates/site.css +0 -72
  99. data/lib/generators/flexi/prepare/templates/site.html.erb +0 -20
  100. data/lib/generators/flexi/prepare/templates/site_controller.rb +0 -9
  101. data/lib/generators/flexi/prepare/templates/site_helper.rb +0 -2
  102. data/lib/generators/flexi/prepare/templates/site_index.html.erb +0 -27
  103. data/lib/generators/flexi/prepare/templates/users.png +0 -0
  104. data/lib/generators/flexi/scaffold/USAGE +0 -5
  105. data/lib/generators/flexi/scaffold/templates/controller.rb +0 -43
  106. data/lib/generators/flexi/scaffold/templates/fixtures.yml +0 -9
  107. data/lib/generators/flexi/scaffold/templates/helper.rb +0 -2
  108. data/lib/generators/flexi/scaffold/templates/migration.rb +0 -14
  109. data/lib/generators/flexi/scaffold/templates/model.rb +0 -3
  110. data/lib/generators/flexi/scaffold/templates/tests/controller.rb +0 -50
  111. data/lib/generators/flexi/scaffold/templates/tests/helper.rb +0 -4
  112. data/lib/generators/flexi/scaffold/templates/tests/model.rb +0 -8
  113. data/lib/generators/flexi/scaffold/templates/views/erb/_error_messages.html.erb +0 -11
  114. data/lib/generators/flexi/scaffold/templates/views/erb/_form.html.erb +0 -13
  115. data/lib/generators/flexi/scaffold/templates/views/erb/edit.html.erb +0 -3
  116. data/lib/generators/flexi/scaffold/templates/views/erb/index.html.erb +0 -29
  117. data/lib/generators/flexi/scaffold/templates/views/erb/new.html.erb +0 -3
  118. data/lib/generators/flexi/scaffold/templates/views/erb/show.html.erb +0 -15
  119. data/template.rb +0 -15
@@ -0,0 +1,26 @@
1
+ require 'will_paginate/view_helpers/action_view'
2
+
3
+ module WillPaginate
4
+ module ActionView
5
+ def will_paginate(collection = nil, options = {})
6
+ options[:renderer] ||= BootstrapLinkRenderer
7
+ super.try :html_safe
8
+ end
9
+
10
+ class BootstrapLinkRenderer < LinkRenderer
11
+ protected
12
+
13
+ def html_container(html)
14
+ tag :div, tag(:ul, html), container_attributes
15
+ end
16
+
17
+ def page_number(page)
18
+ tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page)
19
+ end
20
+
21
+ def previous_or_next_page(page, text, classname)
22
+ tag :li, link(text, page || '#'), :class => [classname[0..3], classname, ('disabled' unless page)].join(' ')
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'rails/generators'
2
+
3
+ module Flexi
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ desc "This generator installs Twitter Bootstrap to Asset Pipeline"
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ def add_stylesheets
10
+ if File.exist?('app/assets/stylesheets/application.css')
11
+ insert_into_file "app/assets/stylesheets/application.css", " *= require bootstrap-responsive\n", :after => "require_self\n"
12
+ insert_into_file "app/assets/stylesheets/application.css", " *= require bootstrap\n", :after => "require_self\n"
13
+ else
14
+ copy_file "application.css", "app/assets/stylesheets/application.css"
15
+ end
16
+ end
17
+
18
+ def add_javascripts
19
+ if File.exist?('app/assets/javascripts/application.js')
20
+ insert_into_file "app/assets/javascripts/application.js", "//= require bootstrap\n", :after => "jquery_ujs\n"
21
+ else
22
+ copy_file "application.js", "app/assets/javascripts/application.js"
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require bootstrap
13
+ *= require bootstrap-responsive
14
+ *= require_tree .
15
+ */
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require bootstrap
16
+ //= require_tree .
@@ -0,0 +1,46 @@
1
+ require 'rails/generators'
2
+
3
+ module Flexi
4
+ module Generators
5
+ class LayoutGenerator < ::Rails::Generators::Base
6
+ desc "This generator generates layout file with navigation."
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ argument :layout_name, :type => :string, :default => "application"
10
+ argument :layout_type, :type => :string, :default => "fluid",
11
+ :banner => "*fixed or fluid"
12
+ argument :dashboard_name, :type => :string, :default => "dashboard"
13
+ attr_reader :app_name, :container_class
14
+
15
+ def generate_layout
16
+ app = ::Rails.application
17
+ @app_name = app.class.to_s.split("::").first
18
+ @container_class = layout_type == "fluid" ? "container-fluid" : "container"
19
+ template "layout.html.erb", "app/views/layouts/#{layout_name}.html.erb"
20
+ generate "controller", "#{dashboard_name} index"
21
+ remove_file "app/views/#{dashboard_name}/index.html.erb"
22
+ copy_file "#{dashboard_name}.html.erb", "app/views/dashboard/index.html.erb"
23
+ route "root :to => '#{dashboard_name}#index'"
24
+ end
25
+
26
+ def add_stylesheets
27
+ copy_file 'layout.css', 'app/assets/stylesheets/layout.css'
28
+ if File.exist?('app/assets/stylesheets/application.css')
29
+ insert_into_file "app/assets/stylesheets/application.css", " *= require layout\n", :after => "require_self\n"
30
+ else
31
+ copy_file "application.css", "app/assets/stylesheets/application.css"
32
+ end
33
+ end
34
+
35
+ def copy_additional_files
36
+ copy_file 'layout_helper.rb', 'app/helpers/layout_helper.rb'
37
+ copy_file 'error_messages_helper.rb', 'app/helpers/error_messages_helper.rb'
38
+ copy_file '_flash.html.erb', 'app/views/shared/_flash.html.erb'
39
+ template '_sidebar.html.erb', 'app/views/layouts/_sidebar.html.erb'
40
+ template '_navbar.html.erb', 'app/views/layouts/_navbar.html.erb'
41
+ copy_file '_user_dropdown.html.erb', 'app/views/layouts/_user_dropdown.html.erb'
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,4 @@
1
+ <div class="alert alert-<%= css %>">
2
+ <a class="close" data-dismiss="alert" href="#">×</a>
3
+ <strong><%= message %></strong>
4
+ </div>
@@ -0,0 +1,6 @@
1
+ <div class="nav-collapse">
2
+ <ul class="nav">
3
+ <%%= menu('Home', root_path) %>
4
+ <%%= menu('Help', '#help') %>
5
+ </ul>
6
+ </div><!--/.nav-collapse -->
@@ -0,0 +1,16 @@
1
+ <div class="well sidebar-nav">
2
+ <ul class="nav nav-list">
3
+ <li class="nav-header">Sidebar</li>
4
+ <%- (1..3).each do |i| -%>
5
+ <li><a href="#">Link</a></li>
6
+ <li><a href="#">Link</a></li>
7
+ <li><a href="#">Link</a></li>
8
+ <% end %>
9
+ <li class="nav-header">Sidebar</li>
10
+ <%- (1..3).each do |i| -%>
11
+ <li><a href="#">Link</a></li>
12
+ <li><a href="#">Link</a></li>
13
+ <li><a href="#">Link</a></li>
14
+ <% end %>
15
+ </ul>
16
+ </div><!--/.well -->
@@ -0,0 +1,11 @@
1
+ <div class="btn-group pull-right">
2
+ <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
3
+ <i class="icon-user"></i> Username
4
+ <span class="caret"></span>
5
+ </a>
6
+ <ul class="dropdown-menu">
7
+ <li><a href="#">Profile</a></li>
8
+ <li class="divider"></li>
9
+ <li><a href="#">Sign Out</a></li>
10
+ </ul>
11
+ </div>
@@ -0,0 +1,16 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require bootstrap
13
+ *= require bootstrap-responsive
14
+ *= require layout
15
+ *= require_tree .
16
+ */
@@ -0,0 +1,49 @@
1
+ <h1><% title("Dashboard#index") %></h1>
2
+ <p>Find me in app/views/dashboard/index.html.erb</p>
3
+
4
+ <div class="hero-unit">
5
+ <h1>Hello, world!</h1>
6
+ <p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
7
+ <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
8
+ </div>
9
+
10
+ <div class="row-fluid">
11
+ <div class="span4">
12
+ <h2>Heading</h2>
13
+ <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
14
+ <p><a class="btn" href="#">View details &raquo;</a></p>
15
+ </div><!--/span-->
16
+
17
+ <div class="span4">
18
+ <h2>Heading</h2>
19
+ <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
20
+ <p><a class="btn" href="#">View details &raquo;</a></p>
21
+ </div><!--/span-->
22
+
23
+ <div class="span4">
24
+ <h2>Heading</h2>
25
+ <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
26
+ <p><a class="btn" href="#">View details &raquo;</a></p>
27
+ </div><!--/span-->
28
+ </div><!--/row-->
29
+
30
+ <div class="row-fluid">
31
+ <div class="span4">
32
+ <h2>Heading</h2>
33
+ <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
34
+ <p><a class="btn" href="#">View details &raquo;</a></p>
35
+ </div><!--/span-->
36
+
37
+ <div class="span4">
38
+ <h2>Heading</h2>
39
+ <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
40
+ <p><a class="btn" href="#">View details &raquo;</a></p>
41
+ </div><!--/span-->
42
+
43
+ <div class="span4">
44
+ <h2>Heading</h2>
45
+ <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
46
+ <p><a class="btn" href="#">View details &raquo;</a></p>
47
+ </div><!--/span-->
48
+
49
+ </div><!--/row-->
@@ -0,0 +1,33 @@
1
+ module ErrorMessagesHelper
2
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
3
+ def error_messages_for(*objects)
4
+ options = objects.extract_options!
5
+ options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
6
+ options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
7
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
8
+ unless messages.empty?
9
+ # forced as error but may not abstractly always be the case
10
+ content_tag(:div, :class => "alert alert-danger") do
11
+ list_items = messages.map { |msg| content_tag(:li, msg.html_safe) }
12
+ content_tag(:h2, options[:header_message].html_safe) + content_tag(:p, options[:message].html_safe) + content_tag(:ul, list_items.join.html_safe)
13
+ end
14
+ end
15
+ end
16
+
17
+ def display_flash_message
18
+ partials = String.new
19
+ flash.each do |key, value|
20
+ css_class = key.to_s.eql?('notice') ? 'success' : 'danger'
21
+ partials << render( :partial => 'shared/flash', :locals => { :css => css_class, :message => value })
22
+ end
23
+ partials.html_safe
24
+ end
25
+
26
+ module FormBuilderAdditions
27
+ def error_messages(options = {})
28
+ @template.error_messages_for(@object, options)
29
+ end
30
+ end
31
+ end
32
+
33
+ ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
@@ -0,0 +1,8 @@
1
+ /* Your custom css stylesheets goes here */
2
+ body{padding-top:60px;padding-bottom:40px;}
3
+ h1{margin-bottom:20px !important;}
4
+ fieldset legend{margin-bottom:0;}
5
+ .sidebar-nav{padding:9px 0;}
6
+ .navbar .brand{color:#FFFFFF !important;}
7
+ .page-header{padding-bottom:0px !important;}
8
+ .actions{text-align:center !important;}
@@ -0,0 +1,76 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title><%%= content_for?(:title) ? "#{app_name} - #{yield(:title)}" : "<%= app_name %>" %></title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <meta name="description" content="">
8
+ <meta name="keywords" content="">
9
+ <meta name="author" content="">
10
+ <%%= csrf_meta_tags %>
11
+ <%%= stylesheet "application", :media => "all" %>
12
+ <%%= yield(:head) %>
13
+ <!--[if lt IE 9]>
14
+ <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
15
+ <![endif]-->
16
+ <link rel="shortcut icon" href="/favicon.ico">
17
+ <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
18
+ <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
19
+ <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
20
+ </head>
21
+
22
+ <body>
23
+
24
+ <div class="navbar navbar-fixed-top">
25
+ <div class="navbar-inner">
26
+ <%- if layout_type == "fluid" -%>
27
+ <div class="container-fluid">
28
+ <%- else -%>
29
+ <div class="container">
30
+ <%- end -%>
31
+ <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
32
+ <span class="icon-bar"></span>
33
+ <span class="icon-bar"></span>
34
+ <span class="icon-bar"></span>
35
+ </a>
36
+ <%%= link_to(app_name, root_path, :class => "brand") %>
37
+ <%%= render 'layouts/user_dropdown' %>
38
+ <%%= render 'layouts/navbar' %>
39
+ </div>
40
+ </div>
41
+ </div>
42
+
43
+ <%- if layout_type == "fluid" -%>
44
+ <div class="container-fluid">
45
+ <%- else -%>
46
+ <div class="container">
47
+ <%- end -%>
48
+ <%- if layout_type == "fluid" -%>
49
+ <div class="row-fluid">
50
+ <%- else -%>
51
+ <div class="row">
52
+ <%- end -%>
53
+ <div class="span3">
54
+ <%%= render 'layouts/sidebar' %>
55
+ </div><!--/span-->
56
+
57
+ <div class="span9">
58
+ <%%= display_flash_message %>
59
+ <div class="page-header">
60
+ <%%= content_tag :h1, yield(:title) if show_title %>
61
+ </div>
62
+ <%%= yield %>
63
+ </div><!--/span-->
64
+ </div><!--/row-->
65
+
66
+ <hr>
67
+
68
+ <footer>
69
+ <p><%%= app_name %> &copy; <%= Time.now.year %></p>
70
+ </footer>
71
+
72
+ </div><!--/.fluid-container-->
73
+
74
+ <%%= javascript_include_tag "application" %>
75
+ </body>
76
+ </html>
@@ -0,0 +1,47 @@
1
+ # These helper methods can be called in your template to set variables to be used in the layout
2
+ # This module should be included in all views globally,
3
+ # to do so you may need to add this line to your ApplicationController
4
+ # helper :layout
5
+ module LayoutHelper
6
+ def title(page_title, show_title = true)
7
+ content_for(:title) { h(page_title.to_s) }
8
+ @show_title = show_title
9
+ end
10
+
11
+ def show_title
12
+ @show_title
13
+ end
14
+
15
+ def stylesheet(*args)
16
+ content_for(:head) { stylesheet_link_tag(*args) }
17
+ end
18
+
19
+ def javascript(*args)
20
+ content_for(:head) { javascript_include_tag(*args) }
21
+ end
22
+
23
+ def menu(name, path)
24
+ content_tag(:li, link_to(name, path), :class => "#{'active' if request.path.gsub(/(.[^\/]+|\/)/).first == path}")
25
+ end
26
+
27
+ def analytics(site_id)
28
+ html = <<-ANALYTICS
29
+ <script type="text/javascript">
30
+ var _gaq = _gaq || [];
31
+ _gaq.push(['_setAccount', '#{site_id}']);
32
+ _gaq.push(['_trackPageview']);
33
+ (function() {
34
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
35
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
36
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
37
+ })();
38
+ </script>
39
+ ANALYTICS
40
+
41
+ html.html_safe if Rails.env.production?
42
+ end
43
+
44
+ def app_name
45
+ Rails.application.class.to_s.split("::").first
46
+ end
47
+ end
@@ -1,110 +1,25 @@
1
- require 'generators/flexi'
2
- require 'rails/generators/migration'
3
- require 'rails/generators/generated_attribute'
4
-
5
- module Flexi
6
- module Generators
7
- class ScaffoldGenerator < Base
8
- include Rails::Generators::Migration
9
-
10
- no_tasks { attr_accessor :model_name, :model_attributes }
11
- argument :model_name, :type => :string, :required => true, :banner => 'ModelName'
12
- argument :args_for_m, :type => :array, :default => [], :banner => 'model:attributes'
13
-
14
- def initialize(*args, &block)
15
- super
16
- @model_attributes = []
17
-
18
- args_for_m.each do |arg|
19
- if arg.include?(':')
20
- @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
21
- end
22
- end
23
-
24
- @model_attributes.uniq!
25
-
26
- if @model_attributes.empty?
27
- if model_exists?
28
- model_columns_for_attributes.each do |column|
29
- @model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
30
- end
31
- else
32
- @model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
33
- end
34
- end
35
- end
36
-
37
- def create_model
38
- template 'model.rb', "app/models/#{singular_name}.rb"
39
- template "tests/model.rb", "test/unit/#{singular_name}_test.rb"
40
- template 'fixtures.yml', "test/fixtures/#{plural_name}.yml"
41
- end
42
-
43
- def create_controller
44
- template "controller.rb", "app/controllers/admin/#{plural_name}_controller.rb"
45
- inject_into_file "config/routes.rb", "\n\tresources #{plural_name.to_sym.inspect}",
46
- :after => 'namespace :admin do'
47
- template "tests/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
48
- template 'helper.rb', "app/helpers/#{plural_name}_helper.rb"
49
- template "tests/helper.rb", "test/unit/helpers/#{plural_name}_controller_test.rb"
50
- end
51
-
52
- def create_view_files
53
- template "views/erb/index.html.erb", "app/views/admin/#{plural_name}/index.html.erb"
54
- template "views/erb/_form.html.erb", "app/views/admin/#{plural_name}/_form.html.erb"
55
- template "views/erb/show.html.erb", "app/views/admin/#{plural_name}/show.html.erb"
56
- template "views/erb/new.html.erb", "app/views/admin/#{plural_name}/new.html.erb"
57
- template "views/erb/edit.html.erb", "app/views/admin/#{plural_name}/edit.html.erb"
58
- template "views/erb/_error_messages.html.erb", "app/views/shared/_error_messages.html.erb"
59
- end
60
-
61
- def create_menu
62
- inject_into_file "app/views/layouts/_menu.html.erb", :after => "<%= menu do |m| %>" do
63
- "\n\t<%= m.#{plural_name} admin_#{plural_name}_path do %>
64
- <%= image_tag '#{plural_name}.png' %> #{plural_class_name}
65
- <% end %>"
66
- end
67
- end
68
-
69
- def create_migration
70
- migration_template 'migration.rb', "db/migrate/create_#{plural_name}.rb"
71
- end
72
-
73
- private
74
- def singular_name
75
- model_name.underscore
76
- end
77
-
78
- def plural_name
79
- model_name.underscore.pluralize
80
- end
81
-
82
- def class_name
83
- model_name.camelize
84
- end
85
-
86
- def plural_class_name
87
- plural_name.camelize
88
- end
89
-
90
- def model_exists?
91
- File.exist? destination_path("app/models/#{singular_name}.rb")
92
- end
93
-
94
- def model_columns_for_attributes
95
- class_name.constantize.columns.reject do |column|
96
- column.name.to_s =~ /^(id|created_at|updated_at)$/
97
- end
98
- end
99
-
100
- def self.next_migration_number(dirname) #:nodoc:
101
- if ActiveRecord::Base.timestamped_migrations
102
- Time.now.utc.strftime("%Y%m%d%H%M%S")
103
- else
104
- "%.3d" % (current_migration_number(dirname) + 1)
105
- end
106
- end
107
-
108
- end
109
- end
1
+ require 'rails/generators/rails/scaffold/scaffold_generator'
2
+ require 'rails/generators/erb/scaffold/scaffold_generator'
3
+
4
+ module Flexi
5
+ module Generators
6
+ class ScaffoldGenerator < Rails::Generators::ScaffoldGenerator
7
+ remove_hook_for :stylesheet_engine
8
+
9
+ def insert_menu
10
+ if File.exist?('app/views/layouts/_navbar.html.erb')
11
+ insert_into_file "app/views/layouts/_navbar.html.erb", " <%= menu('#{plural_table_name.titleize}', #{plural_table_name}_path) %>\n", :after => "<ul class=\"nav\">\n"
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+
19
+ module Erb
20
+ module Generators
21
+ class ScaffoldGenerator
22
+ source_root File.expand_path("../templates", __FILE__)
23
+ end
24
+ end
110
25
  end