nutmeg 0.0.1 → 0.0.2

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: f7bbd92eb161de717a7158fcafb80113168d0c86
4
- data.tar.gz: 4606cdc2c77bdacdfcff1ec39c4751ea58d06ddb
3
+ metadata.gz: 839f3094a2c5de6f59f396e3c31a456c2910cee0
4
+ data.tar.gz: c58024fe9671ff83ab4a3e6b6104b6b440999ead
5
5
  SHA512:
6
- metadata.gz: 71b7063fce1deba45ac519b44ea1d77dbb257459ceb91b1edbf2f4f09e5eb83c0a08302941c765605b146845f4685f28c97bcd7ce8b5442fd311c7dbf4f31b2e
7
- data.tar.gz: c2840fd116ce1e535f29c9c073639425351a7c4952cdc5ee53e344025333c6a4289ff550ab7c441e23f7f72d5bcb09196dc78a0a0ba0d5e774b52c60dbab1f3d
6
+ metadata.gz: f2a22c789b3eb03b59c21069ec5408e5ada70dcaa21d6b3dafa44bb9917933b062a8e92ede09544ad6b737598e842ba7b1252655fc540f9db62c315069c90d55
7
+ data.tar.gz: 3908dcf8684c2e9b53e33182001586acf4ae8bc162a600caa9abfc1ed014225d6465e804874cf6bd4a949e58f36fb4da7a37f43bcdb3b9b3a4c76771441e4fed
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+ - "2.1.1"
6
+ - "2.1.2"
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/nutmeg.svg)](http://badge.fury.io/rb/nutmeg) [![Build Status](https://travis-ci.org/pressdoc/nutmeg.svg?branch=master)](https://travis-ci.org/pressdoc/nutmeg)
1
2
  # Nutmeg
2
3
 
3
4
  Help you build and show a menu tree in rails
@@ -10,15 +10,18 @@ module Nutmeg
10
10
  [print_node(@tree.original, tags_given)].join("")
11
11
  end
12
12
 
13
- def node_html(node, active, leaf)
14
- "<li class='level_#{node.level}#{leaf ? ' leaf' : ''}#{active ? ' active' : ''}'>"
13
+ def node_html(node, active, leaf, content)
14
+ "<li class='level_#{node.level}#{leaf ? ' leaf' : ''}#{active ? ' active' : ''}'> <a #{(leaf) ? "href=\'#{node_path(node)}\'" : ''}>#{content}</a>"
15
+ end
16
+
17
+ def node_path(node)
18
+ ([""] + node.parentage.map{|p| p.content[:slug]}.reverse.reject{|n| n == "root"} + [node.content[:slug]]).join("/")
15
19
  end
16
20
 
17
21
  def print_node(node, tags_given)
18
22
  output = []
19
23
  if render_node?(node,tags_given)
20
- output << node_html(node, (!@tree.get_paths(tags_given).first.nil? && @tree.get_paths(tags_given).first.map(&:name).include?(node.name)), node.is_leaf? )
21
- output << node.content[:slug]
24
+ output << node_html(node, (!@tree.get_paths(tags_given).first.nil? && @tree.get_paths(tags_given).first.map(&:name).include?(node.name)), node.is_leaf?, node.content[:slug])
22
25
  end
23
26
 
24
27
  if !traverse_node?(node, tags_given)
@@ -1,3 +1,3 @@
1
1
  module Nutmeg
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/files/tree.yml CHANGED
@@ -38,10 +38,10 @@ tags:
38
38
  5: collections
39
39
  6: events
40
40
  7: collaborations
41
- 8: winter 2015
42
- 9: spring 2015
43
- 10: summer 2015
44
- 11: afro jack
45
- 12: pr.co
46
- 13: lowlands 2014
47
- 14: sinterklaas 2014
41
+ 8: winter_2015
42
+ 9: spring_2015
43
+ 10: summer_2015
44
+ 11: afro_jack
45
+ 12: pr_co
46
+ 13: lowlands_2014
47
+ 14: sinterklaas_2014
data/spec/spec_helper.rb CHANGED
@@ -1 +1,7 @@
1
- require 'nutmeg'
1
+ require 'nutmeg'
2
+ # From rspec generator
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+
5
+ RSpec.configure do |config|
6
+ config.order = "random"
7
+ end
@@ -9,7 +9,7 @@ describe Nutmeg::TagTreeHelper do
9
9
  describe "#print_html" do
10
10
  it "outputs html" do
11
11
  expect(Nutmeg::TagTreeHelper.new(@tree_from_yaml.tree).print_html([1]).class).to eq(String)
12
- expect(Nutmeg::TagTreeHelper.new(@tree_from_yaml.tree).print_html([1,3,5,10])).to eq("<ul><li class='level_1 active'>north<ul><li class='level_2 active'>men<ul><li class='level_3 active'>collections<ul><li class='level_4 leaf'>winter 2015</li><li class='level_4 leaf'>spring 2015</li><li class='level_4 leaf active'>summer 2015</li></ul></li></ul></li><li class='level_2'>women<ul><li class='level_3'>collections<ul><li class='level_4 leaf'>winter 2015</li><li class='level_4 leaf'>spring 2015</li><li class='level_4 leaf'>summer 2015</li></ul></li></ul></li><li class='level_2'>events<ul><li class='level_3 leaf'>lowlands 2014</li><li class='level_3 leaf'>sinterklaas 2014</li></ul></li><li class='level_2'>collaborations<ul><li class='level_3 leaf'>afro jack</li><li class='level_3 leaf'>pr.co</li></ul></li></ul></li><li class='level_1'>south<ul></li></li></ul></li></ul>")
12
+ expect(Nutmeg::TagTreeHelper.new(@tree_from_yaml.tree).print_html([1,3,5,10])).to eq("<ul><li class='level_1 active'> <a >north</a><ul><li class='level_2 active'> <a >men</a><ul><li class='level_3 active'> <a >collections</a><ul><li class='level_4 leaf'> <a href='/north/men/collections/winter_2015'>winter_2015</a></li><li class='level_4 leaf'> <a href='/north/men/collections/spring_2015'>spring_2015</a></li><li class='level_4 leaf active'> <a href='/north/men/collections/summer_2015'>summer_2015</a></li></ul></li></ul></li><li class='level_2'> <a >women</a><ul><li class='level_3'> <a >collections</a><ul><li class='level_4 leaf'> <a href='/north/women/collections/winter_2015'>winter_2015</a></li><li class='level_4 leaf'> <a href='/north/women/collections/spring_2015'>spring_2015</a></li><li class='level_4 leaf'> <a href='/north/women/collections/summer_2015'>summer_2015</a></li></ul></li></ul></li><li class='level_2'> <a >events</a><ul><li class='level_3 leaf'> <a href='/north/events/lowlands_2014'>lowlands_2014</a></li><li class='level_3 leaf'> <a href='/north/events/sinterklaas_2014'>sinterklaas_2014</a></li></ul></li><li class='level_2'> <a >collaborations</a><ul><li class='level_3 leaf'> <a href='/north/collaborations/afro_jack'>afro_jack</a></li><li class='level_3 leaf'> <a href='/north/collaborations/pr_co'>pr_co</a></li></ul></li></ul></li><li class='level_1'> <a >south</a><ul></li></li></ul></li></ul>")
13
13
  end
14
14
  end
15
15
  end
data/tasks/rspec.rake CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'rspec/core/rake_task'
2
2
 
3
- RSpec::Core::RakeTask.new(:spec)
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task :default => :spec
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutmeg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis van der Vliet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-07 00:00:00.000000000 Z
11
+ date: 2014-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubytree
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
77
  - .rspec
78
+ - .travis.yml
78
79
  - Gemfile
79
80
  - LICENSE.txt
80
81
  - README.md