locomotivecms_wagon 1.3.2 → 1.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76b2020908c1a171019f9559425d9cd3765ca893
4
- data.tar.gz: 87806b21c18e81bb3c7e1ffe89fc62cef2737398
3
+ metadata.gz: ddf389fd19683084ab7f2c71ceb20bba27a863a8
4
+ data.tar.gz: 7fb14dffa20d08c0df5bcf5a887f84803de98e5d
5
5
  SHA512:
6
- metadata.gz: 0af0ad2b617f60e733a1bf04e6fb414246507e1468957176f4653740e6c7b9d2f71db7e15e1a808d1b707681d88563c885e5ca78f858205b908705c0609282f1
7
- data.tar.gz: 971d7d9f06a6e68a3d93d52d577880b5e0d38e35fc2eebc9bf664e9d23d7b9bb67b5f323fbfafa9d5c7d992ba11f62c46f0287a6086f04303bc5b601279f9fef
6
+ metadata.gz: a65598dd4dd41faddc22c6b358d06e0b821f8d212eea46f03977eded9cc3aad65a92de840b2302151719ffdeb8b8e329ed1212baf2e724f1d37703214b1927e1
7
+ data.tar.gz: 37eb257956b84207ac3bb598a4e24e739b99082540d9626234ac02e6b1f8a5050a66f780dd25e16bc88f3ed6ce1932e348a8b67d62e9dc739eb7f133979b6cd3
@@ -26,28 +26,25 @@ module Locomotive
26
26
  raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.consume"), options[:line])
27
27
  end
28
28
 
29
- @cache_key = Digest::SHA1.hexdigest(@target)
30
29
  @local_cache_key = self.hash
31
30
 
32
31
  super
33
32
  end
34
33
 
35
34
  def render(context)
36
- if @is_var
37
- @url = context[@url]
35
+ if instance_variable_defined? :@variable_name
36
+ @url = context[@variable_name]
38
37
  end
39
38
  render_all_without_cache(context)
40
39
  end
41
40
 
42
41
  protected
43
42
 
44
- def prepare_url(url)
45
- @url = url
46
- @is_var = false
47
- if @url.match(::Liquid::QuotedString)
48
- @url.gsub!(/['"]/, '')
49
- elsif @url.match(::Liquid::VariableSignature)
50
- @is_var = true
43
+ def prepare_url(token)
44
+ if token.match(::Liquid::QuotedString)
45
+ @url = token.gsub(/['"]/, '')
46
+ elsif token.match(::Liquid::VariableSignature)
47
+ @variable_name = token
51
48
  else
52
49
  raise ::Liquid::SyntaxError.new("Syntax Error in 'consume' - Valid syntax: consume <var> from \"<url>\" [username: value, password: value]")
53
50
  end
@@ -77,14 +74,14 @@ module Locomotive
77
74
  begin
78
75
  context.scopes.last[@target.to_s] = Locomotive::Wagon::Httparty::Webservice.consume(@url, @options.symbolize_keys)
79
76
  self.cached_response = context.scopes.last[@target.to_s]
80
- # rescue Errno::ECONNREFUSED
81
- # raise ConnectionRefused.new(@markup)
82
77
  rescue Timeout::Error
83
78
  context.scopes.last[@target.to_s] = self.cached_response
84
79
  rescue ::Liquid::Error => e
85
80
  raise e
86
81
  rescue => e
87
- raise ::Liquid::Error.new(e.message, line)
82
+ liquid_e = ::Liquid::Error.new(e.message, line)
83
+ liquid_e.set_backtrace(e.backtrace)
84
+ raise liquid_e
88
85
  end
89
86
 
90
87
  render_all(@nodelist, context)
@@ -6,6 +6,8 @@ module Locomotive
6
6
 
7
7
  Syntax = /(#{::Liquid::Expression}+)(#{::Liquid::TagAttributes}?)/
8
8
 
9
+ include PathHelper
10
+
9
11
  def initialize(tag_name, markup, tokens, options)
10
12
  if markup =~ Syntax
11
13
  @handle = $1
@@ -21,9 +23,8 @@ module Locomotive
21
23
  end
22
24
 
23
25
  def render(context)
24
- if page = self.retrieve_page_from_handle(context)
25
- label = self.label_from_page(page)
26
- path = self.public_page_url(context, page)
26
+ render_path(context) do |page, path|
27
+ label = label_from_page(page)
27
28
 
28
29
  if @render_as_block
29
30
  context.scopes.last['target'] = page
@@ -31,54 +32,11 @@ module Locomotive
31
32
  end
32
33
 
33
34
  %{<a href="#{path}">#{label}</a>}
34
- else
35
- raise Liquid::PageNotTranslated.new(%{[link_to] Unable to find a page for the #{@handle}. Wrong handle or missing template for your content.})
36
35
  end
37
36
  end
38
37
 
39
38
  protected
40
39
 
41
- def retrieve_page_from_handle(context)
42
- mounting_point = context.registers[:mounting_point]
43
-
44
- context.scopes.reverse_each do |scope|
45
- handle = scope[@handle] || @handle
46
-
47
- page = case handle
48
- when Locomotive::Mounter::Models::Page then handle
49
- when Liquid::Drops::Page then handle.instance_variable_get(:@_source)
50
- when String then fetch_page(mounting_point, handle)
51
- when Liquid::Drops::ContentEntry then fetch_page(mounting_point, handle.instance_variable_get(:@_source), true)
52
- when Locomotive::Mounter::Models::ContentEntry then fetch_page(mounting_point, handle, true)
53
- else
54
- nil
55
- end
56
-
57
- return page unless page.nil?
58
- end
59
-
60
- nil
61
- end
62
-
63
- def fetch_page(mounting_point, handle, templatized = false)
64
- ::Locomotive::Mounter.with_locale(@_options['locale']) do
65
- if templatized
66
- page = mounting_point.pages.values.find do |_page|
67
- _page.templatized? &&
68
- !_page.templatized_from_parent &&
69
- _page.content_type.slug == handle.content_type.slug &&
70
- (@_options['with'].nil? || _page.handle == @_options['with'])
71
- end
72
-
73
- page.content_entry = handle if page
74
-
75
- page
76
- else
77
- mounting_point.pages.values.find { |_page| _page.handle == handle }
78
- end
79
- end
80
- end
81
-
82
40
  def label_from_page(page)
83
41
  ::Locomotive::Mounter.with_locale(@_options['locale']) do
84
42
  if page.templatized?
@@ -89,32 +47,6 @@ module Locomotive
89
47
  end
90
48
  end
91
49
 
92
- def public_page_url(context, page)
93
- mounting_point = context.registers[:mounting_point]
94
- locale = @_options['locale'] || ::I18n.locale
95
-
96
- if !page.translated_in?(locale)
97
- title = page.title_translations.values.compact.first
98
- raise Liquid::PageNotTranslated.new(%{the "#{title}" page is not translated in #{locale.upcase}})
99
- end
100
-
101
- fullpath = ::Locomotive::Mounter.with_locale(locale) do
102
- page.fullpath.clone
103
- end
104
-
105
- fullpath = "#{::I18n.locale}/#{fullpath}" if ::I18n.locale.to_s != mounting_point.default_locale.to_s
106
-
107
- if page.templatized?
108
- if page.content_entry._slug.nil?
109
- title = %{#{page.content_entry.content_type.name.singularize} "#{page.content_entry.send(page.content_entry.content_type.label_field_name)}"}
110
- raise Liquid::ContentEntryNotTranslated.new(%{the #{title} slug is not translated in #{locale.upcase}})
111
- end
112
- fullpath.gsub!(/(content[_-]type[_-]template|template)/, page.content_entry._slug)
113
- end
114
-
115
- File.join('/', fullpath)
116
- end
117
-
118
50
  end
119
51
 
120
52
  ::Liquid::Template.register_tag('link_to', LinkTo)
@@ -78,7 +78,7 @@ module Locomotive
78
78
  when 'page' then self.current_page
79
79
  else
80
80
  self.mounting_point.pages[@source]
81
- end).children.clone
81
+ end).children.try(:clone) || []
82
82
 
83
83
  children.delete_if { |p| !include_page?(p) }
84
84
  end
@@ -0,0 +1,98 @@
1
+ module Locomotive
2
+ module Wagon
3
+ module Liquid
4
+ module Tags
5
+
6
+ module PathHelper
7
+
8
+ def render_path(context, &block)
9
+ site = context.registers[:site]
10
+
11
+ if page = self.retrieve_page_from_handle(context)
12
+ path = self.public_page_fullpath(context, page)
13
+
14
+ if block_given?
15
+ block.call page, path
16
+ else
17
+ path
18
+ end
19
+ else
20
+ raise Liquid::PageNotTranslated.new(%{[link_to] Unable to find a page for the #{@handle}. Wrong handle or missing template for your content.})
21
+ end
22
+ end
23
+
24
+ protected
25
+
26
+ def retrieve_page_from_handle(context)
27
+ mounting_point = context.registers[:mounting_point]
28
+
29
+ context.scopes.reverse_each do |scope|
30
+ handle = scope[@handle] || @handle
31
+
32
+ page = case handle
33
+ when Locomotive::Mounter::Models::Page then handle
34
+ when Liquid::Drops::Page then handle.instance_variable_get(:@_source)
35
+ when String then fetch_page(mounting_point, handle)
36
+ when Liquid::Drops::ContentEntry then fetch_page(mounting_point, handle.instance_variable_get(:@_source), true)
37
+ when Locomotive::Mounter::Models::ContentEntry then fetch_page(mounting_point, handle, true)
38
+ else
39
+ nil
40
+ end
41
+
42
+ return page unless page.nil?
43
+ end
44
+
45
+ nil
46
+ end
47
+
48
+ def fetch_page(mounting_point, handle, templatized = false)
49
+ ::Locomotive::Mounter.with_locale(@_options['locale']) do
50
+ if templatized
51
+ page = mounting_point.pages.values.find do |_page|
52
+ _page.templatized? &&
53
+ !_page.templatized_from_parent &&
54
+ _page.content_type.slug == handle.content_type.slug &&
55
+ (@_options['with'].nil? || _page.handle == @_options['with'])
56
+ end
57
+
58
+ page.content_entry = handle if page
59
+
60
+ page
61
+ else
62
+ mounting_point.pages.values.find { |_page| _page.handle == handle }
63
+ end
64
+ end
65
+ end
66
+
67
+ def public_page_fullpath(context, page)
68
+ mounting_point = context.registers[:mounting_point]
69
+ locale = @_options['locale'] || ::I18n.locale
70
+
71
+ if !page.translated_in?(locale)
72
+ title = page.title_translations.values.compact.first
73
+ raise Liquid::PageNotTranslated.new(%{the "#{title}" page is not translated in #{locale.upcase}})
74
+ end
75
+
76
+ fullpath = ::Locomotive::Mounter.with_locale(locale) do
77
+ page.fullpath.clone
78
+ end
79
+
80
+ fullpath = "#{::I18n.locale}/#{fullpath}" if ::I18n.locale.to_s != mounting_point.default_locale.to_s
81
+
82
+ if page.templatized?
83
+ if page.content_entry._slug.nil?
84
+ title = %{#{page.content_entry.content_type.name.singularize} "#{page.content_entry.send(page.content_entry.content_type.label_field_name)}"}
85
+ raise Liquid::ContentEntryNotTranslated.new(%{the #{title} slug is not translated in #{locale.upcase}})
86
+ end
87
+ fullpath.gsub!(/(content[_-]type[_-]template|template)/, page.content_entry._slug)
88
+ end
89
+
90
+ File.join('/', fullpath)
91
+ end
92
+
93
+ end
94
+ end
95
+
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,36 @@
1
+ module Locomotive
2
+ module Wagon
3
+ module Liquid
4
+ module Tags
5
+
6
+ class PathTo < ::Liquid::Tag
7
+
8
+ include PathHelper
9
+
10
+ Syntax = /(#{::Liquid::Expression}+)(#{::Liquid::TagAttributes}?)/
11
+
12
+ def initialize(tag_name, markup, tokens, context)
13
+ if markup =~ Syntax
14
+ @handle = $1
15
+ @_options = {}
16
+ markup.scan(::Liquid::TagAttributes) do |key, value|
17
+ @_options[key] = value
18
+ end
19
+ else
20
+ raise SyntaxError.new("Syntax Error in 'path_to' - Valid syntax: path_to <page|page_handle|content_entry>(, locale: [fr|de|...], with: <page_handle>")
21
+ end
22
+
23
+ super
24
+ end
25
+
26
+ def render(context)
27
+ render_path(context)
28
+ end
29
+
30
+ end
31
+
32
+ ::Liquid::Template.register_tag('path_to', PathTo)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -3,6 +3,7 @@ require 'locomotive/mounter'
3
3
  require 'locomotive/wagon/liquid/scopeable'
4
4
  require 'locomotive/wagon/liquid/drops/base'
5
5
  require 'locomotive/wagon/liquid/tags/hybrid'
6
+ require 'locomotive/wagon/liquid/tags/path_helper'
6
7
 
7
8
  %w{. drops tags filters}.each do |dir|
8
9
  Dir[File.join(File.dirname(__FILE__), 'liquid', dir, '*.rb')].each { |lib| require lib }
@@ -32,7 +32,7 @@ module Locomotive::Wagon
32
32
  raise RendererException.new(e, self.page.title, self.page.template, context)
33
33
  end
34
34
  end
35
-
35
+
36
36
  def render_404
37
37
  if self.page = self.mounting_point.pages['404']
38
38
  self.render_page
@@ -92,7 +92,8 @@ module Locomotive::Wagon
92
92
  'locales' => self.mounting_point.locales.map(&:to_s),
93
93
  'current_user' => {},
94
94
  'session' => Locomotive::Wagon::Liquid::Drops::SessionProxy.new,
95
- 'wagon' => true
95
+ 'wagon' => true,
96
+ 'editing' => false
96
97
  }
97
98
  end
98
99
 
@@ -1,5 +1,5 @@
1
1
  module Locomotive
2
2
  module Wagon
3
- VERSION = '1.3.2'
3
+ VERSION = '1.3.3'
4
4
  end
5
5
  end
@@ -34,7 +34,7 @@ Gem::Specification.new do |gem|
34
34
 
35
35
  gem.add_dependency 'httmultiparty', '0.3.10'
36
36
  gem.add_dependency 'will_paginate', '~> 3.0.3'
37
- gem.add_dependency 'locomotivecms_mounter', '~> 1.3.2'
37
+ gem.add_dependency 'locomotivecms_mounter', '~> 1.3.3'
38
38
 
39
39
  gem.add_dependency 'faker', '~> 0.9.5'
40
40
 
@@ -34,6 +34,8 @@ position: 2
34
34
  {% endwith_scope %}
35
35
  {% for s in selected_songs %}
36
36
  %p.scoped_song {{ s._label }}
37
+ %p.scoped_song_link
38
+ %a{ href: "{% path_to s %}" } {{ s._label }}
37
39
  {% endfor %}
38
40
  %p.collection_equality {{ contents.songs.all.size }}={{ contents.songs.size }}
39
41
 
@@ -71,15 +71,16 @@ describe Locomotive::Wagon::Server do
71
71
  it "evaluates collection when called all inside of scope" do
72
72
  get '/music'
73
73
  last_response.body.should =~ /<p class=.scoped_song.>Song #3/
74
+ last_response.body.should =~ /<p class=.scoped_song_link.>\s+<a href=.\/songs\/song-3.>Song #3/m
74
75
  end
75
76
 
76
- it "size of evaluated unscoped collection eqaul to unevaluated one" do
77
+ it "size of evaluated unscoped collection equal to unevaluated one" do
77
78
  get '/music'
78
79
  last_response.body.should =~ /class=.collection_equality.>8=8/
79
80
  end
80
81
 
81
82
  end
82
-
83
+
83
84
  describe 'html helpers' do
84
85
  it 'bypass url for css resource' do
85
86
  get '/'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotivecms_wagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-11 00:00:00.000000000 Z
12
+ date: 2013-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -213,14 +213,14 @@ dependencies:
213
213
  requirements:
214
214
  - - ~>
215
215
  - !ruby/object:Gem::Version
216
- version: 1.3.2
216
+ version: 1.3.3
217
217
  type: :runtime
218
218
  prerelease: false
219
219
  version_requirements: !ruby/object:Gem::Requirement
220
220
  requirements:
221
221
  - - ~>
222
222
  - !ruby/object:Gem::Version
223
- version: 1.3.2
223
+ version: 1.3.3
224
224
  - !ruby/object:Gem::Dependency
225
225
  name: faker
226
226
  requirement: !ruby/object:Gem::Requirement
@@ -516,6 +516,8 @@ files:
516
516
  - lib/locomotive/wagon/liquid/tags/locale_switcher.rb
517
517
  - lib/locomotive/wagon/liquid/tags/nav.rb
518
518
  - lib/locomotive/wagon/liquid/tags/paginate.rb
519
+ - lib/locomotive/wagon/liquid/tags/path_helper.rb
520
+ - lib/locomotive/wagon/liquid/tags/path_to.rb
519
521
  - lib/locomotive/wagon/liquid/tags/seo.rb
520
522
  - lib/locomotive/wagon/liquid/tags/session_assign.rb
521
523
  - lib/locomotive/wagon/liquid/tags/snippet.rb