locomotivecms_steam 1.0.1 → 1.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/Gemfile.lock +16 -17
  4. data/lib/locomotive/steam/adapters/filesystem/sanitizers/site.rb +3 -0
  5. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +22 -0
  6. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/site.rb +1 -1
  7. data/lib/locomotive/steam/adapters/memory/order.rb +2 -2
  8. data/lib/locomotive/steam/entities/content_entry.rb +8 -3
  9. data/lib/locomotive/steam/entities/content_type.rb +1 -0
  10. data/lib/locomotive/steam/liquid/drops/metafields.rb +1 -1
  11. data/lib/locomotive/steam/liquid/drops/{upload_file.rb → uploaded_file.rb} +0 -0
  12. data/lib/locomotive/steam/liquid/filters/number.rb +4 -0
  13. data/lib/locomotive/steam/liquid/tags/editable/base.rb +4 -0
  14. data/lib/locomotive/steam/liquid/tags/editable/text.rb +4 -3
  15. data/lib/locomotive/steam/middlewares/locale_redirection.rb +1 -1
  16. data/lib/locomotive/steam/models/i18n_field.rb +3 -1
  17. data/lib/locomotive/steam/repositories/content_entry_repository.rb +1 -1
  18. data/lib/locomotive/steam/repositories/content_type_field_repository.rb +4 -0
  19. data/lib/locomotive/steam/version.rb +1 -1
  20. data/locomotivecms_steam.gemspec +5 -5
  21. data/spec/fixtures/default/data/songs.yml +4 -2
  22. data/spec/unit/adapters/filesystem/sanitizers/site_spec.rb +26 -1
  23. data/spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb +19 -3
  24. data/spec/unit/adapters/memory/order_spec.rb +15 -0
  25. data/spec/unit/entities/content_entry_spec.rb +9 -0
  26. data/spec/unit/liquid/drops/content_entry_spec.rb +1 -1
  27. data/spec/unit/liquid/drops/metafields_spec.rb +17 -1
  28. data/spec/unit/liquid/filters/number_spec.rb +29 -0
  29. data/spec/unit/liquid/tags/editable/file_spec.rb +6 -0
  30. data/spec/unit/liquid/tags/editable/text_spec.rb +1 -0
  31. data/spec/unit/middlewares/locale_redirection_spec.rb +5 -0
  32. data/spec/unit/repositories/content_entry_repository_spec.rb +59 -33
  33. data/spec/unit/repositories/content_type_field_repository_spec.rb +12 -0
  34. metadata +15 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40ab1d48128f72e386a5703b9d7b8714e518a601
4
- data.tar.gz: 9831bdde9c497e76449501f7311f0aec76d15da6
3
+ metadata.gz: 400e04e9a4062cfc7e0102c922c2fe95cca51ce1
4
+ data.tar.gz: 2336e61a9aa71e12270250a0b5c9fe9954ed979f
5
5
  SHA512:
6
- metadata.gz: 011f9a7993651c5d525bc6ee9485007aa271d1c5a7742e2fa9f12f090d617d3fe64f75159d35293e7e1412eabf69e95b3223d5e60ecb8a62b2848b290c8fba64
7
- data.tar.gz: e18402953d1bbad33d9325a2eb1ed9afbcc2dce76f32116bbc6d3761fefeffa12aa8f98d99b2166dd8e75c821ff5ce531139ff07ef5bdf282f89f97e44a6f530
6
+ metadata.gz: 93d703f38bc555e0eb23ff1aa5d212a5c26bd15d6e6c849a4f7a585093a3c952c45eafc11bb925e75548ebe0c3c0ad079c517391cb5adc9cc97b861910e8921a
7
+ data.tar.gz: 2cde9a62ba99ffcf7d731354af3faffbe01eaa2a76bb0f39a209f019df5cccf63b3ee08848a39ed9d70a96b8ab1ac3488997a5908355e17105acaf2aa66acbae
data/Gemfile CHANGED
@@ -3,7 +3,8 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- # gem 'locomotivecms_common', '~> 0.0.3', path: '../common'
6
+ # gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '257047b'
7
+ # gem 'locomotivecms_common', path: '../common'
7
8
  # gem 'locomotivecms_models', '~> 0.0.1', path: '../models'
8
9
  # gem 'locomotivecms_models', '0.0.1.pre.alpha'
9
10
  # gem 'locomotivecms-liquid', path: '/Users/didier/Documents/LocomotiveCMS/gems/liquid'
data/Gemfile.lock CHANGED
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_steam (1.0.1)
4
+ locomotivecms_steam (1.1.0.rc1)
5
5
  RedCloth (~> 4.2.9)
6
- autoprefixer-rails (~> 6.2.3)
6
+ autoprefixer-rails (~> 6.3.3.1)
7
7
  chronic (~> 0.10.2)
8
8
  coffee-script (~> 2.4.1)
9
9
  compass (~> 1.0.3)
10
10
  dragonfly (~> 1.0.12)
11
11
  haml (~> 4.0.6)
12
12
  httparty (~> 0.13.6)
13
- kramdown (~> 1.9.0)
13
+ kramdown (~> 1.10.0)
14
14
  locomotivecms-solid (~> 4.0.1)
15
- locomotivecms_common (~> 0.0.5)
15
+ locomotivecms_common (~> 0.1.0)
16
16
  mime-types (~> 2.6.1)
17
17
  mimetype-fu (~> 0.1.2)
18
18
  moneta (~> 0.8.0)
19
19
  morphine (~> 0.1.1)
20
20
  nokogiri (~> 1.6.7.2)
21
- rack-cache (~> 1.2)
21
+ rack-cache (~> 1.6.1)
22
22
  rack-rewrite (~> 1.5.1)
23
23
  rack_csrf (~> 2.5.0)
24
24
  sanitize (~> 4.0.1)
@@ -29,7 +29,7 @@ GEM
29
29
  remote: https://rubygems.org/
30
30
  specs:
31
31
  RedCloth (4.2.9)
32
- activesupport (4.2.5.1)
32
+ activesupport (4.2.5.2)
33
33
  i18n (~> 0.7)
34
34
  json (~> 1.7, >= 1.7.7)
35
35
  minitest (~> 5.1)
@@ -37,10 +37,9 @@ GEM
37
37
  tzinfo (~> 1.1)
38
38
  addressable (2.4.0)
39
39
  attr_extras (4.4.0)
40
- autoprefixer-rails (6.2.3)
40
+ autoprefixer-rails (6.3.3.1)
41
41
  execjs
42
- json
43
- bson (4.0.0)
42
+ bson (4.0.2)
44
43
  byebug (8.2.1)
45
44
  chronic (0.10.2)
46
45
  chunky_png (1.3.5)
@@ -64,7 +63,7 @@ GEM
64
63
  sass (>= 3.3.0, < 3.5)
65
64
  compass-import-once (1.0.5)
66
65
  sass (>= 3.2, < 3.5)
67
- concurrent-ruby (1.0.0)
66
+ concurrent-ruby (1.0.1)
68
67
  coveralls (0.8.10)
69
68
  json (~> 1.8)
70
69
  rest-client (>= 1.6.8, < 2)
@@ -104,15 +103,15 @@ GEM
104
103
  json_spec (1.1.4)
105
104
  multi_json (~> 1.0)
106
105
  rspec (>= 2.0, < 4.0)
107
- kramdown (1.9.0)
106
+ kramdown (1.10.0)
108
107
  locomotivecms-liquid (4.0.0)
109
108
  locomotivecms-solid (4.0.1)
110
109
  locomotivecms-liquid (~> 4.0.0)
111
- locomotivecms_common (0.0.5)
112
- activesupport (~> 4.2.1)
110
+ locomotivecms_common (0.1.0)
111
+ activesupport (~> 4.2.5.2)
113
112
  attr_extras (~> 4.4.0)
114
113
  colorize
115
- stringex (~> 2.5.2)
114
+ stringex (~> 2.6.0)
116
115
  memory_profiler (0.9.6)
117
116
  method_source (0.8.2)
118
117
  mime-types (2.6.2)
@@ -120,7 +119,7 @@ GEM
120
119
  mini_portile2 (2.0.0)
121
120
  minitest (5.8.4)
122
121
  moneta (0.8.0)
123
- mongo (2.2.1)
122
+ mongo (2.2.3)
124
123
  bson (~> 4.0)
125
124
  morphine (0.1.1)
126
125
  multi_json (1.11.2)
@@ -187,7 +186,7 @@ GEM
187
186
  concurrent-ruby (~> 1.0)
188
187
  rack (> 1, < 3)
189
188
  stackprof (0.2.7)
190
- stringex (2.5.2)
189
+ stringex (2.6.0)
191
190
  term-ansicolor (1.3.2)
192
191
  tins (~> 1.0)
193
192
  thor (0.19.1)
@@ -214,7 +213,7 @@ DEPENDENCIES
214
213
  json_spec (~> 1.1.4)
215
214
  locomotivecms_steam!
216
215
  memory_profiler
217
- mongo (~> 2.2.1)
216
+ mongo (~> 2.2.3)
218
217
  origin (~> 2.1.1)
219
218
  pry-byebug (~> 3.3.0)
220
219
  puma
@@ -28,10 +28,13 @@ module Locomotive::Steam
28
28
 
29
29
  def parse_metafields(fields)
30
30
  fields.each_with_index.map do |(name, attributes), position|
31
+ name, attributes = name.to_a[0] if name.is_a?(Hash) # ordered list of fields
32
+
31
33
  if attributes # Hash
32
34
  attributes[:label] = { default: attributes[:label] } if attributes[:label].is_a?(String)
33
35
  attributes[:hint] = { default: attributes[:hint] } if attributes[:hint].is_a?(String)
34
36
  end
37
+
35
38
  { name: name.to_s, position: position }.merge(attributes || {})
36
39
  end
37
40
  end
@@ -22,6 +22,7 @@ module Locomotive
22
22
 
23
23
  modify_for_selects(_attributes)
24
24
  modify_for_associations(_attributes)
25
+ modify_for_files(_attributes)
25
26
 
26
27
  list << _attributes
27
28
  end
@@ -34,6 +35,27 @@ module Locomotive
34
35
  end
35
36
  end
36
37
 
38
+ def modify_for_files(attributes)
39
+ content_type.file_fields.each do |field|
40
+ attributes[:"#{field.name}_size"] ||= {}
41
+ value = attributes[:"#{field.name}_size"]
42
+
43
+ if (path = attributes[field.name.to_sym]).is_a?(Hash)
44
+ path.each { |locale, path| value[locale.to_s] = file_size(path) }
45
+ else
46
+ value['default'] = file_size(path)
47
+ end
48
+ end
49
+ end
50
+
51
+ def file_size(path)
52
+ return nil if path.blank?
53
+
54
+ _path = File.join(site_path, 'public', path)
55
+
56
+ File.exists?(_path) ? File.size(_path) : nil
57
+ end
58
+
37
59
  def modify_for_associations(attributes)
38
60
  content_type.association_fields.each do |field|
39
61
  case field.type
@@ -23,7 +23,7 @@ module Locomotive
23
23
  private
24
24
 
25
25
  def load_metafields_schema
26
- schema = _load(File.join(site_path, 'config', 'metafields_schema.yml'))
26
+ _load(File.join(site_path, 'config', 'metafields_schema.yml'))
27
27
  end
28
28
 
29
29
  end
@@ -51,11 +51,11 @@ module Locomotive::Steam
51
51
  end
52
52
 
53
53
  class Asc < Direction
54
- def <=>(other); @obj <=> other.obj; end
54
+ def <=>(other) @obj && other.obj ? @obj <=> other.obj : @obj ? -1 : 1; end
55
55
  end
56
56
 
57
57
  class Desc < Direction
58
- def <=>(other); other.obj <=> @obj; end
58
+ def <=>(other); @obj && other.obj ? other.obj <=> @obj : @obj ? -1 : 1; end
59
59
  end
60
60
 
61
61
  end
@@ -129,8 +129,13 @@ module Locomotive::Steam
129
129
  end
130
130
 
131
131
  def _cast_file(field)
132
- _cast_convertor(field.name) do |value|
133
- value.respond_to?(:url) ? value : FileField.new(value, self.base_url, self.updated_at)
132
+ _cast_convertor(field.name) do |value, locale|
133
+ if value.respond_to?(:url)
134
+ value
135
+ else
136
+ size = (self[:"#{field.name}_size"] || {})[locale || 'default']
137
+ FileField.new(value, self.base_url, size, self.updated_at)
138
+ end
134
139
  end
135
140
  end
136
141
 
@@ -172,7 +177,7 @@ module Locomotive::Steam
172
177
  # Represent a file
173
178
  class FileField
174
179
 
175
- attr_accessor_initialize :filename, :base, :updated_at
180
+ attr_accessor_initialize :filename, :base, :size, :updated_at
176
181
 
177
182
  def url
178
183
  return if filename.blank?
@@ -7,6 +7,7 @@ module Locomotive::Steam
7
7
 
8
8
  def_delegator :fields, :associations, :association_fields
9
9
  def_delegator :fields, :selects, :select_fields
10
+ def_delegator :fields, :files, :file_fields
10
11
  def_delegator :fields, :default, :fields_with_default
11
12
 
12
13
  def initialize(attributes = {})
@@ -38,7 +38,7 @@ module Locomotive
38
38
 
39
39
  return @labels_and_values if @labels_and_values
40
40
 
41
- ordered_fields = @namespace['fields'].sort { |f| f['position'] }
41
+ ordered_fields = @namespace['fields'].sort { |a, b| a['position'] <=> b['position'] }
42
42
 
43
43
  @labels_and_values = ordered_fields.map do |field|
44
44
  value, localized = values[field['name']], field['localized']
@@ -12,6 +12,10 @@ module Locomotive
12
12
  NumberProxyHelper.new(:percentage, @context).invoke(input, options)
13
13
  end
14
14
 
15
+ def human_size(input, *options)
16
+ NumberProxyHelper.new(:human_size, @context).invoke(input, options)
17
+ end
18
+
15
19
  def mod(input, modulus)
16
20
  input.to_i % modulus.to_i
17
21
  end
@@ -47,6 +47,10 @@ module Locomotive
47
47
  end
48
48
  end
49
49
 
50
+ def blank?
51
+ false
52
+ end
53
+
50
54
  protected
51
55
 
52
56
  def render_default_content
@@ -44,7 +44,8 @@ module Locomotive
44
44
  content_from_default: self.render_default_content,
45
45
  format: @element_options[:format] || 'html',
46
46
  rows: @element_options[:rows] || 10,
47
- line_break: @element_options[:line_break].blank? ? true : @element_options[:line_break]
47
+ inline: @element_options[:inline],
48
+ line_break: @element_options[:line_break].blank? ? true : @element_options[:line_break],
48
49
  )
49
50
  end
50
51
 
@@ -67,14 +68,14 @@ module Locomotive
67
68
  super
68
69
  end
69
70
  def default_element_attributes
70
- super.merge(format: 'raw', rows: 2, line_break: false)
71
+ super.merge(format: 'raw', rows: 2, line_break: false, inline: true)
71
72
  end
72
73
  end
73
74
  ::Liquid::Template.register_tag('editable_short_text'.freeze, ShortText)
74
75
 
75
76
  class LongText < ShortText
76
77
  def default_element_attributes
77
- super.merge(format: 'html', rows: 15, line_break: true)
78
+ super.merge(format: 'html', rows: 15, line_break: true, inline: false)
78
79
  end
79
80
  end
80
81
  ::Liquid::Template.register_tag('editable_long_text'.freeze, LongText)
@@ -29,7 +29,7 @@ module Locomotive::Steam
29
29
  end
30
30
 
31
31
  def apply_redirection?
32
- site.locales.size > 1 && request.get?
32
+ site.locales.size > 1 && request.get? && env['PATH_INFO'] != '/sitemap.xml'
33
33
  end
34
34
 
35
35
  def default_locale?
@@ -43,7 +43,9 @@ module Locomotive::Steam
43
43
  if default
44
44
  @translations = Hash.new(yield(default))
45
45
  else
46
- each { |l, _value| self[l] = yield(_value) }
46
+ each do |l, _value|
47
+ self[l] = block.arity == 2 ? yield(_value, l) : yield(_value)
48
+ end
47
49
  end
48
50
  self
49
51
  end
@@ -171,7 +171,7 @@ module Locomotive
171
171
 
172
172
  conditions = prepare_conditions({ k(name, op) => i18n_value_of(entry, name) })
173
173
 
174
- public_send(op == 'gt' ? :last : :first) do
174
+ public_send(asc_op == 'gt' ? :first : :last) do
175
175
  where(conditions).order_by(order_by)
176
176
  end
177
177
  end
@@ -22,6 +22,10 @@ module Locomotive
22
22
  query { where(type: :select) }.all
23
23
  end
24
24
 
25
+ def files
26
+ query { where(type: :file) }.all
27
+ end
28
+
25
29
  def belongs_to
26
30
  query { where(type: :belongs_to) }.all
27
31
  end
@@ -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.1'
6
+ VERSION = '1.1.0.rc1'
7
7
  end
8
8
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.add_development_dependency 'bundler', '~> 1.7'
19
19
  spec.add_development_dependency 'rake', '~> 10.4.2'
20
20
 
21
- spec.add_development_dependency 'mongo', '~> 2.2.1'
21
+ spec.add_development_dependency 'mongo', '~> 2.2.3'
22
22
  spec.add_development_dependency 'origin', '~> 2.1.1'
23
23
 
24
24
  spec.add_dependency 'nokogiri', '~> 1.6.7.2'
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency 'chronic', '~> 0.10.2'
29
29
 
30
30
  spec.add_dependency 'rack-rewrite', '~> 1.5.1'
31
- spec.add_dependency 'rack-cache', '~> 1.2'
31
+ spec.add_dependency 'rack-cache', '~> 1.6.1'
32
32
  spec.add_dependency 'dragonfly', '~> 1.0.12'
33
33
  spec.add_dependency 'moneta', '~> 0.8.0'
34
34
  spec.add_dependency 'rack_csrf', '~> 2.5.0'
@@ -37,16 +37,16 @@ Gem::Specification.new do |spec|
37
37
  spec.add_dependency 'sass', '~> 3.4.21'
38
38
  spec.add_dependency 'coffee-script', '~> 2.4.1'
39
39
  spec.add_dependency 'compass', '~> 1.0.3'
40
- spec.add_dependency 'autoprefixer-rails', '~> 6.2.3'
40
+ spec.add_dependency 'autoprefixer-rails', '~> 6.3.3.1'
41
41
 
42
- spec.add_dependency 'kramdown', '~> 1.9.0'
42
+ spec.add_dependency 'kramdown', '~> 1.10.0'
43
43
  spec.add_dependency 'RedCloth', '~> 4.2.9'
44
44
  spec.add_dependency 'haml', '~> 4.0.6'
45
45
  spec.add_dependency 'mimetype-fu', '~> 0.1.2'
46
46
  spec.add_dependency 'mime-types', '~> 2.6.1'
47
47
 
48
48
  spec.add_dependency 'locomotivecms-solid', '~> 4.0.1'
49
- spec.add_dependency 'locomotivecms_common', '~> 0.0.5'
49
+ spec.add_dependency 'locomotivecms_common', '~> 0.1.0'
50
50
 
51
51
  spec.required_ruby_version = '>= 2.0'
52
52
  end
@@ -8,7 +8,9 @@
8
8
  duration: "6:28"
9
9
  short_description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur vitae tincidunt urna. Nunc felis purus, ultricies et venenatis bibendum, fringilla eu lectus. Sed cursus, sem at blandit mattis, libero quam egestas tortor, eget cursus dolor tellus id nunc.
10
10
  audio_url: http://blip.tv/file/get/NicolasRaynier-Milk617.flv
11
- cover: /samples/asset_collections/cover.jpg
11
+ cover:
12
+ en: /samples/asset_collections/cover.jpg
13
+ fr: /samples/photo_2.jpg
12
14
  band: pearl-jam
13
15
  - "Song #3":
14
16
  duration: "6:28"
@@ -43,4 +45,4 @@
43
45
  duration: "6:28"
44
46
  short_description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur vitae tincidunt urna. Nunc felis purus, ultricies et venenatis bibendum, fringilla eu lectus. Sed cursus, sem at blandit mattis, libero quam egestas tortor, eget cursus dolor tellus id nunc.
45
47
  audio_url: http://blip.tv/file/get/NicolasRaynier-Milk617.flv
46
- cover: /samples/asset_collections/cover.jpg
48
+ cover: /samples/asset_collections/cover.jpg
@@ -26,7 +26,26 @@ describe Locomotive::Steam::Adapters::Filesystem::Sanitizers::Site do
26
26
  describe 'with a schema' do
27
27
 
28
28
  # see the metafields_schema.yml in the fixtures folder
29
- let(:schema) { {:social=>{:label=>{:fr=>"Social (FR)"}, :position=>1, :fields=>["facebook_id", "google_id"]}, :github=>{:position=>0, :fields=>{:api_url=>{:label=>"API Url", :type=>"string", :hint=>"API endpoint"}, :expires_in=>{:label=>{:en=>"Expires in", :fr=>"Expire dans"}, :hint=>{:en=>"Cache - In milliseconds", :fr=>"Cache - En millisecondes"}, :type=>"integer", :min=>0, :max=>3600}}}} }
29
+ let(:schema) { {
30
+ :social => {
31
+ :label => { :fr=>"Social (FR)" },
32
+ :position => 1,
33
+ :fields => ["facebook_id", "google_id"]
34
+ },
35
+ :github => {
36
+ :position => 0,
37
+ :fields => {
38
+ :api_url => { :label => "API Url", :type => "string", :hint => "API endpoint" },
39
+ :expires_in => { :label => { :en => "Expires in", :fr => "Expire dans" }, :hint => { :en => "Cache - In milliseconds", :fr => "Cache - En millisecondes" }, :type => "integer", :min => 0, :max => 3600 }
40
+ }
41
+ },
42
+ :theme => {
43
+ :fields => [
44
+ { :color => { :label => 'Color', type: 'color' } },
45
+ { :header => { :label => 'Header image', type: 'image' } }
46
+ ]
47
+ }
48
+ } }
30
49
 
31
50
  it 'loads the full schema' do
32
51
  # First namespace
@@ -40,6 +59,12 @@ describe Locomotive::Steam::Adapters::Filesystem::Sanitizers::Site do
40
59
  expect(subject[1]['position']).to eq 0
41
60
  expect(subject[1]['fields'].count).to eq 2
42
61
  expect(subject[1]['fields'][0]).to eq('name' => 'api_url', 'position' => 0, 'label' => { 'default' => 'API Url' }, 'type' => 'string', 'hint' => { 'default' => 'API endpoint' })
62
+
63
+ # Third namespace
64
+ expect(subject[2]['label']).to eq('default' => 'theme')
65
+ expect(subject[2]['fields'].count).to eq 2
66
+ expect(subject[2]['fields'][0]).to eq('name' => 'color', 'position' => 0, 'label' => { 'default' => 'Color' }, 'type' => 'color')
67
+ expect(subject[2]['fields'][1]).to eq('name' => 'header', 'position' => 1, 'label' => { 'default' => 'Header image' }, 'type' => 'image')
43
68
  end
44
69
 
45
70
  context 'label is a string instead of a hash' do
@@ -6,7 +6,7 @@ require_relative '../../../../../lib/locomotive/steam/adapters/filesystem/yaml_l
6
6
  describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry do
7
7
 
8
8
  let(:site_path) { default_fixture_site_path }
9
- let(:content_type) { instance_double('Bands', _id: 42, slug: 'bands', association_fields: [], select_fields: []) }
9
+ let(:content_type) { instance_double('Bands', _id: 42, slug: 'bands', association_fields: [], select_fields: [], file_fields: []) }
10
10
  let(:scope) { instance_double('Scope', locale: :en, context: { content_type: content_type }) }
11
11
  let(:loader) { described_class.new(site_path) }
12
12
 
@@ -23,7 +23,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry do
23
23
  context 'a content type with a belongs_to field' do
24
24
 
25
25
  let(:field) { instance_double('Field', name: 'band', type: :belongs_to) }
26
- let(:content_type) { instance_double('Songs', slug: 'songs', association_fields: [field], select_fields: []) }
26
+ let(:content_type) { instance_double('Songs', slug: 'songs', association_fields: [field], select_fields: [], file_fields: []) }
27
27
 
28
28
  it 'adds a new attribute for the foreign key' do
29
29
  expect(subject.first[:band_id]).to eq 'pearl-jam'
@@ -36,7 +36,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry do
36
36
  context 'a content type with a select field' do
37
37
 
38
38
  let(:field) { instance_double('Field', name: 'kind', type: :select) }
39
- let(:content_type) { instance_double('Bands', slug: 'bands', select_fields: [field], association_fields: []) }
39
+ let(:content_type) { instance_double('Bands', slug: 'bands', select_fields: [field], association_fields: [], file_fields: []) }
40
40
 
41
41
  it 'adds a new attribute for the foreign key' do
42
42
  expect(subject.first[:kind_id]).to eq 'grunge'
@@ -45,6 +45,22 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry do
45
45
 
46
46
  end
47
47
 
48
+ context 'a content type with a file field' do
49
+
50
+ let(:field) { instance_double('Field', name: 'cover', type: :file) }
51
+ let(:content_type) { instance_double('Songs', slug: 'songs', select_fields: [], association_fields: [], file_fields: [field]) }
52
+
53
+ it 'stores the size of the file' do
54
+ expect(subject.first[:cover_size]).to eq('default' => 14768)
55
+ end
56
+
57
+ it 'stores the size of the file in multiple locales' do
58
+ expect(subject[1][:cover_size]).to eq('en' => 14768, 'fr' => 165883)
59
+ end
60
+
61
+
62
+ end
63
+
48
64
  end
49
65
 
50
66
  end
@@ -71,6 +71,21 @@ describe Locomotive::Steam::Adapters::Memory::Order do
71
71
 
72
72
  it { expect(subject.map(&:id)).to eq([3, 2, 1, 4]) }
73
73
 
74
+ context 'nil value in the array' do
75
+
76
+ let(:array) {
77
+ [
78
+ instance_double('Entry1', id: 1, title: 'b', position: 1),
79
+ instance_double('Entry2', id: 2, title: 'b', position: 2),
80
+ instance_double('Entry3', id: 3, title: nil, position: 3),
81
+ instance_double('Entry3', id: 4, title: 'c', position: 1)
82
+ ]
83
+ }
84
+
85
+ it { expect(subject.map(&:id)).to eq([2, 1, 4, 3]) }
86
+
87
+ end
88
+
74
89
  end
75
90
 
76
91
  end
@@ -169,11 +169,20 @@ describe Locomotive::Steam::ContentEntry do
169
169
  context 'a file' do
170
170
  let(:field_type) { :file }
171
171
  let(:value) { '/foo.png' }
172
+ let(:attributes) { { my_field: value, my_field_size: { 'default' => 42 } } }
172
173
  it { expect(subject.url).to eq('/foo.png') }
174
+ it { expect(subject.size).to eq(42) }
173
175
  context 'localized' do
174
176
  let(:value) { build_i18n_field(en: '/foo-en.png', fr: '/foo-fr.png') }
177
+ let(:attributes) { { my_field: value, my_field_size: { 'en' => 42, 'fr' => 7 } } }
175
178
  it { expect(subject.translations[:en].url).to eq('/foo-en.png') }
179
+ it { expect(subject.translations[:en].size).to eq(42) }
176
180
  it { expect(subject.translations[:fr].url).to eq('/foo-fr.png') }
181
+ it { expect(subject.translations[:fr].size).to eq(7) }
182
+ end
183
+ context 'no file size provided' do
184
+ let(:attributes) { { my_field: value } }
185
+ it { expect(subject.size).to eq(nil) }
177
186
  end
178
187
  end
179
188
 
@@ -101,7 +101,7 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntry do
101
101
  describe '#as_json' do
102
102
 
103
103
  let(:type) { instance_double('Type', fields_by_name: { title: instance_double('StringField', type: :string ), picture: instance_double('FileField', type: :file), category: instance_double('SelectField', type: :select) }) }
104
- let(:picture_field) { Locomotive::Steam::ContentEntry::FileField.new('foo.png', 'http://assets.dev', 42) }
104
+ let(:picture_field) { Locomotive::Steam::ContentEntry::FileField.new('foo.png', 'http://assets.dev', 0, 42) }
105
105
 
106
106
  before do
107
107
  allow(entry).to receive(:to_hash).and_return({ '_id' => 1, 'title' => 'Hello world', 'picture' => picture_field, 'category_id' => 42 })
@@ -3,11 +3,27 @@ require 'spec_helper'
3
3
  describe Locomotive::Steam::Liquid::Drops::Metafields do
4
4
 
5
5
  let(:metafields) { { 'my_namespace' => { 'analytics_id' => { 'default' => '42' }, 'street' => { 'en' => '7 Albert Camus Alley', 'fr' => '7 allée Albert Camus' } } } }
6
- let(:schema) { [ { 'name' => 'my_namespace', fields: [{ name: 'analytics_id' }, { name: 'street', localized: true }, { name: 'country' }] }].as_json }
6
+ let(:schema) { [ { 'name' => 'my_namespace', fields: [{ name: 'analytics_id', position: 1 }, { name: 'street', localized: true, position: 0 }, { name: 'country', :position => 2 }] }].as_json }
7
7
  let(:site) { instance_double('Site', metafields: metafields, metafields_schema: schema) }
8
8
  let(:context) { ::Liquid::Context.new({}, {}, { locale: 'en' }) }
9
9
  let(:drop) { described_class.new(site).tap { |d| d.context = context } }
10
10
 
11
+ describe 'fields' do
12
+
13
+ let(:namespace) { drop.before_method(:my_namespace).tap { |d| d.context = context } }
14
+
15
+ it 'gives the number of the fields' do
16
+ expect(namespace.size).to eq 3
17
+ end
18
+
19
+ it 'iterates over the fields and keeps the order' do
20
+ list = []
21
+ namespace.each { |el| list << el['name'] }
22
+ expect(list).to eq(['street', 'analytics_id', 'country'])
23
+ end
24
+
25
+ end
26
+
11
27
  describe 'calling a metafield' do
12
28
 
13
29
  context 'unknown namespace' do
@@ -87,6 +87,35 @@ describe Locomotive::Steam::Liquid::Filters::Number do
87
87
 
88
88
  end
89
89
 
90
+ describe '#human_size' do
91
+
92
+ subject { human_size(input, options) }
93
+
94
+ context 'not a number' do
95
+
96
+ it { expect(subject).to eq nil }
97
+
98
+ end
99
+
100
+ context 'a number' do
101
+
102
+ let(:input) { 1234567890 }
103
+
104
+ it { expect(subject).to eq '1.15 GB' }
105
+
106
+ end
107
+
108
+ context 'with options' do
109
+
110
+ let(:input) { '1234567' }
111
+ let(:options) { ['precision: 2'] }
112
+
113
+ it { expect(subject).to eq '1.2 MB' }
114
+
115
+ end
116
+
117
+ end
118
+
90
119
  describe '#mod' do
91
120
 
92
121
  it 'returns correct number modulus' do
@@ -145,6 +145,12 @@ describe Locomotive::Steam::Liquid::Tags::Editable::File do
145
145
 
146
146
  end
147
147
 
148
+ context 'no default file and inside a capture block' do
149
+ let(:source) { "{% capture url %}{% editable_file banner, hint: 'some text' %}{% endeditable_file %}{% endcapture %}->{{ url }}" }
150
+ let(:element) { instance_double('EditableFile', id: 42, default_source_url: nil, source?: true, source: '/foo/bar', content: nil, base_url: '') }
151
+ it { is_expected.to eq '->/foo/bar?1183150800' }
152
+ end
153
+
148
154
  end
149
155
 
150
156
  end
@@ -62,6 +62,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Text do
62
62
  it { is_expected.to include(format: 'html') }
63
63
  it { is_expected.to include(rows: 10) }
64
64
  it { is_expected.to include(line_break: true) }
65
+ it { is_expected.to include(inline: nil) }
65
66
  it { is_expected.to include(content_from_default: 'Hello world') }
66
67
 
67
68
  context 'with a defined slug' do
@@ -90,6 +90,11 @@ describe Locomotive::Steam::Middlewares::LocaleRedirection do
90
90
  it { is_expected.to eq [301, '/mounted-on/somewhere/de/hello/world'] }
91
91
  end
92
92
 
93
+ describe 'requesting sitemap.xml' do
94
+ let(:url) { 'http://models.example.com/sitemap.xml' }
95
+ it { is_expected.to eq [200, nil] }
96
+ end
97
+
93
98
  end
94
99
 
95
100
  describe 'with locale' do
@@ -123,65 +123,91 @@ describe Locomotive::Steam::ContentEntryRepository do
123
123
 
124
124
  end
125
125
 
126
- describe '#next' do
126
+ describe '#next or #previous' do
127
127
 
128
- let(:type) { build_content_type('Articles', order_by: { _position: 'asc' }, label_field_name: :title, localized_names: [:title], fields: _fields, fields_by_name: { title: instance_double('Field', name: :title, type: :string) }, fields_with_default: []) }
128
+ let(:direction) { 'asc' }
129
+ let(:type) { build_content_type('Articles', order_by: { _position: direction }, label_field_name: :title, localized_names: [:title], fields: _fields, fields_by_name: { title: instance_double('Field', name: :title, type: :string) }, fields_with_default: []) }
130
+ let(:entry) { nil }
129
131
  let(:entries) do
130
132
  [
131
133
  { content_type_id: 1, _position: 0, _label: 'Update #1', title: { fr: 'Mise a jour #1' }, text: { en: 'added some free stuff', fr: 'phrase FR' }, date: '2009/05/12', category: 'General' },
132
134
  { content_type_id: 1, _position: 1, _label: 'Update #2', title: { fr: 'Mise a jour #2' }, text: { en: 'bla bla', fr: 'blabbla' }, date: '2009/05/12', category: 'General' },
133
- { content_type_id: 1, _position: 2, _label: 'Update #3', title: { fr: 'Mise a jour #2' }, text: { en: 'bla bla', fr: 'blabbla' }, date: '2009/05/12', category: 'General' }
135
+ { content_type_id: 1, _position: 2, _label: 'Update #3', title: { fr: 'Mise a jour #3' }, text: { en: 'bla bla', fr: 'blabbla' }, date: '2009/05/12', category: 'General' },
136
+ { content_type_id: 1, _position: 3, _label: 'Update #4', title: { fr: 'Mise a jour #4' }, text: { en: 'bla bla', fr: 'blabbla' }, date: '2009/05/12', category: 'General' }
134
137
  ]
135
138
  end
136
139
 
137
- let(:entry) { nil }
138
- subject { repository.next(entry) }
140
+ describe '#next' do
139
141
 
140
- it { is_expected.to eq nil }
141
-
142
- context 'being last' do
142
+ subject { repository.next(entry) }
143
143
 
144
- let(:entry) { instance_double('Entry', content_type: type, _position: 2) }
145
144
  it { is_expected.to eq nil }
146
145
 
147
- end
146
+ context 'being last' do
148
147
 
149
- context 'being middle' do
148
+ let(:entry) { instance_double('Entry', content_type: type, _position: 3) }
149
+ it { is_expected.to eq nil }
150
150
 
151
- let(:entry) { instance_double('Entry', content_type: type, _position: 1) }
152
- it { expect(subject._position).to eq 2 }
151
+ end
153
152
 
154
- end
153
+ context 'being middle' do
155
154
 
156
- end
155
+ let(:entry) { instance_double('Entry', content_type: type, _position: 0) }
156
+ it { expect(subject._position).to eq 1 }
157
157
 
158
- describe '#previous' do
158
+ describe 'another example' do
159
159
 
160
- let(:type) { build_content_type('Articles', order_by: { _position: 'asc' }, label_field_name: :title, localized_names: [:title], fields: _fields, fields_by_name: { title: instance_double('Field', name: :title, type: :string) }, fields_with_default: []) }
161
- let(:entries) do
162
- [
163
- { content_type_id: 1, _position: 0, _label: 'Update #1', title: { fr: 'Mise a jour #1' }, text: { en: 'added some free stuff', fr: 'phrase FR' }, date: '2009/05/12', category: 'General' },
164
- { content_type_id: 1, _position: 1, _label: 'Update #2', title: { fr: 'Mise a jour #2' }, text: { en: 'bla bla', fr: 'blabbla' }, date: '2009/05/12', category: 'General' },
165
- { content_type_id: 1, _position: 2, _label: 'Update #3', title: { fr: 'Mise a jour #2' }, text: { en: 'bla bla', fr: 'blabbla' }, date: '2009/05/12', category: 'General' }
166
- ]
167
- end
160
+ let(:entry) { instance_double('Entry', content_type: type, _position: 1) }
161
+ it { expect(subject._position).to eq 2 }
168
162
 
169
- let(:entry) { nil }
170
- subject { repository.previous(entry) }
163
+ end
171
164
 
172
- it { is_expected.to eq nil }
165
+ context 'changing direction' do
173
166
 
174
- context 'being first' do
167
+ let(:direction) { 'desc' }
168
+ let(:entry) { instance_double('Entry', content_type: type, _position: 2) }
169
+ it { expect(subject._position).to eq 1 }
175
170
 
176
- let(:entry) { instance_double('Entry', content_type: type, _position: 0) }
177
- it { is_expected.to eq nil }
171
+ end
172
+
173
+ end
178
174
 
179
175
  end
180
176
 
181
- context 'being middle' do
177
+ describe '#previous' do
182
178
 
183
- let(:entry) { instance_double('Entry', content_type: type, _position: 1) }
184
- it { expect(subject._position).to eq 0 }
179
+ subject { repository.previous(entry) }
180
+
181
+ it { is_expected.to eq nil }
182
+
183
+ context 'being first' do
184
+
185
+ let(:entry) { instance_double('Entry', content_type: type, _position: 0) }
186
+ it { is_expected.to eq nil }
187
+
188
+ end
189
+
190
+ context 'being middle' do
191
+
192
+ let(:entry) { instance_double('Entry', content_type: type, _position: 1) }
193
+ it { expect(subject._position).to eq 0 }
194
+
195
+ describe 'another example' do
196
+
197
+ let(:entry) { instance_double('Entry', content_type: type, _position: 2) }
198
+ it { expect(subject._position).to eq 1 }
199
+
200
+ end
201
+
202
+ context 'changing direction' do
203
+
204
+ let(:direction) { 'desc' }
205
+ let(:entry) { instance_double('Entry', content_type: type, _position: 2) }
206
+ it { expect(subject._position).to eq 3 }
207
+
208
+ end
209
+
210
+ end
185
211
 
186
212
  end
187
213
 
@@ -55,6 +55,18 @@ describe Locomotive::Steam::ContentTypeFieldRepository do
55
55
  subject { repository.default }
56
56
 
57
57
  it { expect(subject.first.name).to eq 'email' }
58
+ it { expect(subject.count).to eq 1 }
59
+
60
+ end
61
+
62
+ describe '#files' do
63
+
64
+ let(:collection) { [{ name: 'name', type: 'string' }, { name: 'picture', type: 'file' }] }
65
+
66
+ subject { repository.files }
67
+
68
+ it { expect(subject.first.name).to eq 'picture' }
69
+ it { expect(subject.count).to eq 1 }
58
70
 
59
71
  end
60
72
 
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.1
4
+ version: 1.1.0.rc1
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: 2016-02-16 00:00:00.000000000 Z
14
+ date: 2016-03-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -47,14 +47,14 @@ dependencies:
47
47
  requirements:
48
48
  - - "~>"
49
49
  - !ruby/object:Gem::Version
50
- version: 2.2.1
50
+ version: 2.2.3
51
51
  type: :development
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: 2.2.1
57
+ version: 2.2.3
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: origin
60
60
  requirement: !ruby/object:Gem::Requirement
@@ -159,14 +159,14 @@ dependencies:
159
159
  requirements:
160
160
  - - "~>"
161
161
  - !ruby/object:Gem::Version
162
- version: '1.2'
162
+ version: 1.6.1
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.2'
169
+ version: 1.6.1
170
170
  - !ruby/object:Gem::Dependency
171
171
  name: dragonfly
172
172
  requirement: !ruby/object:Gem::Requirement
@@ -271,28 +271,28 @@ dependencies:
271
271
  requirements:
272
272
  - - "~>"
273
273
  - !ruby/object:Gem::Version
274
- version: 6.2.3
274
+ version: 6.3.3.1
275
275
  type: :runtime
276
276
  prerelease: false
277
277
  version_requirements: !ruby/object:Gem::Requirement
278
278
  requirements:
279
279
  - - "~>"
280
280
  - !ruby/object:Gem::Version
281
- version: 6.2.3
281
+ version: 6.3.3.1
282
282
  - !ruby/object:Gem::Dependency
283
283
  name: kramdown
284
284
  requirement: !ruby/object:Gem::Requirement
285
285
  requirements:
286
286
  - - "~>"
287
287
  - !ruby/object:Gem::Version
288
- version: 1.9.0
288
+ version: 1.10.0
289
289
  type: :runtime
290
290
  prerelease: false
291
291
  version_requirements: !ruby/object:Gem::Requirement
292
292
  requirements:
293
293
  - - "~>"
294
294
  - !ruby/object:Gem::Version
295
- version: 1.9.0
295
+ version: 1.10.0
296
296
  - !ruby/object:Gem::Dependency
297
297
  name: RedCloth
298
298
  requirement: !ruby/object:Gem::Requirement
@@ -369,14 +369,14 @@ dependencies:
369
369
  requirements:
370
370
  - - "~>"
371
371
  - !ruby/object:Gem::Version
372
- version: 0.0.5
372
+ version: 0.1.0
373
373
  type: :runtime
374
374
  prerelease: false
375
375
  version_requirements: !ruby/object:Gem::Requirement
376
376
  requirements:
377
377
  - - "~>"
378
378
  - !ruby/object:Gem::Version
379
- version: 0.0.5
379
+ version: 0.1.0
380
380
  description: The LocomotiveCMS Steam is the rendering stack used by both Wagon and
381
381
  Engine
382
382
  email:
@@ -466,7 +466,7 @@ files:
466
466
  - lib/locomotive/steam/liquid/drops/page.rb
467
467
  - lib/locomotive/steam/liquid/drops/session_proxy.rb
468
468
  - lib/locomotive/steam/liquid/drops/site.rb
469
- - lib/locomotive/steam/liquid/drops/upload_file.rb
469
+ - lib/locomotive/steam/liquid/drops/uploaded_file.rb
470
470
  - lib/locomotive/steam/liquid/errors.rb
471
471
  - lib/locomotive/steam/liquid/filters/base.rb
472
472
  - lib/locomotive/steam/liquid/filters/date.rb
@@ -816,9 +816,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
816
816
  version: '2.0'
817
817
  required_rubygems_version: !ruby/object:Gem::Requirement
818
818
  requirements:
819
- - - ">="
819
+ - - ">"
820
820
  - !ruby/object:Gem::Version
821
- version: '0'
821
+ version: 1.3.1
822
822
  requirements: []
823
823
  rubyforge_project:
824
824
  rubygems_version: 2.4.5.1