locomotivecms_steam 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.md +19 -0
  5. data/Gemfile +8 -0
  6. data/Gemfile.lock +188 -0
  7. data/LICENSE +20 -0
  8. data/README.md +36 -0
  9. data/Rakefile +17 -0
  10. data/bin/publish +28 -0
  11. data/config/locales/de.yml +157 -0
  12. data/config/locales/en.yml +189 -0
  13. data/config/locales/es.yml +133 -0
  14. data/config/locales/et.yml +154 -0
  15. data/config/locales/fr.yml +148 -0
  16. data/config/locales/it.yml +155 -0
  17. data/config/locales/nb.yml +191 -0
  18. data/config/locales/nl.yml +160 -0
  19. data/config/locales/pl.yml +203 -0
  20. data/config/locales/pt-BR.yml +139 -0
  21. data/config/locales/ru.yml +224 -0
  22. data/lib/locomotive/steam/core_ext.rb +5 -0
  23. data/lib/locomotive/steam/core_ext/array.rb +3 -0
  24. data/lib/locomotive/steam/core_ext/boolean/false.rb +3 -0
  25. data/lib/locomotive/steam/core_ext/boolean/true.rb +3 -0
  26. data/lib/locomotive/steam/core_ext/hash.rb +27 -0
  27. data/lib/locomotive/steam/core_ext/string.rb +8 -0
  28. data/lib/locomotive/steam/exceptions.rb +62 -0
  29. data/lib/locomotive/steam/initializers.rb +5 -0
  30. data/lib/locomotive/steam/initializers/i18n.rb +3 -0
  31. data/lib/locomotive/steam/initializers/markdown.rb +27 -0
  32. data/lib/locomotive/steam/initializers/will_paginate.rb +16 -0
  33. data/lib/locomotive/steam/liquid.rb +22 -0
  34. data/lib/locomotive/steam/liquid/drops/base.rb +46 -0
  35. data/lib/locomotive/steam/liquid/drops/content_entry.rb +48 -0
  36. data/lib/locomotive/steam/liquid/drops/content_types.rb +117 -0
  37. data/lib/locomotive/steam/liquid/drops/page.rb +28 -0
  38. data/lib/locomotive/steam/liquid/drops/session_proxy.rb +18 -0
  39. data/lib/locomotive/steam/liquid/drops/site.rb +26 -0
  40. data/lib/locomotive/steam/liquid/errors.rb +17 -0
  41. data/lib/locomotive/steam/liquid/filters/date.rb +136 -0
  42. data/lib/locomotive/steam/liquid/filters/html.rb +188 -0
  43. data/lib/locomotive/steam/liquid/filters/misc.rb +49 -0
  44. data/lib/locomotive/steam/liquid/filters/resize.rb +18 -0
  45. data/lib/locomotive/steam/liquid/filters/text.rb +55 -0
  46. data/lib/locomotive/steam/liquid/filters/translate.rb +28 -0
  47. data/lib/locomotive/steam/liquid/patches.rb +47 -0
  48. data/lib/locomotive/steam/liquid/scopeable.rb +149 -0
  49. data/lib/locomotive/steam/liquid/tags/consume.rb +97 -0
  50. data/lib/locomotive/steam/liquid/tags/csrf.rb +34 -0
  51. data/lib/locomotive/steam/liquid/tags/editable.rb +6 -0
  52. data/lib/locomotive/steam/liquid/tags/editable/base.rb +50 -0
  53. data/lib/locomotive/steam/liquid/tags/editable/control.rb +19 -0
  54. data/lib/locomotive/steam/liquid/tags/editable/file.rb +15 -0
  55. data/lib/locomotive/steam/liquid/tags/editable/long_text.rb +15 -0
  56. data/lib/locomotive/steam/liquid/tags/editable/short_text.rb +20 -0
  57. data/lib/locomotive/steam/liquid/tags/editable/text.rb +15 -0
  58. data/lib/locomotive/steam/liquid/tags/extends.rb +25 -0
  59. data/lib/locomotive/steam/liquid/tags/google_analytics.rb +28 -0
  60. data/lib/locomotive/steam/liquid/tags/hybrid.rb +27 -0
  61. data/lib/locomotive/steam/liquid/tags/inline_editor.rb +16 -0
  62. data/lib/locomotive/steam/liquid/tags/link_to.rb +56 -0
  63. data/lib/locomotive/steam/liquid/tags/locale_switcher.rb +106 -0
  64. data/lib/locomotive/steam/liquid/tags/nav.rb +287 -0
  65. data/lib/locomotive/steam/liquid/tags/paginate.rb +105 -0
  66. data/lib/locomotive/steam/liquid/tags/path_helper.rb +98 -0
  67. data/lib/locomotive/steam/liquid/tags/path_to.rb +36 -0
  68. data/lib/locomotive/steam/liquid/tags/seo.rb +74 -0
  69. data/lib/locomotive/steam/liquid/tags/session_assign.rb +41 -0
  70. data/lib/locomotive/steam/liquid/tags/snippet.rb +63 -0
  71. data/lib/locomotive/steam/liquid/tags/with_scope.rb +44 -0
  72. data/lib/locomotive/steam/listen.rb +64 -0
  73. data/lib/locomotive/steam/logger.rb +54 -0
  74. data/lib/locomotive/steam/monkey_patches.rb +5 -0
  75. data/lib/locomotive/steam/monkey_patches/better_errors.rb +70 -0
  76. data/lib/locomotive/steam/monkey_patches/dragonfly.rb +79 -0
  77. data/lib/locomotive/steam/monkey_patches/haml.rb +15 -0
  78. data/lib/locomotive/steam/monkey_patches/httparty.rb +46 -0
  79. data/lib/locomotive/steam/monkey_patches/mounter.rb +32 -0
  80. data/lib/locomotive/steam/server.rb +81 -0
  81. data/lib/locomotive/steam/server/dynamic_assets.rb +33 -0
  82. data/lib/locomotive/steam/server/entry_submission.rb +120 -0
  83. data/lib/locomotive/steam/server/favicon.rb +18 -0
  84. data/lib/locomotive/steam/server/locale.rb +42 -0
  85. data/lib/locomotive/steam/server/logging.rb +32 -0
  86. data/lib/locomotive/steam/server/middleware.rb +61 -0
  87. data/lib/locomotive/steam/server/page.rb +69 -0
  88. data/lib/locomotive/steam/server/path.rb +34 -0
  89. data/lib/locomotive/steam/server/renderer.rb +118 -0
  90. data/lib/locomotive/steam/server/templatized_page.rb +32 -0
  91. data/lib/locomotive/steam/server/timezone.rb +18 -0
  92. data/lib/locomotive/steam/standalone_server.rb +33 -0
  93. data/lib/locomotive/steam/version.rb +5 -0
  94. data/lib/steam.rb +4 -0
  95. data/locomotivecms_steam.gemspec +42 -0
  96. data/spec/fixtures/default/README +0 -0
  97. data/spec/fixtures/default/app/content_types/bands.yml +19 -0
  98. data/spec/fixtures/default/app/content_types/events.yml +25 -0
  99. data/spec/fixtures/default/app/content_types/messages.yml +17 -0
  100. data/spec/fixtures/default/app/content_types/songs.yml +25 -0
  101. data/spec/fixtures/default/app/content_types/updates.yml +33 -0
  102. data/spec/fixtures/default/app/views/pages/404.liquid.haml +10 -0
  103. data/spec/fixtures/default/app/views/pages/about_us.fr.liquid.haml +7 -0
  104. data/spec/fixtures/default/app/views/pages/about_us.liquid.haml +21 -0
  105. data/spec/fixtures/default/app/views/pages/about_us.nb.liquid.haml +4 -0
  106. data/spec/fixtures/default/app/views/pages/about_us/jane_doe.liquid.haml +4 -0
  107. data/spec/fixtures/default/app/views/pages/about_us/john_doe.fr.liquid.haml +5 -0
  108. data/spec/fixtures/default/app/views/pages/about_us/john_doe.liquid.haml +6 -0
  109. data/spec/fixtures/default/app/views/pages/all.liquid.haml +13 -0
  110. data/spec/fixtures/default/app/views/pages/archives/news.liquid.haml +10 -0
  111. data/spec/fixtures/default/app/views/pages/contact.liquid.haml +54 -0
  112. data/spec/fixtures/default/app/views/pages/contest.liquid.haml +18 -0
  113. data/spec/fixtures/default/app/views/pages/events.liquid.haml +42 -0
  114. data/spec/fixtures/default/app/views/pages/filtered.liquid.haml +10 -0
  115. data/spec/fixtures/default/app/views/pages/grunge_bands.liquid.haml +8 -0
  116. data/spec/fixtures/default/app/views/pages/index.fr.liquid.haml +3 -0
  117. data/spec/fixtures/default/app/views/pages/index.liquid.haml +100 -0
  118. data/spec/fixtures/default/app/views/pages/music.fr.liquid.haml +4 -0
  119. data/spec/fixtures/default/app/views/pages/music.liquid.haml +42 -0
  120. data/spec/fixtures/default/app/views/pages/songs/template.fr.liquid.haml +16 -0
  121. data/spec/fixtures/default/app/views/pages/songs/template.liquid.haml +18 -0
  122. data/spec/fixtures/default/app/views/pages/songs/template/band.liquid.haml +16 -0
  123. data/spec/fixtures/default/app/views/pages/store.fr.liquid.haml +5 -0
  124. data/spec/fixtures/default/app/views/pages/store.liquid +5 -0
  125. data/spec/fixtures/default/app/views/pages/tags/nav.liquid.haml +6 -0
  126. data/spec/fixtures/default/app/views/pages/tags/nav_in_deep.liquid.haml +6 -0
  127. data/spec/fixtures/default/app/views/pages/unlisted_pages.liquid.haml +9 -0
  128. data/spec/fixtures/default/app/views/snippets/A_Complicated-one.liquid.haml +1 -0
  129. data/spec/fixtures/default/app/views/snippets/footer.liquid.haml +6 -0
  130. data/spec/fixtures/default/app/views/snippets/header.liquid.haml +1 -0
  131. data/spec/fixtures/default/app/views/snippets/song.fr.liquid.haml +8 -0
  132. data/spec/fixtures/default/app/views/snippets/song.liquid +12 -0
  133. data/spec/fixtures/default/config/deploy.yml +12 -0
  134. data/spec/fixtures/default/config/deploy_example.yml +12 -0
  135. data/spec/fixtures/default/config/site.yml +15 -0
  136. data/spec/fixtures/default/config/translations.yml +3 -0
  137. data/spec/fixtures/default/data/bands.yml +10 -0
  138. data/spec/fixtures/default/data/events.yml +53 -0
  139. data/spec/fixtures/default/data/songs.yml +46 -0
  140. data/spec/fixtures/default/data/updates.yml +48 -0
  141. data/spec/fixtures/default/public/fonts/chunkfive-webfont.eot +0 -0
  142. data/spec/fixtures/default/public/fonts/chunkfive-webfont.svg +213 -0
  143. data/spec/fixtures/default/public/fonts/chunkfive-webfont.ttf +0 -0
  144. data/spec/fixtures/default/public/fonts/chunkfive-webfont.woff +0 -0
  145. data/spec/fixtures/default/public/fonts/chunkfive.css +8 -0
  146. data/spec/fixtures/default/public/fonts/chunkfive.otf +0 -0
  147. data/spec/fixtures/default/public/images/nav_on.png +0 -0
  148. data/spec/fixtures/default/public/images/photo_frame.png +0 -0
  149. data/spec/fixtures/default/public/images/sep.png +0 -0
  150. data/spec/fixtures/default/public/images/top.jpg +0 -0
  151. data/spec/fixtures/default/public/javascripts/application.js.coffee +2 -0
  152. data/spec/fixtures/default/public/javascripts/common.js +1 -0
  153. data/spec/fixtures/default/public/samples/asset_collections/cover.jpg +0 -0
  154. data/spec/fixtures/default/public/samples/photo.jpg +0 -0
  155. data/spec/fixtures/default/public/samples/photo_2.jpg +0 -0
  156. data/spec/fixtures/default/public/stylesheets/application.css +64 -0
  157. data/spec/fixtures/default/public/stylesheets/other/extra.css.less +8 -0
  158. data/spec/fixtures/default/public/stylesheets/other/style.css.scss +13 -0
  159. data/spec/fixtures/default/public/stylesheets/reboot.css +82 -0
  160. data/spec/integration/integration_helper.rb +15 -0
  161. data/spec/integration/server/basic_spec.rb +170 -0
  162. data/spec/integration/server/contact_form_spec.rb +111 -0
  163. data/spec/integration/server/liquid_spec.rb +91 -0
  164. data/spec/integration/server/with_scope_spec.rb +20 -0
  165. data/spec/locales/locales_spec.rb +22 -0
  166. data/spec/spec_helper.rb +21 -0
  167. data/spec/support.rb +4 -0
  168. data/spec/support/examples/locale_file.rb +14 -0
  169. data/spec/support/examples/matching_locale.rb +8 -0
  170. data/spec/support/helpers.rb +22 -0
  171. data/spec/support/matchers/hash.rb +5 -0
  172. metadata +564 -0
@@ -0,0 +1,49 @@
1
+ module Locomotive
2
+ module Steam
3
+ module Liquid
4
+ module Filters
5
+ module Misc
6
+
7
+ # was called modulo at first
8
+ def str_modulo(word, index, modulo)
9
+ (index.to_i + 1) % modulo == 0 ? word : ''
10
+ end
11
+
12
+ # Get the nth element of the passed in array
13
+ def index(array, position)
14
+ array.at(position) if array.respond_to?(:at)
15
+ end
16
+
17
+ def default(input, value)
18
+ input.blank? ? value : input
19
+ end
20
+
21
+ def random(input)
22
+ rand(input.to_i)
23
+ end
24
+
25
+ # map/collect on a given property (support to_f, to_i)
26
+ def map(input, property)
27
+ flatten_if_necessary(input).map do |e|
28
+ e = e.call if e.is_a?(Proc)
29
+
30
+ if property == "to_liquid"
31
+ e
32
+ elsif property == "to_f"
33
+ e.to_f
34
+ elsif property == "to_i"
35
+ e.to_i
36
+ elsif e.respond_to?(:[])
37
+ e[property]
38
+ end
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ ::Liquid::Template.register_filter(Misc)
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,18 @@
1
+ module Locomotive
2
+ module Steam
3
+ module Liquid
4
+ module Filters
5
+ module Resize
6
+
7
+ def resize(input, resize_string)
8
+ Locomotive::Steam::Dragonfly.instance.resize_url(input, resize_string)
9
+ end
10
+
11
+ end
12
+
13
+ ::Liquid::Template.register_filter(Resize)
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,55 @@
1
+ module Locomotive
2
+ module Steam
3
+ module Liquid
4
+ module Filters
5
+ module Text
6
+
7
+ # right justify and padd a string
8
+ def rjust(input, integer, padstr = '')
9
+ input.to_s.rjust(integer, padstr)
10
+ end
11
+
12
+ # left justify and padd a string
13
+ def ljust(input, integer, padstr = '')
14
+ input.to_s.ljust(integer, padstr)
15
+ end
16
+
17
+ def underscore(input)
18
+ input.to_s.gsub(' ', '_').gsub('/', '_').underscore
19
+ end
20
+
21
+ def dasherize(input)
22
+ input.to_s.gsub(' ', '-').gsub('/', '-').dasherize
23
+ end
24
+
25
+ # alias newline_to_br
26
+ def multi_line(input)
27
+ input.to_s.gsub("\n", '<br/>')
28
+ end
29
+
30
+ def concat(input, *args)
31
+ result = input.to_s
32
+ args.flatten.each { |a| result << a.to_s }
33
+ result
34
+ end
35
+
36
+ def encode(input)
37
+ Rack::Utils.escape(input)
38
+ end
39
+
40
+ def textile(input)
41
+ ::RedCloth.new(input).to_html
42
+ end
43
+
44
+ def markdown(input)
45
+ Locomotive::Steam::Markdown.steam(input)
46
+ end
47
+
48
+ end
49
+
50
+ ::Liquid::Template.register_filter(Text)
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ module Locomotive
2
+ module Steam
3
+ module Liquid
4
+ module Filters
5
+ module Translate
6
+
7
+ def translate(key, locale = nil, scope = nil)
8
+ locale ||= I18n.locale.to_s
9
+ if scope.blank?
10
+ translation = @context.registers[:mounting_point].translations[key.to_s]
11
+
12
+ if translation
13
+ translation.get(locale) || translation.get(Locomotive::Mounter.locale.to_s)
14
+ else
15
+ "[unknown translation key: #{key}]"
16
+ end
17
+ else
18
+ I18n.t(key, scope: scope.split('.'), locale: locale)
19
+ end
20
+ end
21
+ end
22
+
23
+ ::Liquid::Template.register_filter(Translate)
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,47 @@
1
+ module Liquid
2
+
3
+ class Drop
4
+
5
+ def mounting_point
6
+ @context.registers[:mounting_point]
7
+ end
8
+
9
+ def site
10
+ @context.registers[:site]
11
+ end
12
+
13
+ end
14
+
15
+ class Template
16
+
17
+ # creates a new <tt>Template</tt> object from liquid source code
18
+ def parse_with_utf8(source, context = {})
19
+ if RUBY_VERSION =~ /1\.9/
20
+ source = source.force_encoding('UTF-8') if source.present?
21
+ end
22
+ self.parse_without_utf8(source, context)
23
+ end
24
+
25
+ alias_method_chain :parse, :utf8
26
+
27
+ end
28
+
29
+ module StandardFilters
30
+
31
+ private
32
+
33
+ def to_number(obj)
34
+ case obj
35
+ when Numeric
36
+ obj
37
+ when String
38
+ (obj.strip =~ /^\d+\.\d+$/) ? obj.to_f : obj.to_i
39
+ when DateTime, Date, Time
40
+ obj.to_time.to_i
41
+ else
42
+ 0
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,149 @@
1
+ module Locomotive
2
+ module Steam
3
+ module Liquid
4
+ module Scopeable
5
+
6
+ def apply_scope(entries)
7
+ if @context['with_scope'].blank?
8
+ entries
9
+ else
10
+ # extract the conditions
11
+ _conditions = @context['with_scope'].clone.delete_if { |k, _| %w(order_by per_page page).include?(k) }
12
+
13
+ # build the chains of conditions
14
+ conditions = _conditions.map { |name, value| Condition.new(name, value) }
15
+
16
+ Locomotive::Steam::Logger.info "[with_scope] conditions: #{conditions.map(&:to_s).join(', ')}"
17
+
18
+ # get only the entries matching ALL the conditions
19
+ _entries = entries.find_all do |content|
20
+ accepted = true
21
+
22
+ conditions.each do |_condition|
23
+ unless _condition.matches?(content)
24
+ accepted = false
25
+ break # no to go further
26
+ end
27
+ end
28
+
29
+ accepted
30
+ end
31
+
32
+ self._apply_scope_order(_entries, @context['with_scope']['order_by'])
33
+ end
34
+ end
35
+
36
+ def _apply_scope_order(entries, order_by)
37
+ return entries if order_by.blank?
38
+
39
+ name, direction = order_by.split.map(&:to_sym)
40
+
41
+ Locomotive::Steam::Logger.info "[with_scope] order_by #{name} #{direction || 'asc'}"
42
+
43
+ if direction == :asc || direction.nil?
44
+ entries.sort { |a, b| a.send(name) <=> b.send(name) }
45
+ else
46
+ entries.sort { |a, b| b.send(name) <=> a.send(name) }
47
+ end
48
+ end
49
+
50
+ class Condition
51
+
52
+ OPERATORS = %w(all gt gte in lt lte ne nin size)
53
+
54
+ attr_accessor :name, :operator, :right_operand
55
+
56
+ def initialize(name, value)
57
+ self.name, self.right_operand = name, value
58
+
59
+ self.process_right_operand
60
+
61
+ # default value
62
+ self.operator = :==
63
+
64
+ self.decode_operator_based_on_name
65
+ end
66
+
67
+ def matches?(entry)
68
+ value = self.get_value(entry)
69
+
70
+ self.decode_operator_based_on_value(value)
71
+
72
+ case self.operator
73
+ when :== then value == self.right_operand
74
+ when :ne then value != self.right_operand
75
+ when :matches then self.right_operand =~ value
76
+ when :gt then value > self.right_operand
77
+ when :gte then value >= self.right_operand
78
+ when :lt then value < self.right_operand
79
+ when :lte then value <= self.right_operand
80
+ when :size then value.size == self.right_operand
81
+ when :all then [*self.right_operand].contains?(value)
82
+ when :in, :nin
83
+ _matches = if value.is_a?(Array)
84
+ [*value].contains?([*self.right_operand])
85
+ else
86
+ [*self.right_operand].include?(value)
87
+ end
88
+ self.operator == :in ? _matches : !_matches
89
+ else
90
+ raise UnknownConditionInScope.new("#{self.operator} is unknown or not implemented.")
91
+ end
92
+ end
93
+
94
+ def to_s
95
+ "#{name} #{operator} #{self.right_operand.to_s}"
96
+ end
97
+
98
+ protected
99
+
100
+ def get_value(entry)
101
+ value = entry.send(self.name)
102
+
103
+ if value.respond_to?(:_slug)
104
+ # belongs_to
105
+ value._slug
106
+ elsif value.respond_to?(:map)
107
+ # many_to_many or tags ?
108
+ value.map { |v| v.respond_to?(:_slug) ? v._slug : v }
109
+ else
110
+ value
111
+ end
112
+ end
113
+
114
+ def process_right_operand
115
+ if self.right_operand.respond_to?(:_slug)
116
+ # belongs_to
117
+ self.right_operand = self.right_operand._slug
118
+ elsif self.right_operand.respond_to?(:map) && self.right_operand.first.respond_to?(:_slug)
119
+ # many_to_many
120
+ self.right_operand = self.right_operand.map do |entry|
121
+ entry.try(&:_slug)
122
+ end
123
+ end
124
+ end
125
+
126
+ def decode_operator_based_on_name
127
+ if name =~ /^([a-z0-9_-]+)\.(#{OPERATORS.join('|')})$/
128
+ self.name = $1.to_sym
129
+ self.operator = $2.to_sym
130
+ end
131
+
132
+ if self.right_operand.is_a?(Regexp)
133
+ self.operator = :matches
134
+ end
135
+ end
136
+
137
+ def decode_operator_based_on_value(value)
138
+ case value
139
+ when Array
140
+ self.operator = :in if self.operator == :==
141
+ end
142
+ end
143
+
144
+ end
145
+
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,97 @@
1
+ module Locomotive
2
+ module Steam
3
+ module Liquid
4
+ module Tags
5
+ # Consume web services as easy as pie directly in liquid !
6
+ #
7
+ # Usage:
8
+ #
9
+ # {% consume blog from 'http://nocoffee.tumblr.com/api/read.json?num=3', username: 'john', password: 'easy', format: 'json', expires_in: 3000 %}
10
+ # {% for post in blog.posts %}
11
+ # {{ post.title }}
12
+ # {% endfor %}
13
+ # {% endconsume %}
14
+ #
15
+ class Consume < ::Liquid::Block
16
+
17
+ Syntax = /(#{::Liquid::VariableSignature}+)\s*from\s*(#{::Liquid::QuotedString}|#{::Liquid::VariableSignature}+)/
18
+
19
+ def initialize(tag_name, markup, tokens, options)
20
+ if markup =~ Syntax
21
+ @target = $1
22
+
23
+ self.prepare_url($2)
24
+ self.prepare_options(markup)
25
+ else
26
+ raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.consume"), options[:line])
27
+ end
28
+
29
+ @local_cache_key = self.hash
30
+
31
+ super
32
+ end
33
+
34
+ def render(context)
35
+ if instance_variable_defined? :@variable_name
36
+ @url = context[@variable_name]
37
+ end
38
+ render_all_without_cache(context)
39
+ end
40
+
41
+ protected
42
+
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
48
+ else
49
+ raise ::Liquid::SyntaxError.new("Syntax Error in 'consume' - Valid syntax: consume <var> from \"<url>\" [username: value, password: value]")
50
+ end
51
+ end
52
+
53
+ def prepare_options(markup)
54
+ @options = {}
55
+ markup.scan(::Liquid::TagAttributes) do |key, value|
56
+ @options[key] = value if key != 'http'
57
+ end
58
+ @options['timeout'] = @options['timeout'].to_f if @options['timeout']
59
+ @expires_in = (@options.delete('expires_in') || 0).to_i
60
+ end
61
+
62
+ def cached_response
63
+ @@local_cache ||= {}
64
+ @@local_cache[@local_cache_key]
65
+ end
66
+
67
+ def cached_response=(response)
68
+ @@local_cache ||= {}
69
+ @@local_cache[@local_cache_key] = response
70
+ end
71
+
72
+ def render_all_without_cache(context)
73
+ context.stack do
74
+ begin
75
+ context.scopes.last[@target.to_s] = Locomotive::Steam::Httparty::Webservice.consume(@url, @options.symbolize_keys)
76
+ self.cached_response = context.scopes.last[@target.to_s]
77
+ rescue Timeout::Error
78
+ context.scopes.last[@target.to_s] = self.cached_response
79
+ rescue ::Liquid::Error => e
80
+ raise e
81
+ rescue => e
82
+ liquid_e = ::Liquid::Error.new(e.message, line)
83
+ liquid_e.set_backtrace(e.backtrace)
84
+ raise liquid_e
85
+ end
86
+
87
+ render_all(@nodelist, context)
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ ::Liquid::Template.register_tag('consume', Consume)
94
+ end
95
+ end
96
+ end
97
+ end