Permalink
Browse files

Cleaning up the config generator code

  • Loading branch information...
1 parent b399469 commit f34b692773e365c933007f72c3b791311e880cb7 @simonc simonc committed Feb 19, 2014
@@ -1,8 +1,8 @@
class NavigationConfigGenerator < Rails::Generator::Base
def manifest
record do |m|
- m.file "config/navigation.rb", "config/navigation.rb"
- m.readme "../../../README"
+ m.file 'config/navigation.rb', 'config/navigation.rb'
+ m.readme '../../../README'
end
end
-end
+end
@@ -6,8 +6,8 @@
# The renderer can also be specified as option in the render_navigation call.
# navigation.renderer = Your::Custom::Renderer
- # Specify the class that will be applied to active navigation items. Defaults to 'selected'
- # navigation.selected_class = 'your_selected_class'
+ # Specify the class that will be applied to active navigation items.
+ # Defaults to 'selected' navigation.selected_class = 'your_selected_class'
# Specify the class that will be applied to the current leaf of
# active navigation items. Defaults to 'simple-navigation-active-leaf'
@@ -22,7 +22,8 @@
# The example below would add a prefix to each key.
# navigation.id_generator = Proc.new {|key| "my-prefix-#{key}"}
- # If you need to add custom html around item names, you can define a proc that will be called with the name you pass in to the navigation.
+ # If you need to add custom html around item names, you can define a proc that
+ # will be called with the name you pass in to the navigation.
# The example below shows how to wrap items spans.
# navigation.name_generator = Proc.new {|name, item| "<span>#{name}</span>"}
@@ -42,15 +43,15 @@
# options - can be used to specify attributes that will be included in the rendered navigation item (e.g. id, class etc.)
# some special options that can be set:
# :if - Specifies a proc to call to determine if the item should
- # be rendered (e.g. <tt>:if => Proc.new { current_user.admin? }</tt>). The
+ # be rendered (e.g. <tt>if: -> { current_user.admin? }</tt>). The
# proc should evaluate to a true or false value and is evaluated in the context of the view.
# :unless - Specifies a proc to call to determine if the item should not
- # be rendered (e.g. <tt>:unless => Proc.new { current_user.admin? }</tt>). The
+ # be rendered (e.g. <tt>unless: -> { current_user.admin? }</tt>). The
# proc should evaluate to a true or false value and is evaluated in the context of the view.
# :method - Specifies the http-method for the generated link - default is :get.
# :highlights_on - if autohighlighting is turned off and/or you want to explicitly specify
# when the item should be highlighted, you can set a regexp which is matched
- # against the current URI. You may also use a proc, or the symbol <tt>:subpath</tt>.
+ # against the current URI. You may also use a proc, or the symbol <tt>:subpath</tt>.
#
primary.item :key_1, 'name', url, options
@@ -63,16 +64,14 @@
# You can also specify a condition-proc that needs to be fullfilled to display an item.
# Conditions are part of the options. They are evaluated in the context of the views,
# thus you can use all the methods and vars you have available in the views.
- primary.item :key_3, 'Admin', url, :class => 'special', :if => Proc.new { current_user.admin? }
- primary.item :key_4, 'Account', url, :unless => Proc.new { logged_in? }
+ primary.item :key_3, 'Admin', url, class: 'special', if: -> { current_user.admin? }
+ primary.item :key_4, 'Account', url, unless: -> { logged_in? }
# you can also specify html attributes to attach to this particular level
# works for all levels of the menu
# primary.dom_attributes = {id: 'menu-id', class: 'menu-class'}
# You can turn off auto highlighting for a specific level
# primary.auto_highlight = false
-
end
-
end
@@ -1,12 +1,17 @@
class NavigationConfigGenerator < Rails::Generators::Base
def self.source_root
- @source_root ||= File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','generators','navigation_config', 'templates'))
+ @source_root ||= begin
+ tpl_dir = %w[.. .. .. .. generators navigation_config templates]
+ tpl_dir_path = File.join(tpl_dir)
+ File.expand_path(tpl_dir_path, __FILE__)
+ end
end
- desc 'Creates a template config file for the simple-navigation plugin. You will find the generated file in config/navigation.rb.'
+ desc 'Creates a template config file for the simple-navigation plugin. ' \
+ 'You will find the generated file in config/navigation.rb.'
def navigation_config
- copy_file('config/navigation.rb', 'config/navigation.rb')
- say File.read(File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','README')))
+ copy_file('config/navigation.rb', 'config/navigation.rb')
+ readme_path = File.join(%w[.. .. .. .. README.md])
+ say File.read(File.expand_path(readme_path, __FILE__))
end
-
-end
+end

0 comments on commit f34b692

Please sign in to comment.