navigasmic 0.5.6 → 1.0.0

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 (57) hide show
  1. data/LICENSE +7 -1
  2. data/lib/generators/navigasmic/install/POST_INSTALL +6 -0
  3. data/lib/generators/navigasmic/install/install_generator.rb +17 -0
  4. data/lib/generators/navigasmic/install/templates/initializer.rb +145 -0
  5. data/lib/navigasmic.rb +5 -146
  6. data/lib/navigasmic/builders/crumb_builder.rb +20 -0
  7. data/lib/navigasmic/builders/list_builder.rb +90 -0
  8. data/lib/navigasmic/builders/map_builder.rb +77 -0
  9. data/lib/navigasmic/core/builders.rb +109 -0
  10. data/lib/navigasmic/core/configuration.rb +38 -0
  11. data/lib/navigasmic/core/item.rb +66 -0
  12. data/lib/navigasmic/rails.rb +2 -0
  13. data/lib/navigasmic/rails/engine.rb +9 -0
  14. data/lib/navigasmic/rails/view_helpers.rb +18 -0
  15. data/lib/navigasmic/version.rb +3 -0
  16. data/spec/dummy/Rakefile +7 -0
  17. data/spec/dummy/app/controllers/application_controller.rb +13 -0
  18. data/spec/dummy/app/controllers/blog/links_controller.rb +7 -0
  19. data/spec/dummy/app/controllers/blog/posts_controller.rb +7 -0
  20. data/spec/dummy/app/views/application/welcome.html.erb +4 -0
  21. data/spec/dummy/app/views/application/welcome.xml.builder +2 -0
  22. data/spec/dummy/app/views/blog/links/index.html +4 -0
  23. data/spec/dummy/app/views/blog/links/show.html +4 -0
  24. data/spec/dummy/app/views/blog/posts/index.html +4 -0
  25. data/spec/dummy/app/views/blog/posts/show.html +4 -0
  26. data/spec/dummy/app/views/layouts/_navigation.html.erb +73 -0
  27. data/spec/dummy/app/views/layouts/application.html.erb +40 -0
  28. data/spec/dummy/config.ru +4 -0
  29. data/spec/dummy/config/application.rb +57 -0
  30. data/spec/dummy/config/boot.rb +9 -0
  31. data/spec/dummy/config/environment.rb +5 -0
  32. data/spec/dummy/config/environments/development.rb +37 -0
  33. data/spec/dummy/config/environments/test.rb +37 -0
  34. data/spec/dummy/config/evergreen.rb +47 -0
  35. data/spec/dummy/config/initializers/additional_navigasmic.rb +14 -0
  36. data/spec/dummy/config/initializers/navigasmic.rb +145 -0
  37. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  38. data/spec/dummy/config/initializers/session_store.rb +8 -0
  39. data/spec/dummy/config/locales/en.yml +5 -0
  40. data/spec/dummy/config/routes.rb +68 -0
  41. data/spec/dummy/log/.gitkeep +0 -0
  42. data/spec/dummy/public/bootstrap.min.css +9 -0
  43. data/spec/dummy/public/bootstrap.min.js +6 -0
  44. data/spec/dummy/public/favicon.ico +0 -0
  45. data/spec/dummy/public/jquery.min.js +2 -0
  46. data/spec/dummy/script/rails +6 -0
  47. data/spec/spec_helper.rb +39 -0
  48. metadata +139 -63
  49. data/.document +0 -5
  50. data/README.textile +0 -276
  51. data/Rakefile +0 -57
  52. data/VERSION +0 -1
  53. data/lib/builders/html_builder.rb +0 -69
  54. data/lib/builders/xml_builder.rb +0 -51
  55. data/navigasmic.gemspec +0 -49
  56. data/test/navigasmic_test.rb +0 -7
  57. data/test/test_helper.rb +0 -10
@@ -0,0 +1,40 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Navigasmic: Regression Test</title>
5
+ <link rel="stylesheet" type="text/css" href="/bootstrap.min.css"/>
6
+ <script type="text/javascript" src="/jquery.min.js"></script>
7
+ <script type="text/javascript" src="/bootstrap.min.js"></script>
8
+ <style>
9
+ .foo {
10
+ color: #0f0;
11
+ }
12
+ .foo a {
13
+ color: #0f0;
14
+ }
15
+ li.disabled {
16
+ color: #999;
17
+ }
18
+ .active {
19
+ color: #f00;
20
+ }
21
+ .active a {
22
+ color: #f00;
23
+ }
24
+ </style>
25
+ </head>
26
+ <body>
27
+
28
+ <div class="navbar">
29
+ <div class="navbar-inner">
30
+ <a class="brand" href="/">Title</a>
31
+ <%= semantic_navigation :testing, config: :bootstrap %>
32
+ </div>
33
+ </div>
34
+
35
+ <%= yield %>
36
+
37
+ <%= render partial: 'layouts/navigation' %>
38
+
39
+ </body>
40
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,57 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'action_controller/railtie'
4
+
5
+ require 'navigasmic'
6
+
7
+ module Dummy
8
+ class Application < Rails::Application
9
+ # Settings in config/environments/* take precedence over those specified here.
10
+ # Application configuration should go into files in config/initializers
11
+ # -- all .rb files in that directory are automatically loaded.
12
+
13
+ # Custom directories with classes and modules you want to be autoloadable.
14
+ # config.autoload_paths += %W(#{config.root}/extras)
15
+
16
+ # Only load the plugins named here, in the order given (default is alphabetical).
17
+ # :all can be used as a placeholder for all plugins not explicitly named.
18
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
19
+
20
+ # Activate observers that should always be running.
21
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
22
+
23
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
24
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
25
+ # config.time_zone = 'Central Time (US & Canada)'
26
+
27
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
28
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
29
+ # config.i18n.default_locale = :de
30
+
31
+ # Configure the default encoding used in templates for Ruby 1.9.
32
+ config.encoding = "utf-8"
33
+
34
+ # Configure sensitive parameters which will be filtered from the log file.
35
+ config.filter_parameters += [:password]
36
+
37
+ # Enable escaping HTML in JSON.
38
+ #config.active_support.escape_html_entities_in_json = true
39
+
40
+ # Use SQL instead of Active Record's schema dumper when creating the database.
41
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
42
+ # like if you have constraints or database-specific column types
43
+ #config.active_record.schema_format = :sql
44
+
45
+ # Enforce whitelist mode for mass assignment.
46
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
47
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
48
+ # parameters by using an attr_accessible or attr_protected declaration.
49
+ #config.active_record.whitelist_attributes = true
50
+
51
+ # Enable the asset pipeline
52
+ #config.assets.enabled = true
53
+
54
+ # Version of your assets, change this if you want to expire all your assets
55
+ #config.assets.version = '1.0'
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
2
+
3
+ if File.exist?(gemfile)
4
+ ENV['BUNDLE_GEMFILE'] = gemfile
5
+ require 'bundler'
6
+ Bundler.setup
7
+ end
8
+
9
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,37 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ #config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Raise exception on mass assignment protection for Active Record models
26
+ #config.active_record.mass_assignment_sanitizer = :strict
27
+
28
+ # Log the query plan for queries taking more than this (works
29
+ # with SQLite, MySQL, and PostgreSQL)
30
+ #config.active_record.auto_explain_threshold_in_seconds = 0.5
31
+
32
+ # Do not compress assets
33
+ #config.assets.compress = false
34
+
35
+ # Expands the lines which load the assets
36
+ #config.assets.debug = true
37
+ end
@@ -0,0 +1,37 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ #config.action_mailer.delivery_method = :test
31
+
32
+ # Raise exception on mass assignment protection for Active Record models
33
+ #config.active_record.mass_assignment_sanitizer = :strict
34
+
35
+ # Print deprecation notices to the stderr
36
+ config.active_support.deprecation = :stderr
37
+ end
@@ -0,0 +1,47 @@
1
+ # The following allows us to have a nested directory structure of specs. With
2
+ # a lot of specs this is needed.
3
+ Evergreen.configure do |config|
4
+ config.root = Temporal::Engine.root
5
+ end
6
+
7
+ module Evergreen
8
+ class Suite
9
+ def specs
10
+ Dir.glob(File.join(root, Evergreen.spec_dir, '**', '*_spec.{js,coffee,js.coffee}')).map do |path|
11
+ Spec.new(self, path.gsub(File.join(root), ''))
12
+ end
13
+ end
14
+
15
+ def templates
16
+ Dir.glob(File.join(root, Evergreen.template_dir, '**', '*')).map do |path|
17
+ Template.new(self, path.gsub(File.join(root), '')) unless File.directory?(path)
18
+ end.compact
19
+ end
20
+ end
21
+ end
22
+
23
+ module Evergreen
24
+ class Spec
25
+ def initialize(suite, name)
26
+ @suite = suite
27
+ @name = name
28
+ @name = "#{Evergreen.spec_dir}/#{name}" if !exist?
29
+ end
30
+
31
+ def name
32
+ @name.gsub("/#{Evergreen.spec_dir}/", '')
33
+ end
34
+ end
35
+ end
36
+
37
+ module Evergreen
38
+ class Template
39
+ def name
40
+ @name.gsub("/#{Evergreen.template_dir}/", '')
41
+ end
42
+
43
+ def full_path
44
+ File.join(root, @name)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,14 @@
1
+ Navigasmic.setup do |config|
2
+
3
+ config.semantic_navigation :testing do |n|
4
+ n.item 'Home', proc{ root_path }
5
+ n.item 'Site Map', proc{ root_path(format: 'xml') }
6
+ n.item 'Blog', class: 'blog', highlights_on: [{controller: '/blog/posts'}, {controller: '/blog/links'}] do
7
+ n.item 'Articles', controller: '/blog/posts'
8
+ n.item 'Links', '/blog/links'
9
+ n.item 'Specific Article', link: {controller: '/blog/posts', action: 'show', id: '2'}
10
+ n.item 'Not Linked'
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,145 @@
1
+ Navigasmic.setup do |config|
2
+
3
+ # Defining Navigation Structures:
4
+ #
5
+ # You can begin by defining your navigation structures here. You can also define them directly in the view if you'd
6
+ # like, but it's recommended to eventually move them here to clean help up your views. You can read about Navigasmic
7
+ # at https://github.com/jejacks0n/navigasmic
8
+ #
9
+ # When you're defining navigation here, it's basically the same as if you were doing it in the view but the scope is
10
+ # different. It's important to understand that -- and use procs where you want things to execute in the view scope.
11
+ #
12
+ # Once you've defined some navigation structures and configured your builders you can render navigation in your views
13
+ # using the `semantic_navigation` view helper. You can also use the same syntax to define your navigation structures
14
+ # in your views, and eventually move them here (it's handy to prototype navigation/css by putting them in the views
15
+ # first).
16
+ #
17
+ # <%= semantic_navigation :primary %>
18
+ #
19
+ # You can optionally provided a :builder and :config option to the semantic_navigation view helper.
20
+ #
21
+ # <%= semantic_navigation :primary, config: :blockquote %>
22
+ # <%= semantic_navigation :primary, builder: Navigasmic::Builder::MapBuilder %>
23
+ #
24
+ # When defining navigation in your views just pass it a block (the same as here basically).
25
+ #
26
+ # <%= semantic_navigation :primary do |n| %>
27
+ # <% n.item 'About Me' %>
28
+ # <% end %>
29
+ #
30
+ # Here's a basic example:
31
+ config.semantic_navigation :primary do |n|
32
+
33
+ n.item 'Home', '/'
34
+
35
+ # Groups and Items:
36
+ #
37
+ # You can create a structure using `group`, and `item`. You can nest items inside groups or items. In the
38
+ # following example, the "Articles" item will always highlight on the blog/posts controller, and the nested article
39
+ # items will only highlight when on those specific pages. The "Links" item will be disabled unless the user is
40
+ # logged in.
41
+ #
42
+ #n.group 'Blog' do
43
+ # n.item 'Articles', controller: '/blog/posts' do
44
+ # n.item 'First Article', '/blog/posts/1'
45
+ # n.item 'Second Article', '/blog/posts/2', map: {changefreq: 'weekly'}
46
+ # end
47
+ # n.item 'Links', controller: '/blog/links', disabled_if: proc{ !logged_in? }
48
+ #end
49
+ #
50
+ # You can hide specific specific items or groups. Here we specify that the "About" section of navigation should
51
+ # only be displayed if the user is logged in.
52
+ #
53
+ #n.group 'About', hidden_unless: proc{ logged_in? } do
54
+ # n.item 'About Me', class: 'featured', link_html: {class: 'about-me'}
55
+ #end
56
+ #
57
+ # Scoping:
58
+ #
59
+ # Scoping is different than in the view here, so we've provided some nice things for you to get around that. In
60
+ # the above example we just provide '/' as what the home page is, but that may not be correct. You can also access
61
+ # the path helpers, using a proc, or by proxying them through the navigation object. Any method called on the
62
+ # navigation scope will be called within the view scope.
63
+ #
64
+ #n.item 'Home', proc{ root_path }
65
+ #n.item 'Home', n.root_path
66
+ #
67
+ # This proxy behavior can be used for I18n as well.
68
+ #
69
+ #n.item n.t('hello'), '/'
70
+
71
+ end
72
+
73
+
74
+ # Setting the Default Builder:
75
+ #
76
+ # By default the Navigasmic::Builder::ListBuilder is used unless otherwise specified.
77
+ #
78
+ # You can change this here:
79
+ #config.default_builder = MyCustomBuilder
80
+
81
+
82
+ # Configuring Builders:
83
+ #
84
+ # You can change various builder options here by specifying the builder you want to configure and the options you
85
+ # want to change.
86
+ #
87
+ # Changing the default ListBuilder options:
88
+ config.builder Navigasmic::Builder::ListBuilder do |builder|
89
+ builder.wrapper_class = 'semantic-navigation'
90
+ end
91
+
92
+
93
+ # Naming Builder Configurations:
94
+ #
95
+ # If you want to define a named configuration for a builder, just provide a hash with the name, and the builder to
96
+ # configure. The named configurations can then be used during rendering by specifying a `:config => :bootstrap`
97
+ # option to the `semantic_navigation` view helper.
98
+ #
99
+ # A Twitter Bootstrap configuration:
100
+ #
101
+ # Example usage:
102
+ #
103
+ # <%= semantic_navigation :primary, config: :bootstrap, class: 'nav-pills' %>
104
+ #
105
+ # Or to create a full navigation bar using twitter bootstrap you could use the following in your view:
106
+ # <div class="navbar">
107
+ # <div class="navbar-inner">
108
+ # <a class="brand" href="/">Title</a>
109
+ # <%= semantic_navigation :primary, config: :bootstrap %>
110
+ # </div>
111
+ # </div>
112
+ config.builder bootstrap: Navigasmic::Builder::ListBuilder do |builder|
113
+
114
+ # Set the nav and nav-pills css (you can also use 'nav nav-tabs') -- or remove them if you're using this inside a
115
+ # navbar.
116
+ builder.wrapper_class = 'nav nav-pills'
117
+
118
+ # Set the classed for items that have nested items, and that are nested items.
119
+ builder.has_nested_class = 'dropdown'
120
+ builder.is_nested_class = 'dropdown-menu'
121
+
122
+ # For dropdowns to work you'll need to include the bootstrap dropdown js
123
+ # For groups, we adjust the markup so they'll be clickable and be picked up by the javascript.
124
+ builder.label_generator = proc do |label, has_link, has_nested|
125
+ if !has_nested || has_link
126
+ "<span>#{label}</span>"
127
+ else
128
+ link_to("#{label}<b class='caret'></b>".html_safe, '#', class: 'dropdown-toggle', data: {toggle: 'dropdown'})
129
+ end
130
+ end
131
+
132
+ # For items, we adjust the links so they're '#', and do the same as for groups. This allows us to use more complex
133
+ # highlighting rules for dropdowns.
134
+ builder.link_generator = proc do |label, link, options, has_nested|
135
+ if has_nested
136
+ link = '#'
137
+ label << "<b class='caret'></b>"
138
+ options.merge!(class: 'dropdown-toggle', data: {toggle: 'dropdown'})
139
+ end
140
+ link_to(label, link, options)
141
+ end
142
+
143
+ end
144
+
145
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '990bac5b6d4f068883259503539cad4e9ec00f137986fcbc718a1e0b645af7a3eb0340468f8fae09958a6281190396d65789b6316af61e47a8cbda3c8c071a0e'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Localized label"
@@ -0,0 +1,68 @@
1
+ Dummy::Application.routes.draw do
2
+
3
+ root to: 'application#welcome'
4
+
5
+ match '/my_awesome_blog' => 'blog/posts#index', as: :my_awesome_blog
6
+ namespace :blog do
7
+ resources :posts
8
+ resources :links
9
+ end
10
+
11
+ # The priority is based upon order of creation:
12
+ # first created -> highest priority.
13
+
14
+ # Sample of regular route:
15
+ # match 'products/:id' => 'catalog#view'
16
+ # Keep in mind you can assign values other than :controller and :action
17
+
18
+ # Sample of named route:
19
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
20
+ # This route can be invoked with purchase_url(:id => product.id)
21
+
22
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
23
+ # resources :products
24
+
25
+ # Sample resource route with options:
26
+ # resources :products do
27
+ # member do
28
+ # get 'short'
29
+ # post 'toggle'
30
+ # end
31
+ #
32
+ # collection do
33
+ # get 'sold'
34
+ # end
35
+ # end
36
+
37
+ # Sample resource route with sub-resources:
38
+ # resources :products do
39
+ # resources :comments, :sales
40
+ # resource :seller
41
+ # end
42
+
43
+ # Sample resource route with more complex sub-resources
44
+ # resources :products do
45
+ # resources :comments
46
+ # resources :sales do
47
+ # get 'recent', :on => :collection
48
+ # end
49
+ # end
50
+
51
+ # Sample resource route within a namespace:
52
+ # namespace :admin do
53
+ # # Directs /admin/products/* to Admin::ProductsController
54
+ # # (app/controllers/admin/products_controller.rb)
55
+ # resources :products
56
+ # end
57
+
58
+ # You can have the root of your site routed with "root"
59
+ # just remember to delete public/index.html.
60
+ # root :to => 'welcome#index'
61
+
62
+ # See how all your routes lay out with "rake routes"
63
+
64
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
65
+ # Note: This route will make all actions in every controller accessible via GET requests.
66
+ # match ':controller(/:action(/:id))(.:format)'
67
+
68
+ end