locomotivecms_steam 1.0.0.pre.alpha.1 → 1.0.0.pre.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +10 -10
  3. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/site.rb +2 -0
  4. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/translation.rb +4 -38
  5. data/lib/locomotive/steam/adapters/memory/query.rb +1 -1
  6. data/lib/locomotive/steam/adapters/mongodb/query.rb +19 -1
  7. data/lib/locomotive/steam/adapters/mongodb.rb +1 -1
  8. data/lib/locomotive/steam/decorators/template_decorator.rb +10 -2
  9. data/lib/locomotive/steam/entities/content_entry.rb +1 -0
  10. data/lib/locomotive/steam/entities/editable_element.rb +6 -1
  11. data/lib/locomotive/steam/entities/page.rb +4 -0
  12. data/lib/locomotive/steam/errors.rb +32 -0
  13. data/lib/locomotive/steam/liquid/drops/site.rb +2 -1
  14. data/lib/locomotive/steam/liquid/tags/editable/file.rb +2 -1
  15. data/lib/locomotive/steam/liquid/tags/extends.rb +1 -1
  16. data/lib/locomotive/steam/liquid/tags/model_form.rb +1 -1
  17. data/lib/locomotive/steam/liquid/tags/paginate.rb +1 -1
  18. data/lib/locomotive/steam/liquid/tags/seo.rb +2 -2
  19. data/lib/locomotive/steam/models/i18n_field.rb +4 -4
  20. data/lib/locomotive/steam/models/repository.rb +4 -0
  21. data/lib/locomotive/steam/repositories/content_entry_repository.rb +5 -2
  22. data/lib/locomotive/steam/services/editable_element_service.rb +1 -1
  23. data/lib/locomotive/steam/services/entry_submission_service.rb +1 -1
  24. data/lib/locomotive/steam/services/parent_finder_service.rb +4 -6
  25. data/lib/locomotive/steam/version.rb +1 -1
  26. data/lib/locomotive/steam.rb +1 -0
  27. data/locomotivecms_steam.gemspec +3 -3
  28. data/spec/fixtures/default/app/views/pages/tags/nav.liquid.haml +2 -2
  29. data/spec/integration/repositories/page_repository_spec.rb +12 -1
  30. data/spec/integration/server/sitemap_spec.rb +1 -1
  31. data/spec/unit/decorators/template_decorator_spec.rb +42 -0
  32. data/spec/unit/errors_spec.rb +28 -0
  33. data/spec/unit/liquid/tags/editable/file_spec.rb +3 -3
  34. data/spec/unit/liquid/tags/seo_spec.rb +4 -4
  35. data/spec/unit/models/i18n_field_spec.rb +25 -0
  36. metadata +15 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4defa074871fdae0481e4f65d6e33dfea1fede03
4
- data.tar.gz: 3beda891d09f56d5883e284d958f42288be36c40
3
+ metadata.gz: d356e35a4a40eb38ba622e0f11c80c6c4f96f60c
4
+ data.tar.gz: 271c77fcbd49d0f728b696b42c5cb53893710876
5
5
  SHA512:
6
- metadata.gz: 91b5751d14bdf87d35ab308399a222983bc91edbfe5cd9f7cca1c8a0036a12327930d3fe5196494ed4160ff6159db430df6ec7a4beb7a02374e81954472c1341
7
- data.tar.gz: c7b56474a51cd689f9c0229d89c0630b376a699aa253909bdcaf1cdb8fc4dc70bc18f9986e20e32b84fd1d6f417fa460e7a97098812317d19f4ad82b0bc2b00f
6
+ metadata.gz: 9f2b709d5db8a35b9d2f3d17cbf05ed9f47a40190b73336b50c8e7bcbdda1fa83107149618e391db6374efbe8a6e6ed884ebdc6e3163ca988edc11ae887ca92d
7
+ data.tar.gz: 7665c557df441bcda5e23321d02945712585a1f75b989ade5fd41a414ab3d9733a84e9f6adba2e008714114083c6513ba9296ebfbeff0350ca22d7cf82b077da
data/Gemfile.lock CHANGED
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_steam (1.0.0.pre.alpha.1)
4
+ locomotivecms_steam (1.0.0.pre.alpha.2)
5
5
  RedCloth (~> 4.2.9)
6
6
  chronic (~> 0.10.2)
7
7
  coffee-script (~> 2.4.1)
8
8
  compass (~> 1.0.3)
9
- dragonfly (~> 1.0.9)
9
+ dragonfly (~> 1.0.10)
10
10
  haml (~> 4.0.6)
11
- httparty (~> 0.13.3)
11
+ httparty (~> 0.13.5)
12
12
  kramdown (~> 1.7.0)
13
13
  locomotivecms-solid (~> 4.0.0.alpha2)
14
14
  locomotivecms_common (~> 0.0.4)
15
- mime-types (~> 2.5.0)
15
+ mime-types (~> 2.6.1)
16
16
  mimetype-fu (~> 0.1.2)
17
17
  moneta (~> 0.8.0)
18
18
  morphine (~> 0.1.1)
@@ -75,10 +75,10 @@ GEM
75
75
  docile (1.1.5)
76
76
  domain_name (0.5.24)
77
77
  unf (>= 0.0.5, < 1.0.0)
78
- dragonfly (1.0.9)
78
+ dragonfly (1.0.10)
79
79
  addressable (~> 2.3)
80
80
  multi_json (~> 1.0)
81
- rack
81
+ rack (>= 1.3.0)
82
82
  eventmachine (1.0.7)
83
83
  execjs (2.5.2)
84
84
  ffi (1.9.8)
@@ -87,7 +87,7 @@ GEM
87
87
  hike (1.2.3)
88
88
  http-cookie (1.0.2)
89
89
  domain_name (~> 0.5)
90
- httparty (0.13.3)
90
+ httparty (0.13.5)
91
91
  json (~> 1.8)
92
92
  multi_xml (>= 0.5.2)
93
93
  i18n (0.7.0)
@@ -110,7 +110,7 @@ GEM
110
110
  colorize
111
111
  stringex (~> 2.5.2)
112
112
  method_source (0.8.2)
113
- mime-types (2.5)
113
+ mime-types (2.6.1)
114
114
  mimetype-fu (0.1.2)
115
115
  mini_portile (0.6.2)
116
116
  minitest (5.6.1)
@@ -145,7 +145,7 @@ GEM
145
145
  rack_csrf (2.5.0)
146
146
  rack (>= 1.1.0)
147
147
  rake (10.4.2)
148
- rb-fsevent (0.9.4)
148
+ rb-fsevent (0.9.5)
149
149
  rb-inotify (0.9.5)
150
150
  ffi (>= 0.5.0)
151
151
  rest-client (1.8.0)
@@ -169,7 +169,7 @@ GEM
169
169
  crass (~> 1.0.2)
170
170
  nokogiri (>= 1.4.4)
171
171
  nokogumbo (= 1.4.1)
172
- sass (3.4.13)
172
+ sass (3.4.14)
173
173
  simplecov (0.9.2)
174
174
  docile (~> 1.1.0)
175
175
  multi_json (~> 1.0)
@@ -13,6 +13,8 @@ module Locomotive
13
13
 
14
14
  (attributes[:domains] ||= []) << 'localhost'
15
15
 
16
+ attributes[:picture] = File.expand_path(File.join(site_path, 'icon.png'))
17
+
16
18
  [attributes]
17
19
  end
18
20
 
@@ -17,8 +17,10 @@ module Locomotive
17
17
 
18
18
  def load_array
19
19
  [].tap do |array|
20
- _load(path).each do |key, values|
21
- array << { key: key.to_s, values: HashConverter.to_string(values) }
20
+ if (all = _load(path))
21
+ all.each do |key, values|
22
+ array << { key: key.to_s, values: HashConverter.to_string(values) }
23
+ end
22
24
  end
23
25
  end
24
26
  end
@@ -34,39 +36,3 @@ module Locomotive
34
36
  end
35
37
  end
36
38
  end
37
-
38
- # module Locomotive
39
- # module Steam
40
- # module Repositories
41
- # module Filesystem
42
- # module YAMLLoaders
43
-
44
- # class Translation < Struct.new(:root_path, :cache)
45
-
46
- # include YAMLLoaders::Concerns::Common
47
-
48
- # def list_of_attributes
49
- # cache.fetch('config/translations') { load_array }
50
- # end
51
-
52
- # private
53
-
54
- # def load_array
55
- # [].tap do |array|
56
- # load(path).each do |key, values|
57
- # array << { key: key.to_s, values: HashConverter.to_string(values) }
58
- # end
59
- # end
60
- # end
61
-
62
- # def path
63
- # File.join(root_path, 'config', 'translations.yml')
64
- # end
65
-
66
- # end
67
-
68
- # end
69
- # end
70
- # end
71
- # end
72
- # end
@@ -9,7 +9,7 @@ module Locomotive::Steam
9
9
  include Enumerable
10
10
  extend Forwardable
11
11
 
12
- def_delegators :all, :each, :to_s, :to_a, :empty?, :size
12
+ def_delegators :all, :each, :last, :to_s, :to_a, :empty?, :size
13
13
 
14
14
  alias :length :size
15
15
  alias :count :size
@@ -4,6 +4,8 @@ module Locomotive::Steam
4
4
 
5
5
  class Query
6
6
 
7
+ SYMBOL_OPERATORS = %w(all elem_match exists gt gte in lt lte mod ne near near_sphere nin with_size with_type within_box within_circle within_polygon within_spherical_circle)
8
+
7
9
  attr_reader :criteria, :sort
8
10
 
9
11
  def initialize(scope, localized_attributes, &block)
@@ -17,7 +19,7 @@ module Locomotive::Steam
17
19
 
18
20
  def where(criterion = nil)
19
21
  self.tap do
20
- @criteria.merge!(criterion) unless criterion.nil?
22
+ @criteria.merge!(decode_symbol_operators(criterion)) unless criterion.nil?
21
23
  end
22
24
  end
23
25
 
@@ -75,6 +77,22 @@ module Locomotive::Steam
75
77
  where(site_id: @scope.site._id) if @scope.site
76
78
  end
77
79
 
80
+ def decode_symbol_operators(criterion)
81
+ criterion.dup.tap do |_criterion|
82
+ criterion.each do |key, value|
83
+ next unless key.is_a?(String)
84
+
85
+ _key, operator = key.split('.')
86
+
87
+ if operator && SYMBOL_OPERATORS.include?(operator)
88
+ _criterion.delete(key)
89
+ _key = _key.to_s.to_sym.public_send(operator.to_sym)
90
+ _criterion[_key] = value
91
+ end
92
+ end
93
+ end
94
+ end
95
+
78
96
  end
79
97
 
80
98
  end
@@ -28,7 +28,7 @@ module Locomotive::Steam
28
28
  end
29
29
 
30
30
  def key(name, operator)
31
- name.__send__(operator)
31
+ name.to_sym.__send__(operator.to_sym)
32
32
  end
33
33
 
34
34
  def base_url(mapper, scope, entity = nil)
@@ -18,19 +18,27 @@ module Locomotive
18
18
  private
19
19
 
20
20
  def source_from_template_file
21
- source = File.open(template_path).read.force_encoding('utf-8')
21
+ source = File.read(template_path).force_encoding('utf-8')
22
22
 
23
23
  if match = source.match(FRONTMATTER_REGEXP)
24
24
  source = match[:template]
25
25
  end
26
26
 
27
27
  if template_path.ends_with?('.haml')
28
- Haml::Engine.new(source).render
28
+ render_haml(source, template_path)
29
29
  else
30
30
  source
31
31
  end
32
32
  end
33
33
 
34
+ def render_haml(source, template_path)
35
+ begin
36
+ Haml::Engine.new(source).render
37
+ rescue Haml::SyntaxError => e
38
+ raise Steam::RenderError.new(e.message, template_path, source, e.line, e.backtrace)
39
+ end
40
+ end
41
+
34
42
  end
35
43
 
36
44
  end
@@ -145,6 +145,7 @@ module Locomotive::Steam
145
145
  class FileField < Struct.new(:filename, :base, :updated_at)
146
146
 
147
147
  def url
148
+ return if filename.blank?
148
149
  base.blank? ? filename : "#{base}/#{filename}"
149
150
  end
150
151
 
@@ -8,12 +8,17 @@ module Locomotive::Steam
8
8
 
9
9
  def initialize(attributes = {})
10
10
  super({
11
+ content: nil,
11
12
  source: nil
12
13
  }.merge(attributes))
13
14
  end
14
15
 
16
+ def source
17
+ self[:source].blank? ? self.content : self[:source]
18
+ end
19
+
15
20
  def default_content?
16
- !!self[:default_content]
21
+ self.content.blank?
17
22
  end
18
23
 
19
24
  end
@@ -48,6 +48,10 @@ module Locomotive::Steam
48
48
  self[:raw_template]
49
49
  end
50
50
 
51
+ def depth
52
+ @depth || self[:depth]
53
+ end
54
+
51
55
  def to_liquid
52
56
  Locomotive::Steam::Liquid::Drops::Page.new(self)
53
57
  end
@@ -0,0 +1,32 @@
1
+ module Locomotive::Steam
2
+
3
+ class RenderError < ::StandardError
4
+
5
+ LINES_RANGE = 10
6
+
7
+ attr_reader :file, :source, :line, :original_backtrace
8
+
9
+ def initialize(message, file, source, line, original_backtrace)
10
+ @file, @source, @line, @original_backtrace = file, source, line, original_backtrace
11
+ super(message)
12
+ end
13
+
14
+ def code_lines
15
+ return [] if source.blank? || line.nil?
16
+
17
+ lines = source.split("\n")
18
+
19
+ start = line - (LINES_RANGE / 2)
20
+ start = 0 if start < 0
21
+ finish = line + (LINES_RANGE / 2)
22
+
23
+ (start..finish).map { |i| [i, lines[i]] }
24
+ end
25
+
26
+ def backtrace
27
+ original_backtrace
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -22,7 +22,8 @@ module Locomotive
22
22
 
23
23
  def scoped_pages
24
24
  conditions = @context['with_scope'] || {}
25
- conditions['slug.ne'] = '404'
25
+ conditions['slug.ne'] = '404'
26
+ conditions[:published] = true
26
27
  repository.all(conditions)
27
28
  end
28
29
 
@@ -33,7 +33,8 @@ module Locomotive
33
33
  if element.source =~ /^https?/
34
34
  element.source
35
35
  else
36
- "#{element.base_url}/#{element.source}"
36
+ _url = element.source.start_with?('/') ? element.source : "/#{element.source}"
37
+ "#{element.base_url}#{_url}"
37
38
  end
38
39
  end
39
40
 
@@ -10,7 +10,7 @@ module Locomotive
10
10
  parent = options[:parent_finder].find(options[:page], @template_name)
11
11
 
12
12
  # no need to go further if the parent does not exist
13
- raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if parent.nil?
13
+ raise PageNotFound.new("Extending a missing page. Page/Layout with fullpath '#{@template_name}' was not found") if parent.nil?
14
14
 
15
15
  ActiveSupport::Notifications.instrument("steam.parse.extends", page: options[:page], parent: parent)
16
16
 
@@ -24,7 +24,7 @@ module Locomotive
24
24
  name = options.shift
25
25
  options = options.shift || {}
26
26
 
27
- form_attributes = { method: 'POST', enctype: 'multipart/form-data' }.merge(options.slice(:id, :class))
27
+ form_attributes = { method: 'POST', enctype: 'multipart/form-data' }.merge(options.slice(:id, :class, :action))
28
28
 
29
29
  html_content_tag :form,
30
30
  content_type_html(name) + csrf_html + callbacks_html(options) + yield,
@@ -54,7 +54,7 @@ module Locomotive
54
54
  #
55
55
  def paginate_collection(context)
56
56
  collection = context[@collection_name]
57
- current_page = context['current_page']
57
+ current_page = context['current_page'].try(:to_i)
58
58
 
59
59
  raise ::Liquid::ArgumentError.new("Cannot paginate '#{@collection_name}'. Not found.") if collection.nil?
60
60
 
@@ -17,7 +17,7 @@ module Locomotive
17
17
 
18
18
  def render_title(context)
19
19
  title = self.value_for(:seo_title, context)
20
- title = context.registers[:site].name if title.blank?
20
+ title = context['site'].name if title.blank?
21
21
 
22
22
  %{
23
23
  <title>#{title}</title>
@@ -38,7 +38,7 @@ module Locomotive
38
38
 
39
39
  def value_for(attribute, context)
40
40
  object = self.metadata_object(context)
41
- value = object.try(attribute.to_sym).blank? ? context.registers[:site].send(attribute.to_sym) : object.send(attribute.to_sym)
41
+ value = object.try(attribute.to_sym).blank? ? context['site'].send(attribute.to_sym) : object.send(attribute.to_sym)
42
42
  self.sanitized_string(value)
43
43
  end
44
44
 
@@ -3,6 +3,10 @@ module Locomotive::Steam
3
3
 
4
4
  class I18nField
5
5
 
6
+ extend Forwardable
7
+
8
+ def_delegators :@translations, :values, :blank?
9
+
6
10
  attr_reader :name, :translations
7
11
 
8
12
  def initialize(name, translations)
@@ -18,10 +22,6 @@ module Locomotive::Steam
18
22
  @translations[locale] = value
19
23
  end
20
24
 
21
- def values
22
- @translations.values
23
- end
24
-
25
25
  def translations=(translations)
26
26
  @translations = (if translations.respond_to?(:fetch)
27
27
  translations
@@ -47,6 +47,10 @@ module Locomotive::Steam
47
47
  adapter.query(mapper, scope, &block).first
48
48
  end
49
49
 
50
+ def last(&block)
51
+ adapter.query(mapper, scope, &block).last
52
+ end
53
+
50
54
  def k(name, operator)
51
55
  adapter.key(name, operator)
52
56
  end
@@ -162,12 +162,15 @@ module Locomotive
162
162
 
163
163
  with(entry.content_type)
164
164
 
165
- name, direction = self.content_type.order_by.first
165
+ order_by = self.content_type.order_by
166
+ name, direction = order_by.first
166
167
  op = direction == 'asc' ? asc_op : desc_op
167
168
 
168
169
  conditions = prepare_conditions({ k(name, op) => i18n_value_of(entry, name) })
169
170
 
170
- first { where(conditions) }
171
+ public_send(op == 'gt' ? :last : :first) do
172
+ where(conditions).order_by(order_by)
173
+ end
171
174
  end
172
175
 
173
176
  def groups_to_array(name, groups)
@@ -6,7 +6,7 @@ module Locomotive
6
6
  include Locomotive::Steam::Services::Concerns::Decorator
7
7
 
8
8
  def find(page, block, slug)
9
- decorate do
9
+ decorate(Decorators::I18nDecorator) do
10
10
  repository.editable_element_for(page, block, slug).tap do |element|
11
11
  element.base_url = repository.base_url(page) if element
12
12
  end
@@ -67,7 +67,7 @@ module Locomotive
67
67
  entry.valid?
68
68
 
69
69
  # check if the entry has unique values for its
70
- # fields marked as unique are really
70
+ # fields marked as unique
71
71
  content_type_repository.look_for_unique_fields(entry.content_type).each do |name, _|
72
72
  if repository.with(entry.content_type).exists?(name => entry.send(name))
73
73
  entry.errors.add(name, :unique)
@@ -8,12 +8,10 @@ module Locomotive
8
8
  def find(page, fullpath)
9
9
  return nil if fullpath.blank?
10
10
 
11
- decorate do
12
- if fullpath.strip == 'parent'
13
- repository.parent_of(page)
14
- else
15
- repository.by_fullpath(fullpath)
16
- end
11
+ if fullpath.strip == 'parent'
12
+ decorate { repository.parent_of(page) }
13
+ else
14
+ super(fullpath)
17
15
  end
18
16
  end
19
17
 
@@ -3,6 +3,6 @@
3
3
  # 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0
4
4
  module Locomotive
5
5
  module Steam
6
- VERSION = '1.0.0-alpha.1'
6
+ VERSION = '1.0.0-alpha.2'
7
7
  end
8
8
  end
@@ -3,6 +3,7 @@ require 'locomotive/common'
3
3
  require_relative 'steam/configuration'
4
4
  require_relative_all 'steam/decorators'
5
5
  require_relative 'steam/liquid'
6
+ require_relative 'steam/errors'
6
7
 
7
8
  require_relative 'steam/models'
8
9
  require_relative_all 'steam/entities'
@@ -23,12 +23,12 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency 'sanitize', '~> 4.0.0'
25
25
  spec.add_dependency 'morphine', '~> 0.1.1'
26
- spec.add_dependency 'httparty', '~> 0.13.3'
26
+ spec.add_dependency 'httparty', '~> 0.13.5'
27
27
  spec.add_dependency 'chronic', '~> 0.10.2'
28
28
 
29
29
  spec.add_dependency 'rack-rewrite', '~> 1.5.1'
30
30
  spec.add_dependency 'rack-cache', '~> 1.2'
31
- spec.add_dependency 'dragonfly', '~> 1.0.9'
31
+ spec.add_dependency 'dragonfly', '~> 1.0.10'
32
32
  spec.add_dependency 'moneta', '~> 0.8.0'
33
33
  spec.add_dependency 'rack_csrf', '~> 2.5.0'
34
34
 
@@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
42
42
  spec.add_dependency 'RedCloth', '~> 4.2.9'
43
43
  spec.add_dependency 'haml', '~> 4.0.6'
44
44
  spec.add_dependency 'mimetype-fu', '~> 0.1.2'
45
- spec.add_dependency 'mime-types', '~> 2.5.0'
45
+ spec.add_dependency 'mime-types', '~> 2.6.1'
46
46
 
47
47
  spec.add_dependency 'locomotivecms-solid', '~> 4.0.0.alpha2'
48
48
  spec.add_dependency 'locomotivecms_common', '~> 0.0.4'
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: Page to test the nav tag
3
3
  listed: false
4
- published: false
4
+ published: true
5
5
  ---
6
- {% nav site %}
6
+ {% nav site %}
@@ -5,6 +5,11 @@ require_relative '../../../lib/locomotive/steam/adapters/mongodb.rb'
5
5
 
6
6
  describe Locomotive::Steam::PageRepository do
7
7
 
8
+ # before(:all) do
9
+ # Moped.logger = Logger.new($stdout)
10
+ # Moped.logger.level = Logger::DEBUG
11
+ # end
12
+
8
13
  shared_examples_for 'a repository' do
9
14
 
10
15
  let(:site) { Locomotive::Steam::Site.new(_id: site_id, locales: %w(en fr nb)) }
@@ -12,8 +17,14 @@ describe Locomotive::Steam::PageRepository do
12
17
  let(:repository) { described_class.new(adapter, site, locale) }
13
18
 
14
19
  describe '#all' do
15
- subject { repository.all }
20
+ let(:conditions) { {} }
21
+ subject { repository.all(conditions) }
16
22
  it { expect(subject.size).to eq 24 }
23
+
24
+ context 'with conditions' do
25
+ let(:conditions) { { fullpath: 'index', 'slug.ne' => '404' } }
26
+ it { expect(subject.size).to eq 1 }
27
+ end
17
28
  end
18
29
 
19
30
  describe '#query' do
@@ -18,7 +18,7 @@ describe Locomotive::Steam::Server do
18
18
 
19
19
  it 'checks if it looks valid' do
20
20
  expect(Nokogiri::XML(subject).errors.empty?).to eq true
21
- expect(subject.scan(/<url>/).size).to eq 45
21
+ expect(subject.scan(/<url>/).size).to eq 46
22
22
  expect(subject).to match("<loc>http://example.org/songs/song-number-2/band</loc>")
23
23
  expect(subject).to match((<<-EOF
24
24
  <url>
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::Decorators::TemplateDecorator do
4
+
5
+ let(:template_path) { 'template.liquid' }
6
+ let(:page) { instance_double('Page', localized_attributes: [], template_path: template_path) }
7
+ let(:locale) { 'fr' }
8
+ let(:default_locale) { nil }
9
+ let(:decorated) { described_class.new(page, locale, default_locale) }
10
+
11
+ describe '#liquid_source' do
12
+
13
+ let(:content) { 'Lorem ipsum' }
14
+
15
+ before { allow(File).to receive(:read).and_return(content) }
16
+
17
+ subject { decorated.liquid_source.strip }
18
+
19
+ it { is_expected.to eq 'Lorem ipsum' }
20
+
21
+ context 'HAML file' do
22
+
23
+ let(:template_path) { 'template.liquid.haml' }
24
+ let(:content) { '%p Lorem ipsum' }
25
+
26
+ it { is_expected.to eq '<p>Lorem ipsum</p>' }
27
+
28
+ context 'incorrect HAML syntax' do
29
+
30
+ let(:content) { "foo\n %p TEST" }
31
+
32
+ it 'raises an error' do
33
+ expect { subject }.to raise_error Locomotive::Steam::RenderError
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::RenderError do
4
+
5
+ let(:message) { 'Wrong syntax' }
6
+ let(:file) { 'template.liquid.haml' }
7
+ let(:source) { %w(a b c d e f g h i j k l m n o p q r s t u v w y z).join("\n") }
8
+ let(:line) { 10 }
9
+ let(:backtrace) { 'Backtrace' }
10
+ let(:error) { described_class.new(message, file, source, line, backtrace) }
11
+
12
+ describe '#code_lines' do
13
+
14
+ subject { error.code_lines }
15
+
16
+ it { is_expected.to eq [[5, 'f'], [6, 'g'], [7, 'h'], [8, 'i'], [9, 'j'], [10, 'k'], [11, 'l'], [12, 'm'], [13, 'n'], [14, 'o'], [15, 'p']] }
17
+
18
+ end
19
+
20
+ describe '#backtrace' do
21
+
22
+ subject { error.original_backtrace }
23
+
24
+ it { is_expected.to eq 'Backtrace' }
25
+
26
+ end
27
+
28
+ end
@@ -71,7 +71,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::File do
71
71
  let(:inline_editing) { false }
72
72
 
73
73
  let(:page) { instance_double('Page', fullpath: 'hello-world', updated_at: DateTime.parse('2007-06-29 21:00:00')) }
74
- let(:element) { instance_double('EditableFile', id: 42, default_source_url: nil, source?: false, source: nil, base_url: '') }
74
+ let(:element) { instance_double('EditableFile', id: 42, default_source_url: nil, source?: false, source: nil, content: nil, base_url: '') }
75
75
  let(:services) { Locomotive::Steam::Services.build_instance }
76
76
  let(:context) { ::Liquid::Context.new({}, {}, { page: page, services: services }) }
77
77
 
@@ -92,7 +92,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::File do
92
92
 
93
93
  context 'using the default value' do
94
94
 
95
- let(:element) { instance_double('EditableFile', id: 42, default_source_url: 'http://www.placehold.it/500x500', source?: false, source: nil) }
95
+ let(:element) { instance_double('EditableFile', id: 42, default_source_url: 'http://www.placehold.it/500x500', source?: false, source: nil, content: nil) }
96
96
  it { is_expected.to eq 'http://www.placehold.it/500x500?1183150800' }
97
97
 
98
98
  end
@@ -100,7 +100,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::File do
100
100
  context 'modified value' do
101
101
 
102
102
  let(:file) { 'http://www.placehold.it/250x250' }
103
- let(:element) { instance_double('EditableFile', source: file, source?: true, default_source_url: false, base_url: '') }
103
+ let(:element) { instance_double('EditableFile', source: file, default_source_url: false, base_url: '') }
104
104
  it { is_expected.to eq 'http://www.placehold.it/250x250?1183150800' }
105
105
 
106
106
  end
@@ -5,9 +5,9 @@ describe Locomotive::Steam::Liquid::Tags::SEO do
5
5
  let(:page) { nil }
6
6
  let(:content_entry) { nil }
7
7
 
8
- let(:site) { instance_double('Site', name: 'Acme', seo_title: 'Acme (SEO)', meta_description: 'A short site description', meta_keywords: 'test only cat dog') }
9
- let(:assigns) { { 'page' => page, 'content_entry' => content_entry } }
10
- let(:context) { ::Liquid::Context.new(assigns, {}, { site: site }) }
8
+ let(:site) { liquid_instance_double('Site', name: 'Acme', seo_title: 'Acme (SEO)', meta_description: 'A short site description', meta_keywords: 'test only cat dog') }
9
+ let(:assigns) { { 'site' => site, 'page' => page, 'content_entry' => content_entry } }
10
+ let(:context) { ::Liquid::Context.new(assigns, {}, {}) }
11
11
 
12
12
  subject { render_template(source, context).strip }
13
13
 
@@ -30,7 +30,7 @@ describe Locomotive::Steam::Liquid::Tags::SEO do
30
30
 
31
31
  describe 'no seo_title site property' do
32
32
 
33
- let(:site) { instance_double('Site', name: 'Acme', seo_title: nil, meta_description: 'A short site description', meta_keywords: 'test only cat dog') }
33
+ let(:site) { liquid_instance_double('Site', name: 'Acme', seo_title: nil, meta_description: 'A short site description', meta_keywords: 'test only cat dog') }
34
34
  it { is_expected.to eq '<title>Acme</title>' }
35
35
 
36
36
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::Models::I18nField do
4
+
5
+ let(:name) { 'title' }
6
+ let(:translations) { nil }
7
+ let(:field) { described_class.new(name, translations) }
8
+
9
+ describe '#blank?' do
10
+
11
+ subject { field.blank? }
12
+
13
+ it { is_expected.to eq true }
14
+
15
+ context 'with translations' do
16
+
17
+ let(:translations) { { en: 'Hello world', fr: nil } }
18
+
19
+ it { is_expected.to eq false }
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotivecms_steam
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.alpha.1
4
+ version: 1.0.0.pre.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-05-18 00:00:00.000000000 Z
14
+ date: 2015-05-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -103,14 +103,14 @@ dependencies:
103
103
  requirements:
104
104
  - - "~>"
105
105
  - !ruby/object:Gem::Version
106
- version: 0.13.3
106
+ version: 0.13.5
107
107
  type: :runtime
108
108
  prerelease: false
109
109
  version_requirements: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - "~>"
112
112
  - !ruby/object:Gem::Version
113
- version: 0.13.3
113
+ version: 0.13.5
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: chronic
116
116
  requirement: !ruby/object:Gem::Requirement
@@ -159,14 +159,14 @@ dependencies:
159
159
  requirements:
160
160
  - - "~>"
161
161
  - !ruby/object:Gem::Version
162
- version: 1.0.9
162
+ version: 1.0.10
163
163
  type: :runtime
164
164
  prerelease: false
165
165
  version_requirements: !ruby/object:Gem::Requirement
166
166
  requirements:
167
167
  - - "~>"
168
168
  - !ruby/object:Gem::Version
169
- version: 1.0.9
169
+ version: 1.0.10
170
170
  - !ruby/object:Gem::Dependency
171
171
  name: moneta
172
172
  requirement: !ruby/object:Gem::Requirement
@@ -327,14 +327,14 @@ dependencies:
327
327
  requirements:
328
328
  - - "~>"
329
329
  - !ruby/object:Gem::Version
330
- version: 2.5.0
330
+ version: 2.6.1
331
331
  type: :runtime
332
332
  prerelease: false
333
333
  version_requirements: !ruby/object:Gem::Requirement
334
334
  requirements:
335
335
  - - "~>"
336
336
  - !ruby/object:Gem::Version
337
- version: 2.5.0
337
+ version: 2.6.1
338
338
  - !ruby/object:Gem::Dependency
339
339
  name: locomotivecms-solid
340
340
  requirement: !ruby/object:Gem::Requirement
@@ -434,6 +434,7 @@ files:
434
434
  - lib/locomotive/steam/entities/snippet.rb
435
435
  - lib/locomotive/steam/entities/theme_asset.rb
436
436
  - lib/locomotive/steam/entities/translation.rb
437
+ - lib/locomotive/steam/errors.rb
437
438
  - lib/locomotive/steam/initializers.rb
438
439
  - lib/locomotive/steam/initializers/dragonfly.rb
439
440
  - lib/locomotive/steam/initializers/i18n.rb
@@ -686,12 +687,14 @@ files:
686
687
  - spec/unit/adapters/mongodb_adapter_spec.rb
687
688
  - spec/unit/configuration_spec.rb
688
689
  - spec/unit/decorators/i18n_decorator_spec.rb
690
+ - spec/unit/decorators/template_decorator_spec.rb
689
691
  - spec/unit/entities/content_entry_spec.rb
690
692
  - spec/unit/entities/content_type_field_spec.rb
691
693
  - spec/unit/entities/content_type_spec.rb
692
694
  - spec/unit/entities/page_spec.rb
693
695
  - spec/unit/entities/site_spec.rb
694
696
  - spec/unit/entities/snippet_spec.rb
697
+ - spec/unit/errors_spec.rb
695
698
  - spec/unit/initializers/dragonfly_spec.rb
696
699
  - spec/unit/initializers/sprockets_spec.rb
697
700
  - spec/unit/liquid/drops/content_entry_collection_spec.rb
@@ -732,6 +735,7 @@ files:
732
735
  - spec/unit/middlewares/locale_redirection_spec.rb
733
736
  - spec/unit/middlewares/renderer_spec.rb
734
737
  - spec/unit/middlewares/stack_proxy_spec.rb
738
+ - spec/unit/models/i18n_field_spec.rb
735
739
  - spec/unit/models/mapper_spec.rb
736
740
  - spec/unit/models/pager_spec.rb
737
741
  - spec/unit/models/repository_spec.rb
@@ -915,12 +919,14 @@ test_files:
915
919
  - spec/unit/adapters/mongodb_adapter_spec.rb
916
920
  - spec/unit/configuration_spec.rb
917
921
  - spec/unit/decorators/i18n_decorator_spec.rb
922
+ - spec/unit/decorators/template_decorator_spec.rb
918
923
  - spec/unit/entities/content_entry_spec.rb
919
924
  - spec/unit/entities/content_type_field_spec.rb
920
925
  - spec/unit/entities/content_type_spec.rb
921
926
  - spec/unit/entities/page_spec.rb
922
927
  - spec/unit/entities/site_spec.rb
923
928
  - spec/unit/entities/snippet_spec.rb
929
+ - spec/unit/errors_spec.rb
924
930
  - spec/unit/initializers/dragonfly_spec.rb
925
931
  - spec/unit/initializers/sprockets_spec.rb
926
932
  - spec/unit/liquid/drops/content_entry_collection_spec.rb
@@ -961,6 +967,7 @@ test_files:
961
967
  - spec/unit/middlewares/locale_redirection_spec.rb
962
968
  - spec/unit/middlewares/renderer_spec.rb
963
969
  - spec/unit/middlewares/stack_proxy_spec.rb
970
+ - spec/unit/models/i18n_field_spec.rb
964
971
  - spec/unit/models/mapper_spec.rb
965
972
  - spec/unit/models/pager_spec.rb
966
973
  - spec/unit/models/repository_spec.rb