locomotivecms_wagon 1.5.0 → 1.5.1

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: 3eb1d85c3211cccddf3105489a759908fdd12832
4
- data.tar.gz: 62a514ee0e9d0a749feb6dc18a09e696cd1b2e0d
3
+ metadata.gz: 74651ede61e4a001e1a1aabffd7fc88115a80348
4
+ data.tar.gz: b081bf5ca8a03d1fabcd5975419eaf1535ac4312
5
5
  SHA512:
6
- metadata.gz: 3f0f662eaa63ae25c3ab9b52bd7f732e7352ca956827b4e2b5471575fe542398e823c6b6b321157163c20b2147cb913d2887bc017469d68811962730d68e9d52
7
- data.tar.gz: 3d16d23bec319002eb7a0f185044364eb3dcd69b8bfd99612d04f9afca762f7c90fd7fb5a9e3e7730b0557dc674139963dc8cd898335d939be51836da3eb82e6
6
+ metadata.gz: 211391f7500d225cf946181e9685ecd04d4a9174e0631bf2b65c27f2b30917e32976facda2661d68b79f10cd2e1dcc0e3733496cbdb337e0848893e434538f7d
7
+ data.tar.gz: 83bdfb0190f7a255a9e7203196220a17a96b4320e4b1771363cd656c3a5d7363c7a8461f851570b70782d982a1c64b8a3ce0be247ecbdeff9779cc8f21e35cef
data/Gemfile CHANGED
@@ -14,4 +14,4 @@ gem 'rb-fsevent', '~> 0.9.1'
14
14
  group :test do
15
15
  gem 'pry'
16
16
  gem 'coveralls', require: false
17
- end
17
+ end
@@ -1,3 +1,7 @@
1
+ ---
2
+ title: Home page
3
+ published: true
4
+ ---
1
5
  !!!
2
6
  %html{lang: "en"}
3
7
  %head
@@ -1,15 +1,15 @@
1
- development:
2
- host: dev.example.com
3
- email: john@doe.net
4
- password: apassword
5
- # api_key: <your api key here>
6
- staging:
7
- host: staging.example.com
8
- email: john@doe.net
9
- password: apassword
10
- # api_key: <your api key here>
11
- production:
12
- host: www.example.com
13
- email: john@doe.net
14
- password: apassword
15
- # api_key: <your api key here>
1
+ # development:
2
+ # host: dev.example.com
3
+ # email: john@doe.net
4
+ # password: apassword
5
+ # # api_key: <your api key here>
6
+ # staging:
7
+ # host: staging.example.com
8
+ # email: john@doe.net
9
+ # password: apassword
10
+ # # api_key: <your api key here>
11
+ # production:
12
+ # host: www.example.com
13
+ # email: john@doe.net
14
+ # password: apassword
15
+ # # api_key: <your api key here>
@@ -32,7 +32,7 @@ fields: <% config[:fields].each_with_index do |field, index| %>
32
32
  type: <%= field.type %>
33
33
  required: <%= index == 0 ? true : field.required %>
34
34
  hint: Explanatory text displayed in the back office
35
- localized: <%= field.required %><% if field.type == 'text' %>
35
+ localized: <%= field.localized %><% if field.type == 'text' %>
36
36
  # text_formatting: html # html (uses rich text editor) or text (uses plain text editor)<% end -%><% if field.type == 'select' -%>
37
37
  # if localized, use
38
38
  # en: ['option1_en', 'option2_en']
@@ -11,6 +11,9 @@ listed: <% if config[:listed] -%><%= config[:listed] %><% else -%>true<% end %>
11
11
  # true if the page is published
12
12
  published: true
13
13
 
14
+ # true if the page can be used as a layout for new pages created by the editors
15
+ # is_layout: true
16
+
14
17
  # position among sibling pages
15
18
  # position: 1
16
19
 
@@ -34,4 +37,4 @@ content_type: <%= config[:content_type] -%>
34
37
 
35
38
  %p Hello world
36
39
 
37
- {% endblock %}
40
+ {% endblock %}
@@ -12,6 +12,9 @@ listed: <% if config[:listed] -%><%= config[:listed] %><% else -%>true<% end -%>
12
12
  # true if the page is published
13
13
  published: true
14
14
 
15
+ # true if the page can be used as a layout for new pages created by the editors
16
+ # is_layout: true
17
+
15
18
  # position among sibling pages
16
19
  # position: 1
17
20
 
@@ -43,7 +43,7 @@ module Locomotive
43
43
  label: label || name.humanize,
44
44
  type: type || 'string',
45
45
  required: %w(true required).include?(required),
46
- localized: %w(true required).include?(localized)
46
+ localized: %w(true localized).include?(localized)
47
47
  ).tap do |field|
48
48
  if %w(belongs_to has_many many_to_many).include?(type)
49
49
  field.class_name = target_content_type_slug
@@ -15,6 +15,7 @@ module Locomotive
15
15
  end
16
16
 
17
17
  alias :_slug :_permalink
18
+ alias :_id :_permalink
18
19
 
19
20
  def next
20
21
  self
@@ -88,7 +88,7 @@ module Locomotive
88
88
  end
89
89
 
90
90
  def paginate(options = {})
91
- @collection ||= self.collection.paginate(options)
91
+ @collection = self.collection.paginate(options)
92
92
  {
93
93
  collection: @collection,
94
94
  current_page: @collection.current_page,
@@ -101,7 +101,7 @@ module Locomotive
101
101
  end
102
102
 
103
103
  def collection
104
- return unless @collection.blank?
104
+ return @collection unless @collection.blank?
105
105
 
106
106
  # define the default order_by if not set
107
107
  if @context['with_scope'] && @context['with_scope']['order_by'].blank? && !%w(manually position).include?(@content_type.order_by)
@@ -4,15 +4,29 @@ module Locomotive
4
4
  module Drops
5
5
  class Page < Base
6
6
 
7
- delegate :slug, :fullpath, :parent, :depth, :seo_title, :redirect_url, :meta_description, :meta_keywords,
7
+ delegate :fullpath, :parent, :depth, :seo_title, :redirect_url, :meta_description, :meta_keywords,
8
8
  :templatized?, :published?, :redirect?, :listed?, :handle, to: :@_source
9
9
 
10
10
  def title
11
- if @_source.templatized?
12
- @context['entry'].try(:_label) || @_source.title
13
- else
14
- @_source.title
15
- end
11
+ title = @_source.templatized? ? @context['entry'].try(:_label) : nil
12
+ title || @_source.title
13
+ end
14
+
15
+ def slug
16
+ slug = @_source.templatized? ? @context['entry'].try(:_slug).try(:singularize) : nil
17
+ slug || @_source.slug
18
+ end
19
+
20
+ def is_layout?
21
+ @_source.is_layout
22
+ end
23
+
24
+ def original_title
25
+ @_source.title
26
+ end
27
+
28
+ def original_slug
29
+ @_source.slug
16
30
  end
17
31
 
18
32
  def children
@@ -25,12 +39,46 @@ module Locomotive
25
39
  ProxyCollection.new(@_source.content_type) if @_source.content_type
26
40
  end
27
41
 
42
+ def editable_elements
43
+ @editable_elements_hash ||= build_editable_elements_hash
44
+ end
45
+
28
46
  def breadcrumbs
29
47
  # TODO
30
48
  ''
31
49
  end
50
+
51
+ private
52
+
53
+ def build_editable_elements_hash
54
+ {}.tap do |hash|
55
+ @_source.editable_elements.each do |el|
56
+ safe_slug = el.slug.parameterize.underscore
57
+ keys = el.block.try(:split, '/').try(:compact) || []
58
+
59
+ _hash = _build_editable_elements_hashes(hash, keys)
60
+
61
+ _hash[safe_slug] = el.content
62
+ end
63
+ end
64
+ end
65
+
66
+ def _build_editable_elements_hashes(hash, keys)
67
+ _hash = hash
68
+
69
+ keys.each do |key|
70
+ safe_key = key.parameterize.underscore
71
+
72
+ _hash[safe_key] = {} if _hash[safe_key].nil?
73
+
74
+ _hash = _hash[safe_key]
75
+ end
76
+
77
+ _hash
78
+ end
79
+
32
80
  end
33
81
  end
34
82
  end
35
83
  end
36
- end
84
+ end
@@ -23,4 +23,4 @@ module Locomotive
23
23
  end
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -56,6 +56,8 @@ module Locomotive
56
56
  def initialize(name, value)
57
57
  self.name, self.right_operand = name, value
58
58
 
59
+ self.name = :_slug if %w(id _id).include?(name.to_s)
60
+
59
61
  self.process_right_operand
60
62
 
61
63
  # default value
@@ -14,14 +14,14 @@ module Locomotive
14
14
  #
15
15
  class Consume < ::Liquid::Block
16
16
 
17
- Syntax = /(#{::Liquid::VariableSignature}+)\s*from\s*(#{::Liquid::QuotedString}|#{::Liquid::VariableSignature}+)/
17
+ Syntax = /(#{::Liquid::VariableSignature}+)\s*from\s*(#{::Liquid::QuotedString}|#{::Liquid::VariableSignature}+)(.*)?/
18
18
 
19
19
  def initialize(tag_name, markup, tokens, options)
20
20
  if markup =~ Syntax
21
21
  @target = $1
22
22
 
23
23
  self.prepare_url($2)
24
- self.prepare_options(markup)
24
+ self.prepare_api_arguments($3)
25
25
  else
26
26
  raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.consume"), options[:line])
27
27
  end
@@ -32,6 +32,8 @@ module Locomotive
32
32
  end
33
33
 
34
34
  def render(context)
35
+ self.set_api_options(context)
36
+
35
37
  if instance_variable_defined? :@variable_name
36
38
  @url = context[@variable_name]
37
39
  end
@@ -50,13 +52,14 @@ module Locomotive
50
52
  end
51
53
  end
52
54
 
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
55
+ def prepare_api_arguments(string)
56
+ string = string.gsub(/^(\s*,)/, '').strip
57
+ @api_arguments = Solid::Arguments.parse(string)
58
+ end
59
+
60
+ def set_api_options(context)
61
+ @api_options = @api_arguments.interpolate(context).first || {}
62
+ @expires_in = @api_options.delete(:expires_in) || 0
60
63
  end
61
64
 
62
65
  def cached_response
@@ -72,7 +75,7 @@ module Locomotive
72
75
  def render_all_without_cache(context)
73
76
  context.stack do
74
77
  begin
75
- context.scopes.last[@target.to_s] = Locomotive::Wagon::Httparty::Webservice.consume(@url, @options.symbolize_keys)
78
+ context.scopes.last[@target.to_s] = Locomotive::Wagon::Httparty::Webservice.consume(@url, @api_options)
76
79
  self.cached_response = context.scopes.last[@target.to_s]
77
80
  rescue Timeout::Error
78
81
  context.scopes.last[@target.to_s] = self.cached_response
@@ -50,7 +50,6 @@ module Locomotive
50
50
  if templatized
51
51
  page = mounting_point.pages.values.find do |_page|
52
52
  _page.templatized? &&
53
- !_page.templatized_from_parent &&
54
53
  _page.content_type.slug == handle.content_type.slug &&
55
54
  (@_options['with'].nil? || _page.handle == @_options['with'])
56
55
  end
@@ -94,13 +94,15 @@ module Locomotive
94
94
  end
95
95
 
96
96
  def errors
97
- return nil if success? || (self['errors'].nil? && self['error'].nil?)
97
+ return nil if success?
98
98
 
99
99
  @errors ||= if self['error']
100
100
  [[nil, [self['error']]]]
101
+ elsif self['errors']
102
+ self['errors']
101
103
  else
102
- self['errors'].delete_if { |attribute, errors| errors.empty? }
103
- end
104
+ self.to_a
105
+ end.delete_if { |attribute, errors| errors.empty? }
104
106
  end
105
107
 
106
108
  def error_messages
@@ -112,4 +114,4 @@ module Locomotive
112
114
  end
113
115
 
114
116
  end
115
- end
117
+ end
@@ -115,4 +115,4 @@ module Locomotive::Wagon
115
115
  end
116
116
 
117
117
  end
118
- end
118
+ end
@@ -1,5 +1,5 @@
1
1
  module Locomotive
2
2
  module Wagon
3
- VERSION = '1.5.0'
3
+ VERSION = '1.5.1'
4
4
  end
5
5
  end
@@ -103,6 +103,7 @@ module Locomotive
103
103
  if Process.pid != parent_pid
104
104
  # A "new logger" inside the daemon.
105
105
  Locomotive::Wagon::Logger.setup(path, false)
106
+ Locomotive::Mounter.logger = Locomotive::Wagon::Logger.instance.logger
106
107
  end
107
108
  end
108
109
 
@@ -294,4 +295,4 @@ module Locomotive
294
295
  end
295
296
 
296
297
  end
297
- end
298
+ end
@@ -35,7 +35,7 @@ Gem::Specification.new do |gem|
35
35
 
36
36
  gem.add_dependency 'httmultiparty', '0.3.10'
37
37
  gem.add_dependency 'will_paginate', '~> 3.0.3'
38
- gem.add_dependency 'locomotivecms_mounter', '~> 1.4.4'
38
+ gem.add_dependency 'locomotivecms_mounter', '~> 1.5.0'
39
39
 
40
40
  gem.add_dependency 'faker', '~> 0.9.5'
41
41
 
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: My simple layout
3
+ is_layout: true
4
+ ---
5
+ !!! XML
6
+ !!!
7
+ %html{ lang: "en" }
8
+ %head
9
+
10
+ %body
11
+ %h1 {% editable_short_text title %}[TODO]{% endeditable_short_text %}
12
+ .text
13
+ {% editable_text content, format: html, rows: 5 %}[TODO]{% editable_text %}
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'locomotive/wagon/liquid'
4
+
5
+ describe Locomotive::Wagon::Liquid::Drops::Page do
6
+
7
+ let(:attributes) { { title: "Hello world" } }
8
+ let(:source) { Locomotive::Mounter::Models::Page.new(attributes) }
9
+
10
+ subject { source.to_liquid }
11
+
12
+ describe 'the title' do
13
+
14
+ its(:title) { should eq "Hello world" }
15
+
16
+ end
17
+
18
+ describe 'with editable elements' do
19
+
20
+ let(:text_a) { Locomotive::Mounter::Models::EditableElement.new(block: 'sidebar/header', slug: 'ads', content: 'foo' ) }
21
+ let(:text_b) { Locomotive::Mounter::Models::EditableElement.new(block: 'sidebar/footer', slug: 'ads', content: 'foo ter' ) }
22
+ let(:text_c) { Locomotive::Mounter::Models::EditableElement.new(block: '', slug: 'simple_text', content: 'bar' ) }
23
+ let(:text_d) { Locomotive::Mounter::Models::EditableElement.new(block: 'My footer/wrapper/inner', slug: 'text', content: 'hello world' ) }
24
+ let(:attributes) { { editable_elements: [text_a, text_b, text_c, text_d] } }
25
+
26
+ its(:editable_elements) do
27
+ should eq({
28
+ 'sidebar' => {
29
+ 'header' => { 'ads' => 'foo' },
30
+ 'footer' => { 'ads' => 'foo ter' }
31
+ },
32
+ 'simple_text' => 'bar',
33
+ 'my_footer' => {
34
+ 'wrapper' => { 'inner' => { 'text' => 'hello world' } }
35
+ }
36
+ })
37
+ end
38
+
39
+ end
40
+
41
+ end
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.5.0
4
+ version: 1.5.1
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: 2014-10-14 00:00:00.000000000 Z
12
+ date: 2014-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -227,14 +227,14 @@ dependencies:
227
227
  requirements:
228
228
  - - "~>"
229
229
  - !ruby/object:Gem::Version
230
- version: 1.4.4
230
+ version: 1.5.0
231
231
  type: :runtime
232
232
  prerelease: false
233
233
  version_requirements: !ruby/object:Gem::Requirement
234
234
  requirements:
235
235
  - - "~>"
236
236
  - !ruby/object:Gem::Version
237
- version: 1.4.4
237
+ version: 1.5.0
238
238
  - !ruby/object:Gem::Dependency
239
239
  name: faker
240
240
  requirement: !ruby/object:Gem::Requirement
@@ -775,6 +775,7 @@ files:
775
775
  - spec/fixtures/default/app/views/pages/grunge_bands.liquid.haml
776
776
  - spec/fixtures/default/app/views/pages/index.fr.liquid.haml
777
777
  - spec/fixtures/default/app/views/pages/index.liquid.haml
778
+ - spec/fixtures/default/app/views/pages/layouts/simple.liquid.haml
778
779
  - spec/fixtures/default/app/views/pages/music.fr.liquid.haml
779
780
  - spec/fixtures/default/app/views/pages/music.liquid.haml
780
781
  - spec/fixtures/default/app/views/pages/songs/template.fr.liquid.haml
@@ -831,6 +832,7 @@ files:
831
832
  - spec/spec_helper.rb
832
833
  - spec/support/helpers.rb
833
834
  - spec/support/matchers.rb
835
+ - spec/unit/locomotive/wagon/liquid/drops/page_spec.rb
834
836
  homepage: http://www.locomotivecms.com
835
837
  licenses: []
836
838
  metadata: {}
@@ -879,6 +881,7 @@ test_files:
879
881
  - spec/fixtures/default/app/views/pages/grunge_bands.liquid.haml
880
882
  - spec/fixtures/default/app/views/pages/index.fr.liquid.haml
881
883
  - spec/fixtures/default/app/views/pages/index.liquid.haml
884
+ - spec/fixtures/default/app/views/pages/layouts/simple.liquid.haml
882
885
  - spec/fixtures/default/app/views/pages/music.fr.liquid.haml
883
886
  - spec/fixtures/default/app/views/pages/music.liquid.haml
884
887
  - spec/fixtures/default/app/views/pages/songs/template.fr.liquid.haml
@@ -935,3 +938,4 @@ test_files:
935
938
  - spec/spec_helper.rb
936
939
  - spec/support/helpers.rb
937
940
  - spec/support/matchers.rb
941
+ - spec/unit/locomotive/wagon/liquid/drops/page_spec.rb