sigmund_liquid 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/sigmund.rb +5 -0
- data/lib/sigmund/liquid.rb +6 -0
- data/lib/sigmund/liquid/tags/children_nav.rb +101 -0
- data/lib/sigmund/liquid/tags/custom_nav.rb +0 -0
- data/lib/sigmund/liquid/version.rb +5 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTIwZmM0NzA4NmMzMWM4OWY4MWUzZGFhYjZlNjVlM2E4ZGJlZTljNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2U5NDc4MmIwODM2NmVhYjIzN2EzOTFmZWQyMjZiYzc5MTM0NmM2Yg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTkxOGQ3N2E3ZGEyY2U2YjFmMzViM2M5ODY1OGI1NmNiNWViODU4MTk5M2E1
|
10
|
+
ZGZjZTI5MzRlMDQ2YzRlZjA3ZWU4OWMwYTYxNTljNGIzMWY5NmE5YWYyODIx
|
11
|
+
NWQ0ZmYwMjk4YWQwZjBlYmViZTUyNmJkNjFiM2NjNzNmMTY0YTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZmEzYmUxMjc1NmRlMWJkNjBlYjFiYzk3ODM1ZDZkOGY2OTM0NDNiNDJiZTI1
|
14
|
+
NzE0ZTUzNjU1NzM3OTc2ZGE0NmFiZjZjNjBiODRkOGNkMDgyN2ZmNDgwMjRi
|
15
|
+
Y2Y3ODU1NDkxZTY5ZjYzMWQ4YWU0NDhjNGJiYTdjMjRlNmRjN2Q=
|
data/lib/sigmund.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
module Sigmund
|
2
|
+
module Liquid
|
3
|
+
module Tags
|
4
|
+
class ChildrenNav < ::Liquid::Tag
|
5
|
+
|
6
|
+
Syntax = /(#{::Liquid::Expression}+)?/
|
7
|
+
|
8
|
+
def initialize(tag_name, markup, tokens, context)
|
9
|
+
if markup =~ Syntax
|
10
|
+
@options = { id: 'nav', depth: 1, class: '', active_class: 'active'}
|
11
|
+
markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
|
12
|
+
@options[:exclude] = Regexp.new(@options[:exclude]) if @options[:exclude]
|
13
|
+
else
|
14
|
+
raise ::Liquid::SyntaxError.new("Syntax Error in 'children_nav ' - Valid syntax: children_nav <options>")
|
15
|
+
end
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def render(context)
|
20
|
+
@site = context.registers[:site]
|
21
|
+
@page = context.registers[:page] #current page for active class
|
22
|
+
page = get_page_by_slug()
|
23
|
+
render_entry_children(context, page, 1)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Determines root node for the list with the page slug
|
29
|
+
def get_page_by_slug()
|
30
|
+
return [] unless @options[:page_slug]
|
31
|
+
page = @site.pages.where( slug: @options[:page_slug] ).first
|
32
|
+
if page.nil?
|
33
|
+
raise ::Liquid::SyntaxError.new("Slug '#{@options[:page_slug]}'' doesn't exists")
|
34
|
+
end
|
35
|
+
page
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns a list element, a link to the page and its children
|
39
|
+
def render_entry_link(context, page, css, depth)
|
40
|
+
selected = @page.fullpath =~ /^#{page.fullpath}(\/.*)?$/ ? " #{@options[:active_class]}" : ''
|
41
|
+
|
42
|
+
icon = @options[:icon] ? '<span></span>' : ''
|
43
|
+
title = render_title(context, page)
|
44
|
+
label = %{#{icon if @options[:icon] != 'after' }#{title}#{icon if @options[:icon] == 'after' }}
|
45
|
+
|
46
|
+
href = File.join('/', @site.localized_page_fullpath(page))
|
47
|
+
|
48
|
+
output = %{<li id="#{page.slug.to_s.dasherize}-link" class="link#{selected} #{css}">}
|
49
|
+
output << %{<a href="#{href}">#{label}</a>}
|
50
|
+
output << render_entry_children(context, page, depth.succ) if (depth.succ <= @options[:depth].to_i)
|
51
|
+
output << %{</li>}
|
52
|
+
|
53
|
+
output.strip
|
54
|
+
end
|
55
|
+
|
56
|
+
# Recursively creates a nested unordered list for the depth specified
|
57
|
+
def render_entry_children(context, page, depth)
|
58
|
+
output = %{}
|
59
|
+
children = page.children_with_minimal_attributes.reject { |c| !include_page?(c) }
|
60
|
+
if children.present?
|
61
|
+
output = %{<ul id="#{@options[:id]}-#{page.slug.to_s.dasherize}" >}
|
62
|
+
children.each do |c, page|
|
63
|
+
css = []
|
64
|
+
css << 'first' if children.first == c
|
65
|
+
css << 'last' if children.last == c
|
66
|
+
output << render_entry_link(context, c, css.join(' '), depth)
|
67
|
+
end
|
68
|
+
output << %{</ul>}
|
69
|
+
end
|
70
|
+
|
71
|
+
output
|
72
|
+
end
|
73
|
+
|
74
|
+
def render_title(context, page)
|
75
|
+
if @options[:liquid_render]
|
76
|
+
context.stack do
|
77
|
+
context['page'] = page
|
78
|
+
@options[:liquid_render].render(context)
|
79
|
+
end
|
80
|
+
else
|
81
|
+
page.title
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Determines whether or not a page should be a part of the menu
|
86
|
+
def include_page?(page)
|
87
|
+
if !page.listed? || page.templatized? || !page.published?
|
88
|
+
false
|
89
|
+
elsif @options[:exclude]
|
90
|
+
(page.fullpath =~ @options[:exclude]).nil?
|
91
|
+
else
|
92
|
+
true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
::Liquid::Template.register_tag('children_nav', ChildrenNav)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sigmund_liquid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- amainguy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3'
|
55
|
+
description: Overrides or add functionalities to locomotive_liquid gem
|
56
|
+
email:
|
57
|
+
- amainguy@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/sigmund/liquid/tags/children_nav.rb
|
63
|
+
- lib/sigmund/liquid/tags/custom_nav.rb
|
64
|
+
- lib/sigmund/liquid/version.rb
|
65
|
+
- lib/sigmund/liquid.rb
|
66
|
+
- lib/sigmund.rb
|
67
|
+
homepage: ''
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.0.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Custom liquid elements
|
91
|
+
test_files: []
|