locomotivecms_steam 1.3.0.rc1 → 1.3.0.rc2

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: 2f196a0b63817aacbd1564c4f1e48f11f3d9a099
4
- data.tar.gz: f2abdbd4a45e167bec4ec66ed0e4fe8ecb51f41a
3
+ metadata.gz: 1535dbba02a328de41369d5887f7ea9971b76127
4
+ data.tar.gz: 3e039bd983df5359ddf2d9a65fb0f548a50448ed
5
5
  SHA512:
6
- metadata.gz: 70e71b96955c2395129bfb9c42b83a581592a7c55ec814b682b3f3919a2b55d63c87a42fe5fc671600ff4674202c19d6c2e462d9581fd2341f820fbe2d3027c8
7
- data.tar.gz: efc45f6d8acb3117e4b9154830b1b43fbeb299358c60e57d606692b0eb3a86fe0ea4ac05d095f080331bcb0ea6358a9d8f23cbed96311bac21239f4de40a4c39
6
+ metadata.gz: c09afe41b49e1426bc7ff4793a9ddc56e6e2888a134afaf0ce7117380da4bcee13c54247b6f7d7d549ea8e642b36a5d0f55593b8f63ead2dfa57860c838be8be
7
+ data.tar.gz: eb77af54a2142c206e9c0b0a5a52a3a641e49752b60e165cc166e2ee84232f26822de94db329cfaadc00cec4ff3bfe233c5cd5b03188d5abba26dc76bd2dede3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_steam (1.3.0.rc1)
4
+ locomotivecms_steam (1.3.0.rc2)
5
5
  RedCloth (~> 4.3.2)
6
6
  autoprefixer-rails (~> 6.7.2)
7
7
  bcrypt (~> 3.1.11)
@@ -37,10 +37,10 @@ GEM
37
37
  minitest (~> 5.1)
38
38
  thread_safe (~> 0.3, >= 0.3.4)
39
39
  tzinfo (~> 1.1)
40
- addressable (2.5.0)
40
+ addressable (2.5.1)
41
41
  public_suffix (~> 2.0, >= 2.0.2)
42
42
  attr_extras (4.4.0)
43
- autoprefixer-rails (6.7.6)
43
+ autoprefixer-rails (6.7.7.2)
44
44
  execjs
45
45
  bcrypt (3.1.11)
46
46
  bson (4.2.1)
@@ -107,7 +107,7 @@ GEM
107
107
  attr_extras (~> 4.4.0)
108
108
  colorize
109
109
  stringex (~> 2.6.0)
110
- mail (2.6.4)
110
+ mail (2.6.5)
111
111
  mime-types (>= 1.16, < 4)
112
112
  memory_profiler (0.9.7)
113
113
  method_source (0.8.2)
@@ -116,7 +116,7 @@ GEM
116
116
  mime-types-data (3.2016.0521)
117
117
  mimetype-fu (0.1.2)
118
118
  mini_portile2 (2.1.0)
119
- minitest (5.10.1)
119
+ minitest (5.10.2)
120
120
  moneta (1.0.0)
121
121
  mongo (2.4.1)
122
122
  bson (>= 4.2.1, < 5.0.0)
@@ -125,7 +125,7 @@ GEM
125
125
  multi_xml (0.6.0)
126
126
  nokogiri (1.7.0.1)
127
127
  mini_portile2 (~> 2.1.0)
128
- nokogumbo (1.4.10)
128
+ nokogumbo (1.4.12)
129
129
  nokogiri
130
130
  origin (2.3.0)
131
131
  pony (1.11)
@@ -170,7 +170,7 @@ GEM
170
170
  crass (~> 1.0.2)
171
171
  nokogiri (>= 1.4.4)
172
172
  nokogumbo (~> 1.4.1)
173
- sass (3.4.23)
173
+ sass (3.4.24)
174
174
  simplecov (0.12.0)
175
175
  docile (~> 1.1.0)
176
176
  json (>= 1.8, < 3)
@@ -189,9 +189,9 @@ GEM
189
189
  tilt (2.0.6)
190
190
  timecop (0.8.1)
191
191
  tins (1.13.2)
192
- tzinfo (1.2.2)
192
+ tzinfo (1.2.3)
193
193
  thread_safe (~> 0.1)
194
- uglifier (3.1.6)
194
+ uglifier (3.1.13)
195
195
  execjs (>= 0.3.0, < 3)
196
196
 
197
197
  PLATFORMS
@@ -80,7 +80,12 @@ module Locomotive::Steam
80
80
  hash = {}
81
81
 
82
82
  # default attributes
83
- _attributes = %i(_id _slug _label _visible _position content_type_slug created_at updated_at)
83
+ _attributes = %i(_id _slug _visible _position content_type_slug created_at updated_at)
84
+
85
+ # stack level too deep raised if the _label field is an association (belongs_to, ...etc)
86
+ unless content_type.fields_by_name[content_type.label_field_name].is_relationship?
87
+ _attributes << :_label
88
+ end
84
89
 
85
90
  # dynamic attributes
86
91
  _attributes += content_type.persisted_field_names
@@ -33,6 +33,7 @@ module Locomotive::Steam
33
33
  def listed?; !!listed; end
34
34
  def published?; !!published; end
35
35
  def templatized?; !!templatized; end
36
+ def redirect?; redirect.nil? ? !redirect_url.blank? : redirect; end
36
37
 
37
38
  def content_type_id
38
39
  self.target_klass_name =~ Locomotive::Steam::CONTENT_ENTRY_ENGINE_CLASS_NAME
@@ -55,7 +55,28 @@ module Locomotive
55
55
  def apply_transformation(url, context)
56
56
  # resize image with the image_resizer service?
57
57
  if (format = @element_options[:resize]).present?
58
- url = context.registers[:services].image_resizer.resize(url, format) || url
58
+ options = []
59
+
60
+ @element_options.each do |k, v|
61
+ options << case k.to_sym
62
+ when :quality
63
+ "-quality #{v}"
64
+ when :optimize # Shortcut helper to set quality, progressive and strip
65
+ "-quality #{v} -strip -interlace Plane"
66
+ when :auto_orient
67
+ "-auto-orient" if v.downcase == "true"
68
+ when :strip
69
+ "-strip" if v.downcase == "true"
70
+ when :progressive
71
+ "-interlace Plane" if v.downcase == "true"
72
+ when :filters
73
+ v
74
+ else
75
+ next
76
+ end
77
+ end
78
+
79
+ url = context.registers[:services].image_resizer.resize(url, format, options.join(' ')) || url
59
80
  end
60
81
 
61
82
  # in the live editing mode, tag all the images with their editable path (block + slug)
@@ -28,7 +28,7 @@ module Locomotive::Steam
28
28
 
29
29
  def build_pages_to_xml
30
30
  page_repository.published.map do |page|
31
- next if page.index? || page.not_found? || page.layout? || (!page.templatized? && !page.listed?)
31
+ next if skip_page?(page)
32
32
 
33
33
  build_page_xml(page)
34
34
  end.flatten.join.strip
@@ -80,6 +80,14 @@ module Locomotive::Steam
80
80
  EOF
81
81
  end
82
82
 
83
+ def skip_page?(page)
84
+ page.index? ||
85
+ page.not_found? ||
86
+ page.layout? ||
87
+ page.redirect? ||
88
+ (!page.templatized? && !page.listed?)
89
+ end
90
+
83
91
  def repositories
84
92
  services.repositories
85
93
  end
@@ -35,7 +35,29 @@ module Locomotive::Steam
35
35
  def redirect_url
36
36
  return false if site.url_redirections.nil? || site.url_redirections.size == 0
37
37
 
38
- site.url_redirections.to_h[requested_url]
38
+ redirections_hash = site.url_redirections.to_h
39
+
40
+ redirections_hash[requested_url] || find_dynamic_url_redirection(redirections_hash)
41
+ end
42
+
43
+ def find_dynamic_url_redirection(redirections_hash)
44
+ number_of_segments = requested_url.split('/').size
45
+
46
+ # attempt to find the first dynamic route which matches
47
+ redirections_hash.each do |route, redirection|
48
+ # a little bit of optimization
49
+ next unless route.include?(':') && route.split('/').size == number_of_segments
50
+
51
+ _regexp = route.gsub(/:([^\/]+)/, "(?<\\1>[^\/]+)").gsub('/', '\/')
52
+
53
+ if matches = Regexp.new(_regexp).match(requested_url)
54
+ matches.names.each { |n| redirection.gsub!(":#{n}", matches[n]) }
55
+
56
+ return redirection
57
+ end
58
+ end
59
+
60
+ false
39
61
  end
40
62
 
41
63
  end
@@ -40,7 +40,8 @@ module Locomotive::Steam
40
40
  end
41
41
 
42
42
  def blank?
43
- @translations.blank? && @translations[:anything].blank?
43
+ @translations.blank? ||
44
+ @translations.values.all? { |v| v.blank? }
44
45
  end
45
46
 
46
47
  def apply(&block)
@@ -26,25 +26,25 @@ module Locomotive
26
26
 
27
27
  def fetch_file(source)
28
28
  return nil if source.blank?
29
-
30
29
  url_or_path = get_url_or_path(source)
31
30
 
32
31
  if url_or_path =~ Steam::IsHTTP
33
32
  resizer.fetch_url(url_or_path)
34
- else
33
+ elsif url_or_path
35
34
  path = url_or_path.sub(/(\?.*)$/, '')
36
35
  resizer.fetch_file(File.join(asset_path || '', path))
37
36
  end
38
37
  end
39
38
 
40
39
  def get_url_or_path(source)
41
- if source.is_a?(Hash)
40
+ value = if source.is_a?(Hash)
42
41
  source['url']
43
42
  elsif source.respond_to?(:url)
44
43
  source.url
45
44
  else
46
45
  source
47
- end.strip
46
+ end
47
+ value.strip if value
48
48
  end
49
49
 
50
50
  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.3.0.rc1'
6
+ VERSION = '1.3.0.rc2'
7
7
  end
8
8
  end
@@ -21,7 +21,7 @@ describe Locomotive::Steam::Server do
21
21
 
22
22
  it 'checks if it looks valid' do
23
23
  expect(Nokogiri::XML(subject).errors.empty?).to eq true
24
- expect(subject.scan(/<url>/).size).to eq 27
24
+ expect(subject.scan(/<url>/).size).to eq 25
25
25
  expect(subject).to match("<loc>http://example.org/songs/song-number-2/band</loc>")
26
26
  expect(subject).to match((<<-EOF
27
27
  <url>
@@ -72,7 +72,7 @@ describe Locomotive::Steam::ContentEntry do
72
72
 
73
73
  describe '#to_hash' do
74
74
 
75
- let(:fields) { [instance_double('TitleField', name: :title, type: :string), instance_double('PictureField', name: :picture, type: :file, localized: true)] }
75
+ let(:fields) { [instance_double('TitleField', name: :title, type: :string, is_relationship?: false), instance_double('PictureField', name: :picture, type: :file, localized: true)] }
76
76
  let(:attributes) { { id: 42, title: 'Hello world', _slug: 'hello-world', picture: Locomotive::Steam::Models::I18nField.new(:picture, fr: 'foo.png', en: 'bar.png'), custom_fields_recipe: ['hello', 'world'], _type: 'Entry' } }
77
77
 
78
78
  subject { content_entry.to_hash }
@@ -101,7 +101,7 @@ describe Locomotive::Steam::ContentEntry do
101
101
 
102
102
  describe '#as_json' do
103
103
 
104
- let(:fields) { [instance_double('TitleField', name: :title, type: :string), instance_double('PictureField', name: :picture, type: :file, localized: true)] }
104
+ let(:fields) { [instance_double('TitleField', name: :title, type: :string, is_relationship?: false), instance_double('PictureField', name: :picture, type: :file, localized: true)] }
105
105
  let(:attributes) { { id: 42, title: 'Hello world', _slug: 'hello-world', picture: Locomotive::Steam::Models::I18nField.new(:picture, fr: 'foo.png', en: 'bar.png'), custom_fields_recipe: ['hello', 'world'], _type: 'Entry' } }
106
106
  let(:decorated) { Locomotive::Steam::Decorators::I18nDecorator.new(content_entry, :fr, :en) }
107
107
 
@@ -82,4 +82,28 @@ describe Locomotive::Steam::Page do
82
82
 
83
83
  end
84
84
 
85
+ describe '#redirect?' do
86
+
87
+ subject { page.redirect? }
88
+
89
+ it { is_expected.to eq false }
90
+
91
+ context 'redirect_url has been set' do
92
+
93
+ let(:attributes) { { redirect: nil, redirect_url: 'http://www.google.fr' } }
94
+
95
+ it { is_expected.to eq true }
96
+
97
+ context 'but redirect is set to false' do
98
+
99
+ let(:attributes) { { redirect: false, redirect_url: 'http://www.google.fr' } }
100
+
101
+ it { is_expected.to eq false }
102
+
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+
85
109
  end
@@ -75,6 +75,8 @@ describe Locomotive::Steam::Liquid::Tags::Editable::File do
75
75
  let(:services) { Locomotive::Steam::Services.build_instance }
76
76
  let(:context) { ::Liquid::Context.new({}, {}, { page: page, services: services, live_editing: live_editing }) }
77
77
 
78
+ before { @context = context }
79
+
78
80
  before { allow(services).to receive(:current_site).and_return(nil) }
79
81
 
80
82
  before { allow(services.editable_element).to receive(:find).and_return(element) }
@@ -142,6 +144,62 @@ describe Locomotive::Steam::Liquid::Tags::Editable::File do
142
144
  it { is_expected.to eq '<span class="locomotive-block-anchor" data-element-id="header" style="visibility: hidden"></span>/steam/dynamic/W1siZnUiLCJodHRwOi8vd3d3LnBsYWNlaG9sZC5pdC81MDB4NTAwIl0sWyJwIiwidGh1bWIiLCI1MDB4MTAwIyJdXQ/1c79f4581f33aae4/500x500?editable-path=header--banner' }
143
145
 
144
146
  end
147
+ end
148
+
149
+ context 'additional image filters' do
150
+ let(:geometry) { '30x40#' }
151
+ let(:input) { 'http://www.placehold.it/500x500' }
152
+ let(:source) { "{%% block header %%}{%% editable_file banner, hint: 'some text', resize: '#{geometry}', %{filter} %%}#{input}{%% endeditable_file %%}{%% endblock %%}" }
153
+
154
+ before do
155
+ @context.registers[:services].image_resizer = instance_spy('ImageResizerService')
156
+ @image_resizer = @context.registers[:services].image_resizer
157
+ end
158
+
159
+ it 'handles quality' do
160
+ render_template(source % {filter: "quality: 70"}, context, options)
161
+ expect(@image_resizer).to have_received(:resize).with(input, geometry, '-quality 70')
162
+ end
163
+
164
+ it 'handles auto_orient' do
165
+ render_template(source % {filter: "auto_orient: true"}, context, options)
166
+ expect(@image_resizer).to have_received(:resize).with(input, geometry, '-auto-orient')
167
+ end
168
+
169
+ it "doesn't auto_orient if false" do
170
+ render_template(source % {filter: "auto_orient: false"}, context, options)
171
+ expect(@image_resizer).to have_received(:resize).with(input, geometry, '')
172
+ end
173
+
174
+ it 'handles optimize' do
175
+ render_template(source % {filter: "optimize: 75"}, context, options)
176
+ expect(@image_resizer).to have_received(:resize).with(input, geometry, '-quality 75 -strip -interlace Plane')
177
+ end
178
+
179
+ it 'handles multiple and custom filters' do
180
+ render_template(source % {filter: "quality: 60, filters: '-sepia-tone 80%'"}, context, options)
181
+ expect(@image_resizer).to have_received(:resize).with(input, geometry, '-quality 60 -sepia-tone 80%')
182
+ end
183
+
184
+ it 'handles progressive display' do
185
+ render_template(source % {filter: "progressive: true"}, context, options)
186
+ expect(@image_resizer).to have_received(:resize).with(input, geometry, '-interlace Plane')
187
+ end
188
+
189
+ it 'doesn\'t progressive display if false' do
190
+ render_template(source % {filter: "progressive: false"}, context, options)
191
+ expect(@image_resizer).to have_received(:resize).with(input, geometry, '')
192
+ end
193
+
194
+ it 'handles strip' do
195
+ render_template(source % {filter: "strip: true"}, context, options)
196
+ expect(@image_resizer).to have_received(:resize).with(input, geometry, '-strip')
197
+ end
198
+
199
+ it 'doesn\'t strip if false' do
200
+ render_template(source % {filter: "strip: false"}, context, options)
201
+ expect(@image_resizer).to have_received(:resize).with(input, geometry, '')
202
+ end
145
203
 
146
204
  end
147
205
 
@@ -54,6 +54,15 @@ describe Locomotive::Steam::Middlewares::UrlRedirection do
54
54
 
55
55
  end
56
56
 
57
+ describe 'url matching a pattern' do
58
+
59
+ let(:redirections) { [['/old_images/:file', '/images/old/:file']] }
60
+ let(:url) { 'http://models.example.com/old_images/cat.png' }
61
+
62
+ it { is_expected.to eq [301, '/images/old/cat.png'] }
63
+
64
+ end
65
+
57
66
  describe 'let the parent app know about the redirection when it happens' do
58
67
 
59
68
  let(:events) { [] }
@@ -68,6 +68,25 @@ describe Locomotive::Steam::ImageResizerService do
68
68
 
69
69
  end
70
70
 
71
+ describe 'nil file' do
72
+ let(:geometry) { '' }
73
+ let(:input) { nil }
74
+
75
+ it { is_expected.to eq nil }
76
+ end
77
+
78
+ describe 'nil hash file' do
79
+ let(:input) { { 'url' => nil } }
80
+
81
+ it { is_expected.to eq nil }
82
+ end
83
+
84
+ describe 'nil object file' do
85
+ let(:input) { instance_double('UploadedFile', url: nil) }
86
+
87
+ it { is_expected.to eq nil }
88
+ end
89
+
71
90
  describe 'additional filters' do
72
91
  let(:input) { '/sites/42/theme/images/banner.png' }
73
92
  let (:filters) { [{"quality" => 70, "auto_orient" => true, "filters" => "-swirl 180"}] }
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.3.0.rc1
4
+ version: 1.3.0.rc2
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: 2017-03-10 00:00:00.000000000 Z
14
+ date: 2017-06-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler