navigator_rails 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/lib/generators/navigator_rails/USAGE +8 -0
  6. data/lib/generators/navigator_rails/install_generator.rb +8 -0
  7. data/lib/generators/navigator_rails/templates/initializer.rb +6 -0
  8. data/lib/navigator_rails/builder.rb +16 -0
  9. data/lib/navigator_rails/config.rb +60 -0
  10. data/lib/navigator_rails/constraint.rb +12 -0
  11. data/lib/navigator_rails/contextable.rb +13 -0
  12. data/lib/navigator_rails/decorator.rb +23 -0
  13. data/lib/navigator_rails/decorators/brand.rb +12 -0
  14. data/lib/navigator_rails/decorators/generic.rb +63 -0
  15. data/lib/navigator_rails/decorators/link.rb +12 -0
  16. data/lib/navigator_rails/decorators/navbar.rb +15 -0
  17. data/lib/navigator_rails/decorators/navigator.rb +31 -0
  18. data/lib/navigator_rails/decorators/submenu.rb +18 -0
  19. data/lib/navigator_rails/decorators.rb +6 -0
  20. data/lib/navigator_rails/engine.rb +24 -0
  21. data/lib/navigator_rails/helpers/application_helper.rb +15 -0
  22. data/lib/navigator_rails/helpers.rb +1 -0
  23. data/lib/navigator_rails/item.rb +36 -0
  24. data/lib/navigator_rails/navigatable.rb +14 -0
  25. data/lib/navigator_rails/navigator.rb +18 -0
  26. data/lib/navigator_rails/store.rb +117 -0
  27. data/lib/navigator_rails/version.rb +3 -0
  28. data/lib/navigator_rails.rb +4 -0
  29. data/test/dummy/README.rdoc +28 -0
  30. data/test/dummy/Rakefile +6 -0
  31. data/test/dummy/app/assets/javascripts/application.js +13 -0
  32. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  33. data/test/dummy/app/controllers/application_controller.rb +5 -0
  34. data/test/dummy/app/helpers/application_helper.rb +2 -0
  35. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/test/dummy/bin/bundle +3 -0
  37. data/test/dummy/bin/rails +4 -0
  38. data/test/dummy/bin/rake +4 -0
  39. data/test/dummy/config/application.rb +23 -0
  40. data/test/dummy/config/boot.rb +5 -0
  41. data/test/dummy/config/database.yml +25 -0
  42. data/test/dummy/config/environment.rb +5 -0
  43. data/test/dummy/config/environments/development.rb +37 -0
  44. data/test/dummy/config/environments/production.rb +78 -0
  45. data/test/dummy/config/environments/test.rb +39 -0
  46. data/test/dummy/config/initializers/assets.rb +8 -0
  47. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  49. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/test/dummy/config/initializers/inflections.rb +16 -0
  51. data/test/dummy/config/initializers/mime_types.rb +4 -0
  52. data/test/dummy/config/initializers/session_store.rb +3 -0
  53. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/test/dummy/config/locales/en.yml +23 -0
  55. data/test/dummy/config/routes.rb +4 -0
  56. data/test/dummy/config/secrets.yml +22 -0
  57. data/test/dummy/config.ru +4 -0
  58. data/test/dummy/public/404.html +67 -0
  59. data/test/dummy/public/422.html +67 -0
  60. data/test/dummy/public/500.html +66 -0
  61. data/test/dummy/public/favicon.ico +0 -0
  62. data/test/integration/navigation_test.rb +10 -0
  63. data/test/navigator_rails_test.rb +7 -0
  64. data/test/test_helper.rb +15 -0
  65. metadata +186 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f67ddd75cd352cf56cf93de0790997a2b517b18c
4
+ data.tar.gz: eb67d1513a5f388eda9bd57e7fb9967b7218e785
5
+ SHA512:
6
+ metadata.gz: 357bfea36b1aa0c632f68ca91bb4b5d847948f9b6b4ccd2378687e70bc578fc504bca3df358bc83fde773e7ab023eb88dec8203669afb15efbd031811eb18718
7
+ data.tar.gz: b257b240bbcab1adad13b1a5a5fe3a2be6f65e8e10e9d3d2564f7f976b22ed24b8ba74a7c3838a5909e8fa15e17e9c72011ba4b9ca5707503add1d05d2665ff1
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = NavigatorRails
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'NavigatorRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate navigator_rails Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,8 @@
1
+ module NavigatorRails
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ def copy_initializer_file
5
+ copy_file 'initializer.rb', 'config/initializers/navigator.rb'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ NavigatorRails.config do
2
+ use devise: '/head/right'
3
+ use :cancan
4
+ use :rolify
5
+ brand path: :head, content: '<span class="ion-cube"></span>Project Name'
6
+ end
@@ -0,0 +1,16 @@
1
+ module NavigatorRails
2
+ module Builder
3
+ def navigator_builder
4
+ def path param; @i.send("#{__method__}=",param); end
5
+ def order param; @i.send("#{__method__}=",param); end
6
+ def content param; @i.send("#{__method__}=",param.call); end
7
+ def constraint param; @i.send("#{__method__}=",param); end
8
+ def decorator param; @i.send("#{__method__}=",param); end
9
+ def type param; @i.send("#{__method__}=",param); end
10
+ @i = Item.new
11
+ yield
12
+ @i.save
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,60 @@
1
+ module NavigatorRails
2
+ module Config
3
+ def config &block
4
+ if block_given?
5
+ @config ||= {
6
+ default_constraint: true,
7
+ use_cancan: false,
8
+ use_devise: false,
9
+ use_rolify: false,
10
+ search_at: %w{ app/controllers },
11
+ controllers: [],
12
+ decorators: [ :navigator, :navbar, :submenu, :link ],
13
+ }
14
+ class_eval(&block)
15
+ Decorator.instance
16
+ Store.instance
17
+ Store.collect
18
+ Store.process_config_builders
19
+ else
20
+ @config
21
+ end
22
+ end
23
+ def brand params={}
24
+ params[:path] and path = "/#{params[:path].to_s}/brand"
25
+ params[:content] and content = params[:content]
26
+ path ||= '/head'
27
+ content ||= '<span class="ion-cube">Project Name</span>'
28
+
29
+ @config[:build_brand] = {path: path, content: content}
30
+ end
31
+ def use *params
32
+ if params.count == 1 and params.first.class == Hash
33
+ features = params.first.keys
34
+ params.first.each do |builder,path|
35
+ @config["build_#{builder}_at".to_sym] = path
36
+ end
37
+ else
38
+ features = params
39
+ end
40
+ features.each do |feature|
41
+ @config["use_#{feature}".to_sym] = true
42
+ end
43
+ end
44
+ def constraint constraint
45
+ @config[:default_constraint] = constraint
46
+ end
47
+ def cancan?
48
+ defined?(CanCan) and true
49
+ end
50
+ def devise?
51
+ defined?(Devise) and true
52
+ end
53
+ def rolify?
54
+ defined?(Rolify) and true
55
+ end
56
+ def rails?
57
+ defined?(Rails) and true
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,12 @@
1
+ module NavigatorRails
2
+ class Constraint
3
+ include Singleton
4
+ extend NavigatorRails::Contextable
5
+ class << self
6
+ def default; NavigatorRails::Constraint.instance.default; end
7
+ end
8
+ def default
9
+ NavigatorRails.config[:default_constraint]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module NavigatorRails
2
+ module Contextable
3
+ attr_accessor :context
4
+ def patch_context
5
+ return if @context.eval('self.methods.include? :navigator_builder')
6
+ @context.eval('extend NavigatorRails::Builder')
7
+ end
8
+ def process code
9
+ patch_context
10
+ @context.eval(code)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ module NavigatorRails
2
+ class Decorator
3
+ include Singleton
4
+ extend NavigatorRails::Contextable
5
+ class << self
6
+ def at params; Decorator.instance.at params; end
7
+ def for decorator; Decorator.instance.for decorator; end
8
+ def register type, decorator; Decorator.instance.register type, decorator; end
9
+ end
10
+ def initialize
11
+ @decorators = {}
12
+ end
13
+ def at params={}
14
+ return NavigatorRails.config[:decorators][params[:level]-1] if params[:level]
15
+ end
16
+ def for type
17
+ @decorators[type] if @decorators[type]
18
+ end
19
+ def register type, decorator
20
+ @decorators[type] = decorator
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module NavigatorRails
2
+ module Decorators
3
+ class Brand
4
+ include NavigatorRails::Decorators::Generic
5
+ def template
6
+ <<-LINK_DECORATION.strip_heredoc
7
+ <%= resource.content %>
8
+ LINK_DECORATION
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,63 @@
1
+ module NavigatorRails
2
+ module Decorators
3
+ module Generic
4
+ class << self
5
+ def included base
6
+ type = base.to_s.demodulize.downcase.to_sym
7
+ decorator = base
8
+ base.send(:extend,NavigatorRails::Decorators::Generic)
9
+ decorator.type = type
10
+ base.send(:include,Singleton)
11
+ NavigatorRails::Decorator.register type, decorator.instance
12
+ end
13
+ end
14
+ attr_accessor :type
15
+ def resource
16
+ @resource
17
+ end
18
+ def children_with params={}
19
+ children = Store.children_of resource
20
+ if params[:except]
21
+ children = children.collect do |child|
22
+ unless child.type
23
+ child
24
+ else
25
+ child unless child.type.to_sym == params[:except].to_sym
26
+ end
27
+ end.compact
28
+ end
29
+ if params[:only]
30
+ children = children.collect do |child|
31
+ next unless child.type
32
+ child if child.type.to_sym == params[:except].to_sym
33
+ end.compact
34
+ end
35
+ children
36
+ end
37
+ def child_count
38
+ children_with.count
39
+ end
40
+ def has_visible_children
41
+ children_with.collect do |child|
42
+ child.constraint
43
+ end.reduce(:|)
44
+ end
45
+ def children params={}
46
+ children = children_with params
47
+ children.collect do |child|
48
+ next unless child.constraint
49
+ child.decorator.draw(child).html_safe
50
+ end.join
51
+ end
52
+ def children_of resource
53
+ end
54
+ def draw resource
55
+ old_resource = @resource
56
+ @resource = resource
57
+ output = ERB.new(template).result(binding).html_safe
58
+ @resource = old_resource
59
+ output
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,12 @@
1
+ module NavigatorRails
2
+ module Decorators
3
+ class Link
4
+ include NavigatorRails::Decorators::Generic
5
+ def template
6
+ <<-LINK_DECORATION.strip_heredoc
7
+ <li><%= resource.content %></li>
8
+ LINK_DECORATION
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module NavigatorRails
2
+ module Decorators
3
+ class Navbar
4
+ include NavigatorRails::Decorators::Generic
5
+ def template
6
+ return '' unless has_visible_children
7
+ <<-LINK_DECORATION.strip_heredoc
8
+ <ul class="nav navbar-nav navbar-<%= resource.relative_path %>">
9
+ <%= children %>
10
+ </ul>
11
+ LINK_DECORATION
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module NavigatorRails
2
+ module Decorators
3
+ class Navigator
4
+ include NavigatorRails::Decorators::Generic
5
+ def brand
6
+ brand = Store.children_of(resource).select{|x|x.type==:brand}.first
7
+ brand.decorator.draw(brand).html_safe
8
+ end
9
+ def template
10
+ <<-LINK_DECORATION.strip_heredoc
11
+ <div class="navbar navbar-default navbar-fixed-top">
12
+ <div class="container">
13
+ <div class="navbar-header">
14
+ <button type="button" data-toggle="collapse" data-target=".navbar-collapse" class="navbar-toggle">
15
+ <span class="sr-only">Toggle navigation</span>
16
+ <span class="icon-bar"></span>
17
+ <span class="icon-bar"></span>
18
+ <span class="icon-bar"></span>
19
+ </button>
20
+ <%= brand %>
21
+ </div>
22
+ <div class="collapse navbar-collapse">
23
+ <%= children except: :brand %>
24
+ </div>
25
+ </div>
26
+ </div>
27
+ LINK_DECORATION
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ module NavigatorRails
2
+ module Decorators
3
+ class Submenu
4
+ include NavigatorRails::Decorators::Generic
5
+ def template
6
+ return '' unless has_visible_children
7
+ <<-LINK_DECORATION.strip_heredoc
8
+ <li class="dropdown">
9
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><%= resource.content %> <span class="caret"></span></a>
10
+ <ul class="dropdown-menu" role="menu">
11
+ <%= children %>
12
+ </ul>
13
+ </li>
14
+ LINK_DECORATION
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ require 'navigator_rails/decorators/generic'
2
+ require 'navigator_rails/decorators/navigator'
3
+ require 'navigator_rails/decorators/navbar'
4
+ require 'navigator_rails/decorators/submenu'
5
+ require 'navigator_rails/decorators/link'
6
+ require 'navigator_rails/decorators/brand'
@@ -0,0 +1,24 @@
1
+ require 'navigator_rails/config'
2
+ require 'navigator_rails/navigatable'
3
+ require 'navigator_rails/contextable'
4
+ require 'navigator_rails/store'
5
+ require 'navigator_rails/helpers'
6
+ require 'navigator_rails/builder'
7
+ require 'navigator_rails/constraint'
8
+ require 'navigator_rails/item'
9
+ require 'navigator_rails/decorator'
10
+ require 'navigator_rails/decorators'
11
+
12
+ module NavigatorRails
13
+ class Engine < ::Rails::Engine
14
+ initializer 'navigator_rails.add_navigator' do
15
+ config.to_prepare do
16
+ ApplicationController.send(:include,Helpers::ApplicationHelper)
17
+ Store.collect
18
+ end
19
+ end
20
+ end
21
+ class << self
22
+ include Config
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ module NavigatorRails
2
+ module Helpers
3
+ module ApplicationHelper
4
+ def self.included(base)
5
+ base.class_eval do
6
+ require 'navigator_rails/navigator'
7
+ helper_method :navigator
8
+ def navigator
9
+ @navigator = NavigatorRails::Navigator
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ require 'navigator_rails/helpers/application_helper.rb'
@@ -0,0 +1,36 @@
1
+ module NavigatorRails
2
+ class Item
3
+ include ActiveModel::Model
4
+ class << self
5
+ def level_of path
6
+ path.count('/')
7
+ end
8
+ def normalize_path path
9
+ path = path.to_s
10
+ path = "/#{path}" unless path =~ /^\//
11
+ path
12
+ end
13
+ end
14
+ attr_accessor :path, :order, :type
15
+ attr_writer :content, :constraint
16
+ def save
17
+ self.type ||= Decorator.at level: self.level
18
+ Store.add self
19
+ end
20
+ def level
21
+ Item.level_of self.path
22
+ end
23
+ def relative_path
24
+ File.basename path
25
+ end
26
+ def decorator
27
+ Decorator.for self.type
28
+ end
29
+ def content
30
+ Decorator.process(@content.to_s) rescue Store.delete self
31
+ end
32
+ def constraint
33
+ Constraint.process(@constraint.to_s) rescue Store.delete self
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ module NavigatorRails
2
+ module Navigatable
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ class_attribute :navigator_rails_items
6
+ end
7
+ module ClassMethods
8
+ def menu_item params={}
9
+ self.navigator_rails_items ||= []
10
+ self.navigator_rails_items << Item.new(params)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module NavigatorRails
2
+ class Navigator
3
+ class << self
4
+ def render path
5
+ context = binding.of_caller(1)
6
+
7
+ Constraint.context=context
8
+ Decorator.context=context
9
+
10
+ path = Item.normalize_path(path)
11
+ resource = Store.get(path)
12
+ decorator = Decorator.for(:navigator)
13
+
14
+ decorator.draw(resource).html_safe
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,117 @@
1
+ require 'sourcify'
2
+
3
+ module NavigatorRails
4
+ class Store
5
+ include Singleton
6
+ class << self
7
+ def add item; Store.instance.add item; end
8
+ def get path; Store.instance.get path; end
9
+ def delete item; Store.instance.delete item; end
10
+ def collect; Store.instance.collect; end
11
+ def children_of resource; Store.instance.children_of resource; end
12
+ def process_items; Store.instance.process_items; end
13
+ def process_config_builders; Store.instance.process_config_builders; end
14
+ end
15
+ def initialize
16
+ puts "Initializing store"
17
+ @items ||= []
18
+ end
19
+ def items
20
+ @items
21
+ end
22
+ def add item
23
+ @items.each do |dbitem|
24
+ return if dbitem.path == item.path
25
+ end
26
+ @items << item
27
+ fill_gaps
28
+ end
29
+ def get path
30
+ @items.collect do |item|
31
+ item if item.path == path
32
+ end.compact.first
33
+ end
34
+ def delete item
35
+ @items.delete(item)
36
+ end
37
+ def children_of resource
38
+ @items.collect do |item|
39
+ next unless item.path =~ /^#{resource.path}\//
40
+ next unless item.level == resource.level+1
41
+ item
42
+ end.compact
43
+ end
44
+ def process_config_builders
45
+ NavigatorRails.config.each do |param,value|
46
+ next unless param =~ /^build_/
47
+ case param
48
+ when :build_devise_at
49
+ parent_path = Item.normalize_path value
50
+ Item.new(path: "#{parent_path}/Profile", type: :link, constraint: 'user_signed_in?', content: "link_to('Profile', edit_user_registration_url)").save
51
+ Item.new(path: "#{parent_path}/SignOut", type: :link, constraint: 'user_signed_in?', content: "link_to('Sign Out', destroy_user_session_url, method: :delete)").save
52
+ Item.new(path: "#{parent_path}/SignIn", type: :link, constraint: 'not user_signed_in?', content: "link_to('Sign In', new_user_session_url)").save
53
+ Item.new(path: "#{parent_path}/SignUp", type: :link, constraint: 'not user_signed_in?', content: "link_to('Sign Up', new_user_registration_url)").save
54
+ when :build_brand
55
+ Item.new(type: :brand, type: :brand, path: value[:path], content: "link_to(raw('#{value[:content]}'),root_url, class: 'navbar-brand')").save
56
+ end
57
+ end
58
+ end
59
+ def get_controller dir, file
60
+ begin
61
+ return file.sub(/^#{dir}\//, '').sub(/\.rb$/,'').classify.constantize
62
+ rescue NameError
63
+ return
64
+ end
65
+ end
66
+ def register_controller controller
67
+ NavigatorRails.config[:controllers] << controller
68
+ end
69
+ def get_items_of controller
70
+ if defined?(controller.navigator_rails_items)
71
+ register_controller controller
72
+ return unless controller.navigator_rails_items
73
+ controller.navigator_rails_items.collect do |item|
74
+ item.save
75
+ end
76
+ end
77
+ end
78
+ def collect
79
+ NavigatorRails.config[:search_at].each do |dir|
80
+ Dir["#{dir}/**/*.rb"].each do |file|
81
+ get_items_of get_controller(dir, file)
82
+ end
83
+ end
84
+ end
85
+ private
86
+ def fill_gaps
87
+ paths = []
88
+ @items.each do |item|
89
+ path = item.path
90
+ loop do
91
+ break if path.empty?
92
+ break if paths.include? path
93
+ paths << path
94
+ path = path.split('/')[0..-2].join('/')
95
+ end
96
+ end
97
+ paths.each do |path|
98
+ next unless get(path).nil?
99
+ level = Item.level_of path
100
+ type = Decorator.at level: level
101
+ constraint = Constraint.default
102
+ content = "#{File.basename(path)}"
103
+ begin
104
+ content.singularize.constantize.model_name.human(count: 2)
105
+ i18n_content = "'#{content}'.singularize.constantize.model_name.human(count: 2)"
106
+ rescue I18n::InvalidPluralizationData
107
+ content.singularize.constantize.model_name.human(count: 1)
108
+ i18n_content = "'#{content}'.singularize.constantize.model_name.human(count: 1)"
109
+ rescue NameError
110
+ nil
111
+ end
112
+ content =i18n_content ? i18n_content : "'#{content}'"
113
+ Item.new(path:path, type: type, content: content, constraint: constraint).save
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,3 @@
1
+ module NavigatorRails
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "navigator_rails/engine"
2
+
3
+ module NavigatorRails
4
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks