simple-navigation 3.11.0 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CHANGELOG +11 -0
- data/Gemfile +2 -16
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +40 -0
- data/Rakefile +6 -39
- data/generators/navigation_config/templates/config/navigation.rb +7 -5
- data/init.rb +1 -0
- data/install.rb +5 -0
- data/lib/simple_navigation/adapters/rails.rb +5 -1
- data/lib/simple_navigation/core/configuration.rb +5 -1
- data/lib/simple_navigation/core/item.rb +2 -1
- data/lib/simple_navigation/core/item_adapter.rb +4 -4
- data/lib/simple_navigation/core/item_container.rb +6 -1
- data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +2 -2
- data/lib/simple_navigation/rendering/renderer/links.rb +2 -2
- data/lib/simple_navigation/rendering/renderer/list.rb +1 -1
- data/lib/simple_navigation/version.rb +3 -0
- data/lib/simple_navigation.rb +1 -0
- data/simple-navigation.gemspec +40 -0
- data/spec/initializers/have_css_matcher.rb +13 -0
- data/spec/lib/simple_navigation/adapters/padrino_spec.rb +23 -25
- data/spec/lib/simple_navigation/adapters/rails_spec.rb +276 -250
- data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +64 -53
- data/spec/lib/simple_navigation/core/configuration_spec.rb +128 -106
- data/spec/lib/simple_navigation/core/item_adapter_spec.rb +144 -168
- data/spec/lib/simple_navigation/core/item_container_spec.rb +361 -339
- data/spec/lib/simple_navigation/core/item_spec.rb +571 -434
- data/spec/lib/simple_navigation/core/items_provider_spec.rb +35 -49
- data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +194 -173
- data/spec/lib/simple_navigation/rendering/helpers_spec.rb +381 -225
- data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +205 -164
- data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +87 -67
- data/spec/lib/simple_navigation/rendering/renderer/json_spec.rb +52 -31
- data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +75 -48
- data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +62 -174
- data/spec/lib/simple_navigation/rendering/renderer/text_spec.rb +41 -28
- data/spec/lib/simple_navigation_spec.rb +207 -225
- data/spec/spec_helper.rb +53 -82
- data/uninstall.rb +1 -0
- metadata +100 -22
- data/README +0 -22
- data/VERSION +0 -1
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
*3.12.0
|
2
|
+
|
3
|
+
* Relax hash constraint on item_adapter. Thanks to Ramon Tayag.
|
4
|
+
* Fixed hidden special character in navigation template. Credits to Stef Lewandowski
|
5
|
+
* Added full MIT license text. Thanks to Ben Armstrong.
|
6
|
+
* Added license to gemspec. Thanks to Troy Thompson.
|
7
|
+
* Allow defining other html attributes than :id and :class on menu container. Credits to Jacek Tomaszewski.
|
8
|
+
* Added new config option "consider_item_names_as_safe". Thanks to Alexey Naumov.
|
9
|
+
* Big cleanup of specs, removed jeweler in favor of the "bundler" way. Huge thank you to Simon Courtois.
|
10
|
+
* Added more powerful name generator which yields the item itself in addition to the item's name. Credits to Simon Curtois.
|
11
|
+
|
1
12
|
*3.11.0
|
2
13
|
|
3
14
|
* Added Json renderer. Thanks to Alberto Avila.
|
data/Gemfile
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
# install the rails group if you want to ensure rails compatibility -
|
6
|
-
# but you've already got rails installed anyway, right? :-)
|
7
|
-
group :rails do
|
8
|
-
gem 'actionpack', '>= 2.3.2'
|
9
|
-
end
|
10
|
-
|
11
|
-
group :development do
|
12
|
-
gem 'rspec', '>= 2.0.1'
|
13
|
-
gem 'json_spec', '~> 1.1.1'
|
14
|
-
gem 'rake'
|
15
|
-
gem 'rdoc'
|
16
|
-
gem 'jeweler'
|
17
|
-
end
|
3
|
+
gemspec
|
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 codeplant GmbH
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Simple Navigation
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/simple-navigation.png)](http://badge.fury.io/rb/simple-navigation)
|
4
|
+
[![Build Status](https://secure.travis-ci.org/codeplant/simple-navigation.png?branch=master)](http://travis-ci.org/codeplant/simple-navigation)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/codeplant/simple-navigation.png)](https://codeclimate.com/github/codeplant/simple-navigation)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/codeplant/simple-navigation/badge.png)](https://coveralls.io/r/codeplant/simple-navigation)
|
7
|
+
|
8
|
+
Simple Navigation is a ruby library for creating navigations (with multiple levels) for your Rails 2, Rails 3, Rails 4, Sinatra or Padrino applications. It runs with all ruby versions (including ruby 2.0).
|
9
|
+
|
10
|
+
## Documentation
|
11
|
+
|
12
|
+
For the complete documentation, take a look at the [project's wiki](http://wiki.github.com/codeplant/simple-navigation).
|
13
|
+
|
14
|
+
## RDoc
|
15
|
+
|
16
|
+
You can consult the project's RDoc on [RubyDoc.info](http://rubydoc.info/github/codeplant/simple-navigation/frames).
|
17
|
+
|
18
|
+
If you need to generate the RDoc files locally, check out the repository and simply call the `rake rdoc` in the project's folder.
|
19
|
+
|
20
|
+
## Online Demo
|
21
|
+
|
22
|
+
You can try simple-navigation with the [online demo](http://simple-navigation-demo.codeplant.ch).
|
23
|
+
|
24
|
+
The source code of this online demo is [available on Github](http://github.com/codeplant/simple-navigation-demo).
|
25
|
+
|
26
|
+
## Feedback and Questions
|
27
|
+
|
28
|
+
Don't hesitate to come talk on the [project's group](http://groups.google.com/group/simple-navigation).
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it (https://github.com/codeplant/simple-navigation/fork)
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
Copyright (c) 2014 codeplant GmbH, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,47 +1,14 @@
|
|
1
|
-
require '
|
1
|
+
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
3
|
require 'rdoc/task'
|
4
4
|
|
5
|
-
|
6
|
-
task :default => :spec
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
6
|
|
8
|
-
|
9
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
10
|
-
t.rspec_opts = ['--colour --format progress']
|
11
|
-
end
|
12
|
-
|
13
|
-
namespace :spec do
|
14
|
-
desc "Run all specs with RCov"
|
15
|
-
RSpec::Core::RakeTask.new(:rcov) do |t|
|
16
|
-
t.rspec_opts = ['--colour --format progress']
|
17
|
-
t.rcov = true
|
18
|
-
t.rcov_opts = ['--exclude', 'spec,/Users/']
|
19
|
-
end
|
20
|
-
end
|
7
|
+
task default: :spec
|
21
8
|
|
22
|
-
|
23
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
9
|
+
RDoc::Task.new do |rdoc|
|
24
10
|
rdoc.rdoc_dir = 'rdoc'
|
25
11
|
rdoc.title = 'SimpleNavigation'
|
26
|
-
rdoc.options << '--
|
27
|
-
rdoc.rdoc_files.include('README')
|
28
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
-
end
|
30
|
-
|
31
|
-
begin
|
32
|
-
require 'jeweler'
|
33
|
-
Jeweler::Tasks.new do |gemspec|
|
34
|
-
gemspec.name = "simple-navigation"
|
35
|
-
gemspec.summary = "simple-navigation is a ruby library for creating navigations (with multiple levels) for your Rails2, Rails3, Sinatra or Padrino application."
|
36
|
-
gemspec.email = "andreas.schacke@gmail.com"
|
37
|
-
gemspec.homepage = "http://github.com/andi/simple-navigation"
|
38
|
-
gemspec.description = "With the simple-navigation gem installed you can easily create multilevel navigations for your Rails, Sinatra or Padrino applications. The navigation is defined in a single configuration file. It supports automatic as well as explicit highlighting of the currently active navigation through regular expressions."
|
39
|
-
gemspec.authors = ["Andi Schacke", "Mark J. Titorenko"]
|
40
|
-
gemspec.rdoc_options = ["--inline-source", "--charset=UTF-8"]
|
41
|
-
gemspec.files = FileList["[A-Z]*", "{lib,spec,rails,generators}/**/*"] - FileList["**/*.log", "Gemfile.lock"]
|
42
|
-
gemspec.rubyforge_project = 'andi'
|
43
|
-
end
|
44
|
-
Jeweler::GemcutterTasks.new
|
45
|
-
rescue LoadError => e
|
46
|
-
puts "Jeweler not available (#{e}). Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
12
|
+
rdoc.options << '--inline-source'
|
13
|
+
rdoc.rdoc_files.include('README.md', 'lib/**/*.rb')
|
47
14
|
end
|
@@ -24,11 +24,14 @@ SimpleNavigation::Configuration.run do |navigation|
|
|
24
24
|
|
25
25
|
# 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.
|
26
26
|
# The example below shows how to wrap items spans.
|
27
|
-
# navigation.name_generator = Proc.new {|name| "<span>#{name}</span>"}
|
27
|
+
# navigation.name_generator = Proc.new {|name, item| "<span>#{name}</span>"}
|
28
28
|
|
29
29
|
# The auto highlight feature is turned on by default.
|
30
30
|
# This turns it off globally (for the whole plugin)
|
31
31
|
# navigation.auto_highlight = false
|
32
|
+
|
33
|
+
# If this option is set to true, all item names will be considered as safe (passed through html_safe). Defaults to false.
|
34
|
+
# navigation.consider_item_names_as_safe = false
|
32
35
|
|
33
36
|
# Define the primary navigation
|
34
37
|
navigation.items do |primary|
|
@@ -60,13 +63,12 @@ SimpleNavigation::Configuration.run do |navigation|
|
|
60
63
|
# You can also specify a condition-proc that needs to be fullfilled to display an item.
|
61
64
|
# Conditions are part of the options. They are evaluated in the context of the views,
|
62
65
|
# thus you can use all the methods and vars you have available in the views.
|
63
|
-
primary.item :key_3, 'Admin', url, :class => 'special', :if => Proc.new
|
66
|
+
primary.item :key_3, 'Admin', url, :class => 'special', :if => Proc.new { current_user.admin? }
|
64
67
|
primary.item :key_4, 'Account', url, :unless => Proc.new { logged_in? }
|
65
68
|
|
66
|
-
# you can also specify
|
69
|
+
# you can also specify html attributes to attach to this particular level
|
67
70
|
# works for all levels of the menu
|
68
|
-
# primary.
|
69
|
-
# primary.dom_class = 'menu-class'
|
71
|
+
# primary.dom_attributes = {id: 'menu-id', class: 'menu-class'}
|
70
72
|
|
71
73
|
# You can turn off auto highlighting for a specific level
|
72
74
|
# primary.auto_highlight = false
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/rails/init"
|
data/install.rb
ADDED
@@ -39,7 +39,7 @@ module SimpleNavigation
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def link_to(name, url, options={})
|
42
|
-
template.link_to(
|
42
|
+
template.link_to(link_title(name), url, options) if template
|
43
43
|
end
|
44
44
|
|
45
45
|
def content_tag(type, content, options={})
|
@@ -76,6 +76,10 @@ module SimpleNavigation
|
|
76
76
|
context.controller || context :
|
77
77
|
context
|
78
78
|
end
|
79
|
+
|
80
|
+
def link_title name
|
81
|
+
SimpleNavigation.config.consider_item_names_as_safe ? html_safe(name) : name
|
82
|
+
end
|
79
83
|
|
80
84
|
end
|
81
85
|
end
|
@@ -6,7 +6,7 @@ module SimpleNavigation
|
|
6
6
|
class Configuration
|
7
7
|
include Singleton
|
8
8
|
|
9
|
-
attr_accessor :renderer, :selected_class, :active_leaf_class, :autogenerate_item_ids, :id_generator, :auto_highlight, :name_generator
|
9
|
+
attr_accessor :renderer, :selected_class, :active_leaf_class, :autogenerate_item_ids, :id_generator, :auto_highlight, :name_generator, :consider_item_names_as_safe
|
10
10
|
attr_reader :primary_navigation
|
11
11
|
|
12
12
|
class << self
|
@@ -32,6 +32,10 @@ module SimpleNavigation
|
|
32
32
|
@id_generator = Proc.new {|id| id.to_s }
|
33
33
|
@name_generator = Proc.new {|name| name}
|
34
34
|
@auto_highlight = true
|
35
|
+
@consider_item_names_as_safe = true
|
36
|
+
if defined?(ActiveSupport::Deprecation)
|
37
|
+
ActiveSupport::Deprecation.warn "simple-navigation: consider_item_names_as_safe will be set to false by default in 3.13.0 release, hence item names will be considered unsafe by default. See https://github.com/codeplant/simple-navigation/wiki", caller
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
41
|
# This is the main method for specifying the navigation items. It can be used in two ways:
|
@@ -13,6 +13,7 @@ module SimpleNavigation
|
|
13
13
|
options = setup_url_and_options(url_or_options, options_or_nil)
|
14
14
|
@container.dom_class = options.delete(:container_class) if options[:container_class]
|
15
15
|
@container.dom_id = options.delete(:container_id) if options[:container_id]
|
16
|
+
@container.dom_attributes = options[:container_attributes] ? options.delete(:container_attributes) : {}
|
16
17
|
@container.selected_class = options.delete(:selected_class) if options[:selected_class]
|
17
18
|
@key = key
|
18
19
|
@method = options.delete(:method)
|
@@ -30,7 +31,7 @@ module SimpleNavigation
|
|
30
31
|
def name(options = {})
|
31
32
|
options.reverse_merge!(:apply_generator => true)
|
32
33
|
if (options[:apply_generator])
|
33
|
-
SimpleNavigation.config.name_generator.call(@name)
|
34
|
+
SimpleNavigation.config.name_generator.call(@name, self)
|
34
35
|
else
|
35
36
|
@name
|
36
37
|
end
|
@@ -20,13 +20,13 @@ module SimpleNavigation
|
|
20
20
|
# See SimpleNavigation::ItemContainer#item for the purpose of these methods.
|
21
21
|
class ItemAdapter
|
22
22
|
extend Forwardable
|
23
|
-
|
23
|
+
|
24
24
|
def_delegators :item, :key, :name, :url
|
25
25
|
|
26
26
|
attr_reader :item
|
27
27
|
|
28
28
|
def initialize(item)
|
29
|
-
@item = item.
|
29
|
+
@item = item.is_a?(Hash) ? to_object(item) : item
|
30
30
|
end
|
31
31
|
|
32
32
|
# Returns the options for this item. If the wrapped item does not implement an options method, an empty hash is returned.
|
@@ -45,7 +45,7 @@ module SimpleNavigation
|
|
45
45
|
end
|
46
46
|
|
47
47
|
protected
|
48
|
-
|
48
|
+
|
49
49
|
# Converts the specified hash into an object. Each key will be added as method.
|
50
50
|
#
|
51
51
|
def to_object(hash)
|
@@ -60,4 +60,4 @@ module SimpleNavigation
|
|
60
60
|
end
|
61
61
|
|
62
62
|
end
|
63
|
-
end
|
63
|
+
end
|
@@ -4,7 +4,7 @@ module SimpleNavigation
|
|
4
4
|
class ItemContainer
|
5
5
|
|
6
6
|
attr_reader :items, :level
|
7
|
-
attr_accessor :renderer, :dom_id, :dom_class, :auto_highlight, :selected_class
|
7
|
+
attr_accessor :renderer, :dom_id, :dom_class, :dom_attributes, :auto_highlight, :selected_class
|
8
8
|
|
9
9
|
def initialize(level=1) #:nodoc:
|
10
10
|
@level = level
|
@@ -13,6 +13,11 @@ module SimpleNavigation
|
|
13
13
|
@auto_highlight = true
|
14
14
|
end
|
15
15
|
|
16
|
+
def dom_attributes
|
17
|
+
# backward compability for #dom_id and #dom_class
|
18
|
+
(@dom_attributes || {}).merge({id: dom_id, class: dom_class}.reject{|k, v| v.nil?})
|
19
|
+
end
|
20
|
+
|
16
21
|
# Creates a new navigation item.
|
17
22
|
#
|
18
23
|
# The <tt>key</tt> is a symbol which uniquely defines your navigation item in the scope of the primary_navigation or the sub_navigation.
|
@@ -6,7 +6,7 @@ module SimpleNavigation
|
|
6
6
|
#
|
7
7
|
# By default, the renderer sets the item's key as dom_id for the rendered <a> element unless the config option <tt>autogenerate_item_ids</tt> is set to false.
|
8
8
|
# The id can also be explicitely specified by setting the id in the html-options of the 'item' method in the config/navigation.rb file.
|
9
|
-
# The ItemContainer's
|
9
|
+
# The ItemContainer's dom_attributes are applied to the surrounding <div> element.
|
10
10
|
#
|
11
11
|
class Breadcrumbs < SimpleNavigation::Renderer::Base
|
12
12
|
|
@@ -14,7 +14,7 @@ module SimpleNavigation
|
|
14
14
|
content = a_tags(item_container).join(join_with)
|
15
15
|
content_tag(:div,
|
16
16
|
prefix_for(content) + content,
|
17
|
-
|
17
|
+
item_container.dom_attributes)
|
18
18
|
end
|
19
19
|
|
20
20
|
protected
|
@@ -8,14 +8,14 @@ module SimpleNavigation
|
|
8
8
|
#
|
9
9
|
# By default, the renderer sets the item's key as dom_id for the rendered <a> element unless the config option <tt>autogenerate_item_ids</tt> is set to false.
|
10
10
|
# The id can also be explicitely specified by setting the id in the html-options of the 'item' method in the config/navigation.rb file.
|
11
|
-
# The ItemContainer's
|
11
|
+
# The ItemContainer's dom_attributes are applied to the surrounding <div> element.
|
12
12
|
#
|
13
13
|
class Links < SimpleNavigation::Renderer::Base
|
14
14
|
def render(item_container)
|
15
15
|
div_content = item_container.items.inject([]) do |list, item|
|
16
16
|
list << tag_for(item)
|
17
17
|
end.join(join_with)
|
18
|
-
content_tag(:div, div_content,
|
18
|
+
content_tag(:div, div_content, item_container.dom_attributes)
|
19
19
|
end
|
20
20
|
|
21
21
|
protected
|
@@ -21,7 +21,7 @@ module SimpleNavigation
|
|
21
21
|
if skip_if_empty? && item_container.empty?
|
22
22
|
''
|
23
23
|
else
|
24
|
-
content_tag((options[:ordered] ? :ol : :ul), list_content,
|
24
|
+
content_tag((options[:ordered] ? :ol : :ul), list_content, item_container.dom_attributes)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/simple_navigation.rb
CHANGED
@@ -3,6 +3,7 @@ require 'active_support/core_ext/array'
|
|
3
3
|
require 'active_support/core_ext/hash'
|
4
4
|
require 'active_support/core_ext/module/attribute_accessors'
|
5
5
|
|
6
|
+
require 'simple_navigation/version'
|
6
7
|
require 'simple_navigation/core'
|
7
8
|
require 'simple_navigation/rendering'
|
8
9
|
require 'simple_navigation/adapters'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_navigation/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'simple-navigation'
|
8
|
+
spec.version = SimpleNavigation::VERSION
|
9
|
+
spec.authors = ['Andi Schacke', 'Mark J. Titorenko']
|
10
|
+
spec.email = ['andi@codeplant.ch']
|
11
|
+
spec.description = "With the simple-navigation gem installed you can easily " \
|
12
|
+
"create multilevel navigations for your Rails, Sinatra or "\
|
13
|
+
"Padrino applications. The navigation is defined in a " \
|
14
|
+
"single configuration file. It supports automatic as well "\
|
15
|
+
"as explicit highlighting of the currently active " \
|
16
|
+
"navigation through regular expressions."
|
17
|
+
spec.summary = "simple-navigation is a ruby library for creating navigations "\
|
18
|
+
"(with multiple levels) for your Rails2, Rails3, Rails4, Sinatra or " \
|
19
|
+
"Padrino application."
|
20
|
+
spec.homepage = 'http://github.com/codeplant/simple-navigation'
|
21
|
+
spec.license = 'MIT'
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0")
|
24
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.rdoc_options = ['--inline-source', '--charset=UTF-8']
|
29
|
+
|
30
|
+
spec.add_runtime_dependency 'activesupport', '>= 2.3.2'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'actionpack', '>= 2.3.2'
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
34
|
+
spec.add_development_dependency 'coveralls', '~> 0.7'
|
35
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.2'
|
36
|
+
spec.add_development_dependency 'json_spec', '~> 1.1'
|
37
|
+
spec.add_development_dependency 'rake'
|
38
|
+
spec.add_development_dependency 'rdoc'
|
39
|
+
spec.add_development_dependency 'rspec', '~> 2.0'
|
40
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
RSpec::Matchers.define :have_css do |expected, times|
|
2
|
+
match do |actual|
|
3
|
+
HTML::Selector.new(expected).select(actual).should have_at_least(times || 1).entry
|
4
|
+
end
|
5
|
+
|
6
|
+
failure_message_for_should do |actual|
|
7
|
+
"expected #{actual.to_s} to have #{times || 1} elements matching '#{expected}'"
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_for_should_not do |actual|
|
11
|
+
"expected #{actual.to_s} not to have #{times || 1} elements matching '#{expected}'"
|
12
|
+
end
|
13
|
+
end
|
@@ -1,31 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module SimpleNavigation
|
4
|
+
module Adapters
|
5
|
+
describe Padrino do
|
6
|
+
let(:adapter) { SimpleNavigation::Adapters::Padrino.new(context) }
|
7
|
+
let(:content) { double(:content) }
|
8
|
+
let(:context) { double(:context, request: request) }
|
9
|
+
let(:request) { double(:request) }
|
4
10
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'content_tag' do
|
24
|
-
it "should delegate to context" do
|
25
|
-
@content.should_receive(:html_safe).and_return('content')
|
26
|
-
@context.should_receive(:content_tag).with('type', 'content', :my_option => true)
|
27
|
-
@adapter.content_tag('type', @content, :my_option => true)
|
11
|
+
describe '#link_to' do
|
12
|
+
it 'delegates to context' do
|
13
|
+
expect(context).to receive(:link_to)
|
14
|
+
.with('name', 'url', :my_option => true)
|
15
|
+
adapter.link_to('name', 'url', :my_option => true)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#content_tag' do
|
20
|
+
it 'delegates to context' do
|
21
|
+
expect(content).to receive(:html_safe).and_return('content')
|
22
|
+
expect(context).to receive(:content_tag)
|
23
|
+
.with('type', 'content', my_option: true)
|
24
|
+
adapter.content_tag('type', content, my_option: true)
|
25
|
+
end
|
26
|
+
end
|
28
27
|
end
|
29
28
|
end
|
30
|
-
|
31
29
|
end
|