som_liquid 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee45cb45b4275171783e0485a9bfc38e3184e33d
4
+ data.tar.gz: 55fff08d6df13eda3ab76b08d3979cfcec17e5cd
5
+ SHA512:
6
+ metadata.gz: bc6ec4789917f2c58c8a82dd318a920846cce26fc79568dacd9a2988fce5869eecc571efb223ab6c39c9b80380df94937e4ff1a7206b450b471fbaf5a53ef597
7
+ data.tar.gz: ee1a522fd1458b3b36e77eabfbd06bd4b9cf22d0bc9c3ca02799328ea09d9671b9b08b1a237274f85b8a4c7ef3153061799d7de704028bac7ad61f1bbc7de236
@@ -0,0 +1,74 @@
1
+ module Som
2
+ module Liquid
3
+ module Tags
4
+ class ImprovedLinkTo < Locomotive::Steam::Liquid::Tags::Hybrid
5
+
6
+ include Locomotive::Steam::Liquid::Tags::Concerns::I18nPage
7
+ include Locomotive::Steam::Liquid::Tags::Concerns::Path
8
+
9
+ Syntax = /(#{::Liquid::VariableSignature}+)/o
10
+
11
+ attr_accessor :current_page
12
+
13
+ def initialize(tag_name, markup, options)
14
+ markup =~ Syntax
15
+ self.set_options(markup, options)
16
+ super
17
+ end
18
+
19
+ def render(context)
20
+ self.current_page = context.registers[:page]
21
+
22
+ render_path(context) do |page, path|
23
+ label = label_from_page(page)
24
+
25
+ if render_as_block?
26
+ context.stack do
27
+ context.scopes.last['target'] = page
28
+ label = super.html_safe
29
+ end
30
+ end
31
+
32
+ tag_attributes = build_tag_attributes(page)
33
+ %{<a #{tag_attributes} href="#{path}">#{label}</a>}
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ def label_from_page(page)
40
+ if page.templatized?
41
+ page.send(:_source).content_entry._label
42
+ else
43
+ page.title
44
+ end
45
+ end
46
+
47
+ def page_active?(page)
48
+ self.current_page.fullpath =~ /^#{page.fullpath}(\/.*)?$/
49
+ end
50
+
51
+ def build_tag_attributes(page)
52
+ css_class = page_active?(page) ? "#{@_options[:class]} active".strip : "#{@_options[:class]}"
53
+ tag_attributes = css_class.blank? ? "" : %{class="#{css_class}" }
54
+ @_options.each do |key, value|
55
+ unless (key == :class || value.blank?)
56
+ attribute = key.to_s
57
+ attribute = attribute.gsub('_','-') if attribute.include? "data_"
58
+ tag_attributes << "#{attribute}=#{value} "
59
+ end
60
+ end
61
+ tag_attributes.strip
62
+ end
63
+
64
+ def set_options(markup, options)
65
+ @_options = {id: '', class: ''}
66
+ markup.scan(::Liquid::TagAttributes) { |key, value| @_options[key.to_sym] = value.gsub(/"|'/, '') }
67
+ end
68
+
69
+ end
70
+
71
+ ::Liquid::Template.register_tag('improved_link_to', ImprovedLinkTo)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,5 @@
1
+ module Som
2
+ module Liquid
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/lib/som/liquid.rb ADDED
@@ -0,0 +1,6 @@
1
+ %w{. tags drops filters}.each do |dir|
2
+ Dir[File.join(File.dirname(__FILE__), 'liquid', dir, '*.rb')].each { |lib| require lib }
3
+ end
4
+
5
+ module Liquid
6
+ end
data/lib/som_liquid.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "som/liquid/version"
2
+ require "som/liquid"
3
+
4
+ module Som
5
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: som_liquid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - amainguy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-16 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Overrides or add functionalities to locomotive_liquid gem
42
+ email:
43
+ - amainguy@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/som/liquid.rb
49
+ - lib/som/liquid/tags/improved_link_to.rb
50
+ - lib/som/liquid/version.rb
51
+ - lib/som_liquid.rb
52
+ homepage: ''
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.4.5.1
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Custom liquid elements
76
+ test_files: []