rails_layout 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8eaeb22659d66ae199abbc7eeb77e85c445f005
4
- data.tar.gz: bf7444e215e3f0d928dec000b4be94beb4816422
3
+ metadata.gz: f4cb2d7684106cd92eafacf25404500f020a6581
4
+ data.tar.gz: d8acf6da27ec2a6d3602d814e4f4653ddae60eee
5
5
  SHA512:
6
- metadata.gz: 6d1f8936240bdf2a99009c9157a14c8e3fe7814d27439d0f54918ca958783cfadc0b0d19d3ea7ca128ee8aeb164577f39e32e1f0eb914c2572f4550dd557b0ff
7
- data.tar.gz: 8ad9db94a74ec5819e7fb64b7693f2f894f32c683cbb485784fafbf28e74b672a270a695252aa93d6906b25b9bdb943197a764c66b7f912097127b82f9c9830f
6
+ metadata.gz: f71d2f02f29f4949bdc4e557e703375073eb5b3b116658c5658be2c785f32f73efa3ee5ef15ada53d1b8be5b62547fc6d74cd068ec9d75751f00831a72db32af
7
+ data.tar.gz: e7d98d8105772adf776c4b353438fd254803c8c506490304c65ee351cab5b590d0ce9938ec31c876b9b224cf9133859640387657c403357572d76193b62e9c85
data/CHANGELOG.textile CHANGED
@@ -1,5 +1,13 @@
1
1
  h1. CHANGELOG
2
2
 
3
+ h3. 0.4.1 November 9, 2013
4
+
5
+ * add option to generate navigation links for Devise
6
+
7
+ h3. 0.4.0 November 9, 2013
8
+
9
+ * separate file for navigation links; isolate framework-specific markup in navigation partial
10
+
3
11
  h3. 0.3.0 November 9, 2013
4
12
 
5
13
  * create a file 'framework_and_overrides' instead of 'bootstrap_and_overrides' or 'foundation_and_overrides'
data/README.textile CHANGED
@@ -10,19 +10,15 @@ Use it to set up a front-end framework:
10
10
  * Twitter Bootstrap 3.0
11
11
  * Zurb Foundation 4.0
12
12
 
13
- It will rename *application.css.css* to *application.css.scss*.
13
+ It will rename *application.css* to *application.css.scss*.
14
14
 
15
- And modify the necessary asset files:
15
+ And add:
16
16
 
17
- * application.js
18
-
19
- and add either:
20
-
21
- * bootstrap_and_overrides.css.scss
17
+ * framework_and_overrides.css.scss
22
18
 
23
- or:
19
+ And modify the JavaScript asset file:
24
20
 
25
- * foundation_and_overrides.css.scss
21
+ * application.js
26
22
 
27
23
  It will set up a default application layout.
28
24
 
@@ -31,6 +27,8 @@ You also get partials for
31
27
  * Rails flash messages
32
28
  * navigation links
33
29
 
30
+ Optionally, you can generate a navigation links file suitable for use with Devise (the authentication gem).
31
+
34
32
  h4. Supported Frameworks
35
33
 
36
34
  You can generate layout files suitable for use with the following front-end frameworks:
@@ -48,11 +46,23 @@ The RailsLayout gem generates application layout files:
48
46
  * app/views/layouts/application.html.erb
49
47
  * app/views/layouts/_messages.html.erb
50
48
  * app/views/layouts/_navigation.html.erb
49
+ * app/views/layouts/_navigation_links.html.erb
51
50
 
52
51
  Additionally, when the @simple@ option is selected:
53
52
 
54
53
  * app/assets/stylesheets/simple.css
55
54
 
55
+ h4. Note About the Navigation Partials
56
+
57
+ Two navigation partials are created:
58
+
59
+ * app/views/layouts/_navigation.html.erb
60
+ * app/views/layouts/_navigation_links.html.erb
61
+
62
+ The first file exists to isolate framework-specific styling.
63
+
64
+ The second file contains no framework-specific styling. It is only a list of links. You can add additional links to this file as needed.
65
+
56
66
  h4. Support for ERB or Haml
57
67
 
58
68
  If you are using ERB for Rails views, the RailsLayout gem will generate ERB files.
@@ -260,6 +270,46 @@ Additionally, it will restore these files to the default versions:
260
270
 
261
271
  The file *app/assets/stylesheets/application.css.scss* will contain a CSS rule but you can ignore it or remove it.
262
272
 
273
+ h2. Navigation Links for Devise
274
+
275
+ If you are using Devise for authentication, you can generate a navigation links partial containing links for Devise.
276
+
277
+ <pre>
278
+ $ rails generate navigation --force
279
+ </pre>
280
+
281
+ This creates a file *app/views/layouts/_navigation_links.html.erb*:
282
+
283
+ <pre>
284
+ <%# add navigation links to this file %>
285
+ <li><%= link_to 'Home', root_path %></li>
286
+ <li><%= link_to 'About', page_path('about') %></li>
287
+ <li><%= link_to 'Contact', new_contact_path %></li>
288
+ <% if user_signed_in? %>
289
+ <li><%= link_to 'Logout', destroy_user_session_path, :method=>'delete' %></li>
290
+ <% else %>
291
+ <li><%= link_to 'Login', new_user_session_path %></li>
292
+ <% end %>
293
+ <% if user_signed_in? %>
294
+ <li><%= link_to 'Edit account', edit_user_registration_path %></li>
295
+ <% else %>
296
+ <li><%= link_to 'Sign up', new_user_registration_path %></li>
297
+ <% end %>
298
+ <% if user_signed_in? %>
299
+ <% if current_user.has_role? :admin %>
300
+ <li><%= link_to 'Admin', users_path %></li>
301
+ <% end %>
302
+ <% end %>
303
+ </pre>
304
+
305
+ The full set of links will be created if the following files are found in your application:
306
+
307
+ * app/views/devise/sessions/new.html.erb
308
+ * app/views/devise/registrations/new.html.erb
309
+ * app/views/users/index.html.erb
310
+
311
+ The @rails generate navigation@ command is used by the "Rails Composer":http://railsapps.github.io/rails-composer/ tool. It may not be suitable for your application if you haven't created custom view for Devise.
312
+
263
313
  h2. Help
264
314
 
265
315
  To see help messages:
@@ -58,28 +58,23 @@ module Layout
58
58
  if framework_name == 'none'
59
59
  remove_file "app/views/layouts/_messages.html.#{ext}"
60
60
  remove_file "app/views/layouts/_navigation.html.#{ext}"
61
+ remove_file "app/views/layouts/_navigation_links.html.#{ext}"
61
62
  else
62
63
  copy_file "#{framework_name}-messages.html.#{ext}", "app/views/layouts/_messages.html.#{ext}"
63
64
  copy_file "#{framework_name}-navigation.html.#{ext}", "app/views/layouts/_navigation.html.#{ext}"
65
+ copy_file "navigation_links.html.erb", "app/views/layouts/_navigation_links.html.erb"
64
66
  end
65
67
  end
66
68
 
67
- # If 'About' or 'Contact' views exist in known locations, add navigation links
69
+ # Add navigation links
68
70
  def add_navigation_links
71
+ app = ::Rails.application
72
+ ext = app.config.generators.options[:rails][:template_engine] || :erb
69
73
  unless framework_name == 'none'
70
- # not yet accommodating Slim (we'll need different substitutions)
71
- if File.exists?('app/views/pages/about.html.erb')
72
- insert_into_file 'app/views/layouts/_navigation.html.erb', "\n <li><%= link_to 'About', page_path('about') %></li>", :before => "\n</ul>"
73
- end
74
- if File.exists?('app/views/contacts/new.html.erb')
75
- insert_into_file 'app/views/layouts/_navigation.html.erb', "\n <li><%= link_to 'Contact', new_contact_path %></li>", :before => "\n</ul>"
76
- end
77
- if File.exists?('app/views/contacts/new.html.haml')
78
- insert_into_file 'app/views/layouts/_navigation.html.haml', "\n %li= link_to 'Contact', new_contact_path", :after => "root_path"
79
- end
80
- if File.exists?('app/views/pages/about.html.haml')
81
- insert_into_file 'app/views/layouts/_navigation.html.haml', "\n %li= link_to 'About', page_path('about')", :after => "root_path"
82
- end
74
+ # ABOUT
75
+ append_file 'app/views/layouts/_navigation_links.html.erb', "<li><%= link_to 'About', page_path('about') %></li>\n" if File.exists?("app/views/pages/about.html.#{ext}")
76
+ # CONTACT
77
+ append_file 'app/views/layouts/_navigation_links.html.erb', "<li><%= link_to 'Contact', new_contact_path %></li>\n" if File.exists?("app/views/contacts/new.html.#{ext}")
83
78
  end
84
79
  end
85
80
 
@@ -10,12 +10,8 @@
10
10
  </head>
11
11
  <body>
12
12
  <%%# application layout styled for Twitter Bootstrap 2.3 %>
13
- <header class="navbar navbar-fixed-top">
14
- <nav class="navbar-inner">
15
- <div class="container">
16
- <%%= render 'layouts/navigation' %>
17
- </div>
18
- </nav>
13
+ <header>
14
+ <%%= render 'layouts/navigation' %>
19
15
  </header>
20
16
  <main role="main">
21
17
  <div class="container">
@@ -9,10 +9,8 @@
9
9
  = csrf_meta_tags
10
10
  %body
11
11
  -# application layout styled for Twitter Bootstrap 2.3
12
- %header.navbar.navbar-fixed-top
13
- %nav.navbar-inner
14
- .container
15
- = render 'layouts/navigation'
12
+ %header
13
+ = render 'layouts/navigation'
16
14
  %main{:role => "main"}
17
15
  .container
18
16
  .content
@@ -1,3 +1,10 @@
1
- <ul class="nav">
2
- <li><%= link_to 'Home', root_path %></li>
3
- </ul>
1
+ <%# navigation styled for Twitter Bootstrap 2.3 %>
2
+ <div class="navbar navbar-fixed-top">
3
+ <nav class="navbar-inner">
4
+ <div class="container">
5
+ <ul class="nav">
6
+ <%= render 'layouts/navigation_links' %>
7
+ </ul>
8
+ </div>
9
+ </nav>
10
+ </div>
@@ -1,2 +1,6 @@
1
- %ul.nav
2
- %li= link_to 'Home', root_path
1
+ -# navigation styled for Twitter Bootstrap 2.3
2
+ .navbar.navbar-fixed-top
3
+ %nav.navbar-inner
4
+ .container
5
+ %ul.nav
6
+ = render 'layouts/navigation_links'
@@ -11,21 +11,7 @@
11
11
  <body>
12
12
  <%%# application layout styled for Twitter Bootstrap 3.0 %>
13
13
  <header>
14
- <nav class="navbar navbar-default navbar-fixed-top">
15
- <div class="container">
16
- <div class="navbar-header">
17
- <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
18
- <span class="sr-only">Toggle navigation</span>
19
- <span class="icon-bar"></span>
20
- <span class="icon-bar"></span>
21
- <span class="icon-bar"></span>
22
- </button>
23
- </div>
24
- <div class="collapse navbar-collapse">
25
- <%%= render 'layouts/navigation' %>
26
- </div>
27
- </div>
28
- </nav>
14
+ <%%= render 'layouts/navigation' %>
29
15
  </header>
30
16
  <main role="main">
31
17
  <div class="container">
@@ -10,16 +10,7 @@
10
10
  %body
11
11
  -# application layout styled for Twitter Bootstrap 3.0
12
12
  %header
13
- %nav.navbar.navbar-default.navbar-fixed-top
14
- .container
15
- .navbar-header
16
- %button.navbar-toggle{"data-target" => ".navbar-collapse", "data-toggle" => "collapse", :type => "button"}
17
- %span.sr-only Toggle navigation
18
- %span.icon-bar
19
- %span.icon-bar
20
- %span.icon-bar
21
- .collapse.navbar-collapse
22
- = render 'layouts/navigation'
13
+ = render 'layouts/navigation'
23
14
  %main{:role => "main"}
24
15
  .container
25
16
  .container
@@ -1,3 +1,18 @@
1
- <ul class="nav navbar-nav">
2
- <li><%= link_to 'Home', root_path %></li>
3
- </ul>
1
+ <%# navigation styled for Twitter Bootstrap 3.0 %>
2
+ <nav class="navbar navbar-default navbar-fixed-top">
3
+ <div class="container">
4
+ <div class="navbar-header">
5
+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
6
+ <span class="sr-only">Toggle navigation</span>
7
+ <span class="icon-bar"></span>
8
+ <span class="icon-bar"></span>
9
+ <span class="icon-bar"></span>
10
+ </button>
11
+ </div>
12
+ <div class="collapse navbar-collapse">
13
+ <ul class="nav navbar-nav">
14
+ <%= render 'layouts/navigation_links' %>
15
+ </ul>
16
+ </div>
17
+ </div>
18
+ </nav>
@@ -1,2 +1,12 @@
1
- %ul.nav.navbar-nav
2
- %li= link_to 'Home', root_path
1
+ -# navigation styled for Twitter Bootstrap 3.0
2
+ %nav.navbar.navbar-default.navbar-fixed-top
3
+ .container
4
+ .navbar-header
5
+ %button.navbar-toggle{"data-target" => ".navbar-collapse", "data-toggle" => "collapse", :type => "button"}
6
+ %span.sr-only Toggle navigation
7
+ %span.icon-bar
8
+ %span.icon-bar
9
+ %span.icon-bar
10
+ .collapse.navbar-collapse
11
+ %ul.nav.navbar-nav
12
+ = render 'layouts/navigation_links'
@@ -13,15 +13,7 @@
13
13
  <body>
14
14
  <%%# application layout styled for Zurb Foundation 4 %>
15
15
  <header>
16
- <nav class="top-bar">
17
- <ul class="title-area">
18
- <li class="name"><!-- add site name or logo here --></li>
19
- <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
20
- </ul>
21
- <section class="top-bar-section">
22
- <%%= render 'layouts/navigation' %>
23
- </section>
24
- </nav>
16
+ <%%= render 'layouts/navigation' %>>
25
17
  </header>
26
18
  <main role="main">
27
19
  <div class="container">
@@ -12,15 +12,7 @@
12
12
  %body
13
13
  -# application layout styled for Zurb Foundation 4
14
14
  %header
15
- %nav.top-bar
16
- %ul.title-area
17
- %li.name
18
- -# add site name or logo here
19
- %li.toggle-topbar.menu-icon
20
- %a{:href => "#"}
21
- %span Menu
22
- %section.top-bar-section
23
- = render 'layouts/navigation'
15
+ = render 'layouts/navigation'
24
16
  %main{:role => "main"}
25
17
  .container
26
18
  .content
@@ -1,3 +1,12 @@
1
- <ul>
2
- <li><%= link_to 'Home', root_path %></li>
3
- </ul>
1
+ <%# navigation styled for Zurb Foundation 4 %>
2
+ <nav class="top-bar">
3
+ <ul class="title-area">
4
+ <li class="name"><!-- add site name or logo here --></li>
5
+ <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
6
+ </ul>
7
+ <section class="top-bar-section">
8
+ <ul>
9
+ <%= render 'layouts/navigation_links' %>
10
+ </ul>
11
+ </section>
12
+ </nav>
@@ -1,2 +1,11 @@
1
- %ul
2
- %li= link_to 'Home', root_path
1
+ -# navigation styled for Zurb Foundation 4
2
+ %nav.top-bar
3
+ %ul.title-area
4
+ %li.name
5
+ -# add site name or logo here
6
+ %li.toggle-topbar.menu-icon
7
+ %a{:href => "#"}
8
+ %span Menu
9
+ %section.top-bar-section
10
+ %ul
11
+ = render 'layouts/navigation_links'
@@ -0,0 +1,2 @@
1
+ <%# add navigation links to this file %>
2
+ <li><%= link_to 'Home', root_path %></li>
@@ -1,3 +1,3 @@
1
1
  <ul class="nav">
2
- <li><%= link_to 'Home', root_path %></li>
3
- </ul>
2
+ <%= render 'layouts/navigation_links' %>
3
+ </ul>
@@ -1,2 +1,2 @@
1
1
  %ul.nav
2
- %li= link_to 'Home', root_path
2
+ = render 'layouts/navigation_links'
@@ -0,0 +1,54 @@
1
+ require 'rails/generators'
2
+
3
+ module Navigation
4
+ module Generators
5
+ class NavigationGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ # Add navigation links
9
+ def add_navigation_links
10
+ app = ::Rails.application
11
+ ext = app.config.generators.options[:rails][:template_engine] || :erb
12
+ copy_file "navigation_links.html.erb", "app/views/layouts/_navigation_links.html.erb"
13
+ # ABOUT
14
+ append_file 'app/views/layouts/_navigation_links.html.erb', "<li><%= link_to 'About', page_path('about') %></li>\n" if File.exists?("app/views/pages/about.html.#{ext}")
15
+ # CONTACT
16
+ append_file 'app/views/layouts/_navigation_links.html.erb', "<li><%= link_to 'Contact', new_contact_path %></li>\n" if File.exists?("app/views/contacts/new.html.#{ext}")
17
+ # DEVISE LOGIN and LOGOUT
18
+ if File.exists?("app/views/devise/sessions/new.html.#{ext}")
19
+ append_file 'app/views/layouts/_navigation_links.html.erb' do <<-LINKS
20
+ <% if user_signed_in? %>
21
+ <li><%= link_to 'Logout', destroy_user_session_path, :method=>'delete' %></li>
22
+ <% else %>
23
+ <li><%= link_to 'Login', new_user_session_path %></li>
24
+ <% end %>
25
+ LINKS
26
+ end
27
+ end
28
+ # DEVISE SIGN UP
29
+ if File.exists?("app/views/devise/registrations/new.html.#{ext}")
30
+ append_file 'app/views/layouts/_navigation_links.html.erb' do <<-LINKS
31
+ <% if user_signed_in? %>
32
+ <li><%= link_to 'Edit account', edit_user_registration_path %></li>
33
+ <% else %>
34
+ <li><%= link_to 'Sign up', new_user_registration_path %></li>
35
+ <% end %>
36
+ LINKS
37
+ end
38
+ end
39
+ # ADMIN LINK
40
+ if File.exists?("app/views/users/index.html.#{ext}")
41
+ append_file 'app/views/layouts/_navigation_links.html.erb' do <<-LINKS
42
+ <% if user_signed_in? %>
43
+ <% if current_user.has_role? :admin %>
44
+ <li><%= link_to 'Admin', users_path %></li>
45
+ <% end %>
46
+ <% end %>
47
+ LINKS
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,2 @@
1
+ <%# add navigation links to this file %>
2
+ <li><%= link_to 'Home', root_path %></li>
@@ -1,3 +1,3 @@
1
1
  module RailsLayout
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_layout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Kehoe
@@ -79,6 +79,7 @@ files:
79
79
  - lib/generators/layout/templates/foundation4-navigation.html.erb
80
80
  - lib/generators/layout/templates/foundation4-navigation.html.haml
81
81
  - lib/generators/layout/templates/foundation_and_overrides.css.scss
82
+ - lib/generators/layout/templates/navigation_links.html.erb
82
83
  - lib/generators/layout/templates/none-application.html.erb
83
84
  - lib/generators/layout/templates/none-application.html.haml
84
85
  - lib/generators/layout/templates/simple-application.html.erb
@@ -88,6 +89,8 @@ files:
88
89
  - lib/generators/layout/templates/simple-navigation.html.erb
89
90
  - lib/generators/layout/templates/simple-navigation.html.haml
90
91
  - lib/generators/layout/templates/simple.css
92
+ - lib/generators/navigation/navigation_generator.rb
93
+ - lib/generators/navigation/templates/navigation_links.html.erb
91
94
  - lib/rails_layout.rb
92
95
  - lib/rails_layout/version.rb
93
96
  - rails_layout.gemspec