locomotivecms_steam 1.1.0.rc3 → 1.1.0

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: 42c767e4b89256e979cc9e73a2851227052b8478
4
- data.tar.gz: 45d39c6d1b6ee403c4797f2793eeecbe03e56d2f
3
+ metadata.gz: 986fc20a458de01b66d78eddb74cf2cda26733aa
4
+ data.tar.gz: 0634c879f6b9763beef950cba0012d59db71714c
5
5
  SHA512:
6
- metadata.gz: cf631f30710f478aa18d766fb9b302fbea3a671ca4cc8b0c02ade4d6e3df11ffe162d779d06a0fac40df2348be9313fca2ef0d258dece9ad4e2666673415f782
7
- data.tar.gz: aa70b068ba7218dbd9f29fe765860fb03b3eb3c72ef96956c48c9cb6596d0aaa896b700c1b111950cdb6dfa5ab1d4f1432b734e48aee3215693c00ede75231e9
6
+ metadata.gz: 4e25cc1a48fa40ec0308d1ea7f4537020eccda5acf8604ccd55e939d50c0f227f83e0bfa1ae7128342004385b038ab19269452c00b4e5a4a54098aa39b11300e
7
+ data.tar.gz: ead24822aea6ae6b4b08bb9a644627bab606032ee3a7b7593bea68cbd7a66367ad2e295b16fc7047944d776f0af80bf65b71a021cb3b02803a09531900be7418
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_steam (1.1.0.rc3)
4
+ locomotivecms_steam (1.1.0)
5
5
  RedCloth (~> 4.2.9)
6
6
  autoprefixer-rails (~> 6.3.3.1)
7
7
  chronic (~> 0.10.2)
@@ -175,7 +175,7 @@ GEM
175
175
  crass (~> 1.0.2)
176
176
  nokogiri (>= 1.4.4)
177
177
  nokogumbo (~> 1.4.1)
178
- sass (3.4.21)
178
+ sass (3.4.22)
179
179
  simplecov (0.11.1)
180
180
  docile (~> 1.1.0)
181
181
  json (~> 1.8)
data/README.md CHANGED
@@ -20,6 +20,8 @@ The rendering stack used by both Wagon and Engine (WIP). It includes:
20
20
 
21
21
  ### Command line:
22
22
 
23
+ *Warning*: For now, Steam is not aimed to be run standalone. The following is just a proof of concept.
24
+
23
25
  Display all the options:
24
26
 
25
27
  steam --help
@@ -36,9 +38,14 @@ Once launched, open your browser
36
38
 
37
39
  open localhost:8080
38
40
 
39
- ### Inside a Rails application:
41
+ ### Inside Engine / Wagon:
42
+
43
+ [https://github.com/locomotivecms/engine/blob/master/lib/locomotive/steam_adaptor.rb](https://github.com/locomotivecms/engine/blob/master/lib/locomotive/steam_adaptor.rb)
44
+ [https://github.com/locomotivecms/engine/blob/master/spec/dummy/config/routes.rb](https://github.com/locomotivecms/engine/blob/master/spec/dummy/config/routes.rb#L12)
45
+
40
46
 
41
- [TODO]
47
+ [https://github.com/locomotivecms/wagon/blob/master/lib/locomotive/wagon/commands/serve_command.rb](https://github.com/locomotivecms/wagon/blob/master/lib/locomotive/wagon/commands/serve_command.rb#L65)
48
+ [https://github.com/locomotivecms/wagon/blob/master/lib/locomotive/wagon/commands/serve_command.rb](https://github.com/locomotivecms/wagon/blob/master/lib/locomotive/wagon/commands/serve_command.rb#L138)
42
49
 
43
50
  ## TODO
44
51
 
@@ -54,4 +61,4 @@ see the list in the issues section.
54
61
 
55
62
  ## License
56
63
 
57
- Copyright (c) 2015 NoCoffee. MIT Licensed, see LICENSE for details.
64
+ Copyright (c) 2016 NoCoffee. MIT Licensed, see LICENSE for details.
@@ -70,13 +70,15 @@ module Locomotive::Steam
70
70
  end
71
71
 
72
72
  def set_slug(entity, dataset)
73
- if entity._label.respond_to?(:translations) # localized?
74
- entity._label.each do |locale, label|
75
- entity[:_slug][locale] ||= slugify(entity._id, label, dataset, locale)
73
+ if entity._slug.blank?
74
+ if entity._label.respond_to?(:translations)
75
+ entity._label.each do |locale, label|
76
+ entity[:_slug][locale] = slugify(entity._id, label, dataset, locale)
77
+ end
78
+ else
79
+ # same value for any locale
80
+ entity[:_slug].translations = slugify(entity._id, entity._label, dataset)
76
81
  end
77
- elsif entity[:_slug] && entity[:_slug][:anylocale].nil?
78
- # Note: replace the translations of the I18nField by a string
79
- entity[:_slug].translations = slugify(entity._id, entity._label, dataset)
80
82
  end
81
83
  end
82
84
 
@@ -26,7 +26,8 @@ module Locomotive::Steam
26
26
 
27
27
  def order_by
28
28
  if (order_by = self[:order_by]).present?
29
- name, direction = order_by.split
29
+ # from Filesystem -> string, from MongoDB -> array (string transformed by Engine)
30
+ name, direction = order_by.respond_to?(:each) ? order_by : order_by.split
30
31
  { name.to_sym => direction || 'asc' }
31
32
  else
32
33
  type == :has_many ? { :"position_in_#{self[:inverse_of]}" => 'asc' } : nil
@@ -3,9 +3,66 @@ require 'sass'
3
3
  require 'coffee_script'
4
4
  require 'compass'
5
5
  require 'autoprefixer-rails'
6
+ require 'open3'
6
7
 
7
8
  module Locomotive::Steam
8
9
 
10
+ class YUICompressorRuntimeError < RuntimeError
11
+ attr_reader :errors
12
+ #:nocov:
13
+ def initialize(msg, errors)
14
+ super(msg)
15
+ @errors = errors
16
+ end
17
+ end
18
+
19
+ module YUICompressorErrors
20
+
21
+ #:nocov:
22
+ def compress(stream_or_string)
23
+ streamify(stream_or_string) do |stream|
24
+ tempfile = new_tempfile(stream)
25
+ full_command = "%s %s" % [command, tempfile.path]
26
+
27
+ output, errors, exit_status = _compress(full_command, tempfile)
28
+
29
+ if exit_status.exitstatus.zero?
30
+ output
31
+ else
32
+ # Bourne shells tend to blow up here when the command fails, usually
33
+ # because java is missing
34
+ raise YUICompressorRuntimeError.new("Command '%s' returned non-zero exit status" %
35
+ full_command, errors)
36
+ end
37
+ end
38
+ end
39
+
40
+ #:nocov:
41
+ def _compress(command, tempfile)
42
+ begin
43
+ # FIXME: catch only useful information from the stderr output
44
+ # output, errors, exit_status = '', [], nil
45
+ output, errors, exit_status = Open3.capture3(command)
46
+ errors = errors.split("\n").find_all { |l| l =~ /\s+[0-9]/ }
47
+ [output, errors, exit_status]
48
+ rescue Exception => e
49
+ # windows shells tend to blow up here when the command fails
50
+ raise RuntimeError, "compression failed: %s" % e.message
51
+ ensure
52
+ tempfile.close!
53
+ end
54
+ end
55
+
56
+ #:nocov:
57
+ def new_tempfile(stream)
58
+ Tempfile.new('yui_compress').tap do |tempfile|
59
+ tempfile.write stream.read
60
+ tempfile.flush
61
+ end
62
+ end
63
+
64
+ end
65
+
9
66
  class SprocketsEnvironment < ::Sprockets::Environment
10
67
 
11
68
  def initialize(root, options = {})
@@ -33,9 +90,13 @@ module Locomotive::Steam
33
90
  def install_yui_compressor(options)
34
91
  return unless options[:minify]
35
92
 
36
- require 'yui/compressor'
37
-
38
93
  if is_java_installed?
94
+ require 'yui/compressor'
95
+
96
+ [YUI::JavaScriptCompressor, YUI::CssCompressor].each do |klass|
97
+ klass.send(:include, YUICompressorErrors)
98
+ end
99
+
39
100
  # minify javascripts and stylesheets
40
101
  self.js_compressor = YUI::JavaScriptCompressor.new
41
102
  self.css_compressor = YUI::CssCompressor.new
@@ -74,7 +74,7 @@ module Locomotive
74
74
  def _retrieve_templatized_page_drop_from(drop)
75
75
  entry = drop.send(:_source)
76
76
 
77
- if page = repository.template_for(entry, @path_options[:with])
77
+ if page = repository.template_for(entry, template_slug)
78
78
  page.to_liquid.tap { |d| d.context = @context }
79
79
  end
80
80
  end
@@ -84,7 +84,11 @@ module Locomotive
84
84
  end
85
85
 
86
86
  def locale
87
- @path_options[:locale] || @locale
87
+ @path_options[:locale] || @raw_locale || @locale
88
+ end
89
+
90
+ def template_slug
91
+ @path_options[:with] || @raw_with
88
92
  end
89
93
 
90
94
  def set_vars_from_context(context)
@@ -101,7 +105,9 @@ module Locomotive
101
105
  def make_options_compatible_with_previous_version(options)
102
106
  if options
103
107
  %w(with locale).each do |name|
104
- options.gsub!(/#{name}: ([\w-]+)/, name + ': "\1"')
108
+ if options =~ /#{name}: ([\w-]+)/
109
+ instance_variable_set(:"@raw_#{name}", $1);
110
+ end
105
111
  end
106
112
  end
107
113
  end
@@ -35,6 +35,9 @@ module Locomotive::Steam
35
35
 
36
36
  def fetch_content_entry(slug)
37
37
  if type = content_type_repository.find(page.content_type_id)
38
+ # don't accept a non localized entry in a locale other than the default one
39
+ return nil if type.localized_names.count == 0 && locale.to_s != default_locale.to_s
40
+
38
41
  decorate(content_entry_repository.with(type).by_slug(slug))
39
42
  else
40
43
  nil
@@ -5,7 +5,7 @@ module Locomotive::Steam
5
5
 
6
6
  extend Forwardable
7
7
 
8
- def_delegators :@translations, :values, :blank?, :default
8
+ def_delegators :@translations, :values, :default
9
9
 
10
10
  attr_reader :name, :translations
11
11
 
@@ -39,6 +39,10 @@ module Locomotive::Steam
39
39
  @translations.each(&block)
40
40
  end
41
41
 
42
+ def blank?
43
+ @translations.blank? && @translations[:anything].blank?
44
+ end
45
+
42
46
  def apply(&block)
43
47
  if default
44
48
  @translations = Hash.new(yield(default))
@@ -32,7 +32,7 @@ module Locomotive::Steam
32
32
  if configuration.serve_assets
33
33
  use ::Rack::Static, {
34
34
  root: configuration.asset_path,
35
- urls: ['/images', '/fonts', '/samples', '/media', '/sites']
35
+ urls: ['/images', '/fonts', '/samples', '/sites']
36
36
  }
37
37
  use Middlewares::DynamicAssets, {
38
38
  root: configuration.asset_path,
@@ -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.1.0.rc3'
6
+ VERSION = '1.1.0'
7
7
  end
8
8
  end
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: Page non trouvée
3
+ ---
4
+ {% extends index %}
5
+
6
+ {% block content %}
7
+
8
+ %p.error Page non trouvée
9
+
10
+ {% endblock %}
@@ -115,6 +115,13 @@ describe Locomotive::Steam::Server do
115
115
  expect(last_response.body).to include 'Leader: Eddie'
116
116
  end
117
117
 
118
+ it 'redirects to the 404 if a locale other than the default one is asked' do
119
+ get '/fr/songs/song-number-2'
120
+ expect(last_response).to be_redirect
121
+ follow_redirect!
122
+ expect(last_response.status).to eq(404)
123
+ end
124
+
118
125
  it 'redirects to the 404 if it does not match a content entry' do
119
126
  get '/songs/unknown'
120
127
  expect(last_response).to be_redirect
@@ -16,7 +16,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Page do
16
16
 
17
17
  it 'tests various stuff' do
18
18
  expect(subject.size).to eq 26
19
- expect(subject.first[:title]).to eq(en: 'Page not found')
19
+ expect(subject.first[:title]).to eq(en: 'Page not found', fr: 'Page non trouvée')
20
20
  expect(subject[15][:is_layout]).to eq true
21
21
  expect(subject[15][:listed]).to eq false
22
22
  expect(subject[15][:published]).to eq false
@@ -68,6 +68,15 @@ describe Locomotive::Steam::Liquid::Tags::PathTo do
68
68
  let(:source) { "{% path_to about_us, locale: 'fr' %}" }
69
69
  it { is_expected.to eq '/fr/a-notre-sujet' }
70
70
 
71
+ context 'locale is a variable' do
72
+
73
+ let(:assigns) { { 'about_us' => drop, 'language' => 'fr' } }
74
+ let(:source) { "{% path_to about_us, locale: language %}" }
75
+
76
+ it { is_expected.to eq '/fr/a-notre-sujet' }
77
+
78
+ end
79
+
71
80
  end
72
81
 
73
82
  end
@@ -82,7 +91,7 @@ describe Locomotive::Steam::Liquid::Tags::PathTo do
82
91
  let(:source) { '{% path_to article %}' }
83
92
 
84
93
  before do
85
- expect(services.repositories.page).to receive(:template_for).with(entry, nil).and_return(page)
94
+ allow(services.repositories.page).to receive(:template_for).with(entry, nil).and_return(page)
86
95
  allow(page).to receive(:to_liquid).and_return(drop)
87
96
  end
88
97
 
@@ -95,6 +104,21 @@ describe Locomotive::Steam::Liquid::Tags::PathTo do
95
104
 
96
105
  end
97
106
 
107
+ context 'and a different template' do
108
+
109
+ let(:archive) { liquid_instance_double('ArticleTemplate', title: 'Template of an article', handle: 'article', localized_attributes: { fullpath: true }, fullpath: { en: 'my-archives/content_type_template', fr: 'mes-archives/content_type_template' }, content_entry: entry_drop.send(:_source), templatized?: true) }
110
+ let(:drop) { Locomotive::Steam::Liquid::Drops::Page.new(archive) }
111
+
112
+ before do
113
+ allow(services.repositories.page).to receive(:template_for).with(entry, 'archives').and_return(archive)
114
+ allow(archive).to receive(:to_liquid).and_return(drop)
115
+ end
116
+
117
+ let(:source) { "{% path_to article, with: archives, locale: fr %}" }
118
+ it { is_expected.to eq '/fr/mes-archives/bonjour-monde' }
119
+
120
+ end
121
+
98
122
  end
99
123
 
100
124
  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.1.0.rc3
4
+ version: 1.1.0
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-03-24 00:00:00.000000000 Z
14
+ date: 2016-04-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -581,6 +581,7 @@ files:
581
581
  - spec/fixtures/default/app/content_types/messages.yml
582
582
  - spec/fixtures/default/app/content_types/songs.yml
583
583
  - spec/fixtures/default/app/content_types/updates.yml
584
+ - spec/fixtures/default/app/views/pages/404.fr.liquid.haml
584
585
  - spec/fixtures/default/app/views/pages/404.liquid.haml
585
586
  - spec/fixtures/default/app/views/pages/about_us.fr.liquid.haml
586
587
  - spec/fixtures/default/app/views/pages/about_us.liquid.haml
@@ -816,9 +817,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
816
817
  version: '2.0'
817
818
  required_rubygems_version: !ruby/object:Gem::Requirement
818
819
  requirements:
819
- - - ">"
820
+ - - ">="
820
821
  - !ruby/object:Gem::Version
821
- version: 1.3.1
822
+ version: '0'
822
823
  requirements: []
823
824
  rubyforge_project:
824
825
  rubygems_version: 2.4.5.1
@@ -832,6 +833,7 @@ test_files:
832
833
  - spec/fixtures/default/app/content_types/messages.yml
833
834
  - spec/fixtures/default/app/content_types/songs.yml
834
835
  - spec/fixtures/default/app/content_types/updates.yml
836
+ - spec/fixtures/default/app/views/pages/404.fr.liquid.haml
835
837
  - spec/fixtures/default/app/views/pages/404.liquid.haml
836
838
  - spec/fixtures/default/app/views/pages/about_us.fr.liquid.haml
837
839
  - spec/fixtures/default/app/views/pages/about_us.liquid.haml