locomotivecms_wagon 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65cdfd7e0302e3c737a42acb94faef8f281161f4
4
- data.tar.gz: 8845d7c25cf6fd0828e814c668fe1814bd17d349
3
+ metadata.gz: c16813277aecf384b3c2a2b8b3eeab3db1da8237
4
+ data.tar.gz: c031bdde8b3277407a0c45e840729e54b2254f9d
5
5
  SHA512:
6
- metadata.gz: 6e7dced59163627556085acc3ed97376d1450fa601cabf5dbf95ad6535e9267642748f00914da20b1a18f8c353fec0d9fa32633eeacc02376649d57e2502908c
7
- data.tar.gz: 29f0d3d74ddbe58800f9a349f06a839adfaa4bf66adfd3de9fe590ab29b37667a89f026282cf0a3060e3a22722e4d420e827971fffd0ecbacc9015613650a2ab
6
+ metadata.gz: a8ca25014447c4c0909a95fe53bf7869d3469cfd21c67af9a38a3a6201b91c0feaaf3901b7c0b579aaa9ec9de6653ebbfa8fc09afec754f9f02fd6e618931735
7
+ data.tar.gz: 9cd1c6e2702d962229a20c98a3f3e0be6a1b35bc17da1318644673fa834c8c5d9b13e7a95c183c79ae3c4b8314ce3881609ee59cf01975086fe4be69cb8dfd8d
data/Gemfile CHANGED
@@ -6,14 +6,14 @@ gemspec
6
6
  gem 'rb-fsevent', '~> 0.9.1'
7
7
 
8
8
  # Development
9
- # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: '940837b', require: false
9
+ # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'ee5b98e', require: false
10
10
  # gem 'locomotivecms_coal', github: 'locomotivecms/coal', ref: '32b2844', require: false
11
11
  # gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '3046b79893', require: false
12
12
 
13
13
  # Local development
14
14
  # gem 'locomotivecms_coal', path: '../gems/coal', require: false
15
15
  # gem 'locomotivecms_steam', path: '../gems/steam', require: false
16
- # gem 'locomotivecms_common', path: '../in_progress/common', require: false
16
+ # gem 'locomotivecms_common', path: '../gems/common', require: false
17
17
 
18
18
  group :development, :test do
19
19
  gem 'pry-byebug', '~> 3.1.0'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Wagon
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/locomotivecms_wagon.svg)](http://badge.fury.io/rb/locomotivecms_wagon) [![Code Climate](https://codeclimate.com/github/locomotivecms/wagon/badges/gpa.svg)](https://codeclimate.com/github/locomotivecms/wagon) [![Dependency Status](https://gemnasium.com/locomotivecms/wagon.png)](https://gemnasium.com/locomotivecms/wagon) [![Build Status](https://travis-ci.org/locomotivecms/wagon.svg?branch=master)](https://travis-ci.org/locomotivecms/wagon) [![Coverage Status](https://coveralls.io/repos/locomotivecms/wagon/badge.svg?branch=master)](https://coveralls.io/r/locomotivecms/wagon?branch=master)
3
+ [![Gem Version](https://badge.fury.io/rb/locomotivecms_wagon.svg)](http://badge.fury.io/rb/locomotivecms_wagon) [![Code Climate](https://codeclimate.com/github/locomotivecms/wagon/badges/gpa.svg)](https://codeclimate.com/github/locomotivecms/wagon) [![Dependency Status](https://gemnasium.com/locomotivecms/wagon.png)](https://gemnasium.com/locomotivecms/wagon) [![Build Status](https://travis-ci.org/locomotivecms/wagon.svg?branch=master)](https://travis-ci.org/locomotivecms/wagon) [![Coverage Status](https://coveralls.io/repos/locomotivecms/wagon/badge.svg?branch=master)](https://coveralls.io/r/locomotivecms/wagon?branch=master) [![Join the chat at https://gitter.im/locomotivecms/wagon](https://badges.gitter.im/locomotivecms/wagon.svg)](https://gitter.im/locomotivecms/wagon?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
4
 
5
5
  Wagon is a command line tool that let's you develop for Locomotive right on your local machine.
6
6
 
@@ -20,6 +20,9 @@ published: true
20
20
  # sets a redirection to the given url (301)
21
21
  # redirect_url: "<url to a page or to a remote url>"
22
22
 
23
+ # other unique identifier of this page. To be used with the path_to liquid tag.
24
+ # handle: my-page-handle
25
+
23
26
  # content type that this page is templatizing
24
27
  <% if config[:content_type] -%>
25
28
  content_type: <%= config[:content_type] -%>
@@ -4,10 +4,12 @@ title: <%= config[:title] -%>
4
4
 
5
5
  # unique identifier for urls, the same as a permalink
6
6
  slug: <%= config[:slug] -%>
7
- <% end %>
7
+
8
+ <% else -%>
9
+
8
10
 
9
11
  # true if the page is included in the menu
10
- listed: <% if config[:listed] -%><%= config[:listed] %><% else -%>true<% end -%>
12
+ listed: <% if config[:listed] -%><%= config[:listed] %><% else -%>true<% end %>
11
13
 
12
14
  # true if the page is published
13
15
  published: true
@@ -21,11 +23,15 @@ published: true
21
23
  # sets a redirection to the given url (301)
22
24
  # redirect_url: "<url to a page or to a remote url>"
23
25
 
26
+ # other unique identifier of this page. To be used with the path_to liquid tag.
27
+ # handle: my-page-handle
28
+
24
29
  # content type that this page is templatizing
25
30
  <% if config[:content_type] -%>
26
31
  content_type: <%= config[:content_type] -%>
27
32
  <% else -%>
28
33
  # content_type: "<slug of one of the content types>"
34
+ <% end %>
29
35
  <% end -%>
30
36
 
31
37
  # editable_elements:
@@ -34,9 +34,9 @@ module Locomotive
34
34
  # @param [ String ] path The path of the site
35
35
  # @param [ Hash ] options The options for the thin server (host, port)
36
36
  #
37
- def self.serve(path, options)
37
+ def self.serve(path, options, shell)
38
38
  require_relative 'wagon/commands/serve_command'
39
- Locomotive::Wagon::ServeCommand.start(path, options)
39
+ Locomotive::Wagon::ServeCommand.start(path, options, shell)
40
40
  end
41
41
 
42
42
  # Stop the thin server.
@@ -44,9 +44,9 @@ module Locomotive
44
44
  # @param [ String ] path The path of the site
45
45
  # @param [ Hash ] force If true, block the current thread for 2s
46
46
  #
47
- def self.stop(path, force = false)
47
+ def self.stop(path, force = false, shell)
48
48
  require_relative 'wagon/commands/serve_command'
49
- Locomotive::Wagon::ServeCommand.stop(path, force)
49
+ Locomotive::Wagon::ServeCommand.stop(path, force, shell)
50
50
  end
51
51
 
52
52
  # Generate components for the LocomotiveCMS site such as content types, snippets, pages.
@@ -270,15 +270,10 @@ module Locomotive
270
270
  option :force, aliases: '-f', type: 'boolean', default: false, desc: 'Stop the current daemonized Thin server if found before starting a new one'
271
271
  option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs'
272
272
  def serve(path = '.')
273
- parent_pid = Process.pid
274
273
  force_color_if_asked(options)
275
274
  if check_path!(path)
276
275
  begin
277
- Locomotive::Wagon.serve(path, options)
278
- rescue SystemExit => e
279
- if parent_pid == Process.pid
280
- say "Your site is served now.", :green
281
- end
276
+ Locomotive::Wagon.serve(path, options, shell)
282
277
  rescue Exception => e
283
278
  self.print_exception(e, options[:verbose])
284
279
  exit(1)
@@ -291,8 +286,7 @@ module Locomotive
291
286
  force_color_if_asked(options)
292
287
  if check_path!(path)
293
288
  begin
294
- Locomotive::Wagon.stop(path)
295
- say "Your site is not served anymore.", :green
289
+ Locomotive::Wagon.stop(path, false, shell)
296
290
  rescue Exception => e
297
291
  say e.message, :red
298
292
  exit(1)
@@ -41,7 +41,7 @@ module Locomotive::Wagon
41
41
  end
42
42
  end
43
43
 
44
- { entry[default_locale].attributes[content_type.label_field_name] => clean_attributes(attributes) }
44
+ { entry[default_locale].attributes[content_type.label_field_name].to_s => clean_attributes(attributes) }
45
45
  end
46
46
 
47
47
  def fetch_content_types(&block)
@@ -37,12 +37,18 @@ module Locomotive::Wagon
37
37
  end
38
38
 
39
39
  def select_options_yaml(options)
40
+ return if options.blank?
41
+
42
+ ordered_options = options.sort { |option| option['position'] }
43
+
40
44
  if locales.size > 1
41
- locales.inject do |_options, locale|
42
- _options[locale] = attributes.map { |option| options['name'][locale.to_s] }
45
+ {}.tap do |_options|
46
+ ordered_options.each do |option|
47
+ locales.each { |locale| (_options[locale] ||= []) << option['name'][locale.to_s] }
48
+ end
43
49
  end
44
50
  else
45
- options.map { |option| option['name'][default_locale] }
51
+ ordered_options.map { |option| option['name'][default_locale] }
46
52
  end
47
53
  end
48
54
 
@@ -19,6 +19,8 @@ module Locomotive::Wagon
19
19
  # push the locales as long as there is no content on the remote site yet
20
20
  _attributes.delete(:locales) if remote_site.edited?
21
21
 
22
+ _attributes.delete(:metafields) unless with_data?
23
+
22
24
  if _attributes.present?
23
25
  api_client.current_site.update(_attributes)
24
26
  else
@@ -7,7 +7,7 @@ module Locomotive::Wagon
7
7
  end
8
8
 
9
9
  def decorate(entity)
10
- SnippetDecorator.new(entity, locale, default_locale)
10
+ SnippetDecorator.new(entity, locale, content_assets_pusher)
11
11
  end
12
12
 
13
13
  def persist(decorated_entity)
@@ -1,21 +1,18 @@
1
1
  module Locomotive::Wagon
2
2
 
3
- class ServeCommand < Struct.new(:path, :options)
3
+ class ServeCommand < Struct.new(:path, :options, :shell)
4
4
 
5
- attr_reader :use_listen
6
-
7
- def initialize(path, options)
8
- super(path, options || {})
9
-
10
- @use_listen = !self.options[:disable_listen]
5
+ def initialize(path, options, shell)
6
+ super(path, options || {}, shell)
7
+ @parent_id = nil
11
8
  end
12
9
 
13
- def self.start(path, options = {})
14
- new(path, options).start
10
+ def self.start(path, options = {}, shell)
11
+ new(path, options, shell).start
15
12
  end
16
13
 
17
- def self.stop(path, force = false)
18
- new(path, nil).stop(force)
14
+ def self.stop(path, force = false, shell)
15
+ new(path, nil, shell).stop(force)
19
16
  end
20
17
 
21
18
  def start
@@ -25,20 +22,36 @@ module Locomotive::Wagon
25
22
  # Steam is our rendering engine
26
23
  require_steam
27
24
 
28
- daemonize if options[:daemonize]
25
+ if options[:daemonize]
26
+ daemonize
27
+ else
28
+ setup_signals
29
+
30
+ show_start_message
31
+ end
29
32
 
30
33
  # if a page, a content type or any resources of the site is getting modified,
31
- # then the cache of Steam will be notified.
32
- listen if use_listen
34
+ # then the cache of Steam will be cleared.
35
+ listen if @parent_pid.nil? || Process.pid != @parent_pid
33
36
 
34
37
  # let's start!
35
38
  server.start
39
+
40
+ rescue SystemExit => e
41
+ show_start_message if @parent_pid == Process.pid
36
42
  end
37
43
 
38
44
  def stop(force = false)
45
+ unless File.exists?(server_pid_file)
46
+ shell.say "No Wagon server is running.", :red
47
+ return
48
+ end
49
+
39
50
  pid = File.read(server_pid_file).to_i
40
51
  Process.kill('TERM', pid)
41
52
 
53
+ shell.say "\nShutting down Wagon server"
54
+
42
55
  # make sure we wait enough for the server process to stop
43
56
  sleep(2) if force
44
57
  end
@@ -54,6 +67,8 @@ module Locomotive::Wagon
54
67
 
55
68
  configure_logger
56
69
 
70
+ subscribe_to_notifications
71
+
57
72
  Locomotive::Steam.configure do |config|
58
73
  config.mode = :test
59
74
  config.adapter = { name: :filesystem, path: File.expand_path(path) }
@@ -70,7 +85,7 @@ module Locomotive::Wagon
70
85
 
71
86
  def daemonize
72
87
  # very important to get the parent pid in order to differenciate the sub process from the parent one
73
- parent_pid = Process.pid
88
+ @parent_pid = Process.pid
74
89
 
75
90
  # The Daemons gem closes all file descriptors when it daemonizes the process. So any logfiles that were opened before the Daemons block will be closed inside the forked process.
76
91
  # So, close the current logger and set it up again when daemonized.
@@ -78,12 +93,11 @@ module Locomotive::Wagon
78
93
 
79
94
  server.log_file = server_log_file
80
95
  server.pid_file = server_pid_file
81
- server.daemonize
82
96
 
83
- use_listen = use_listen && Process.pid != parent_pid
97
+ server.daemonize
84
98
 
85
99
  # A "new logger" inside the daemon.
86
- configure_logger if Process.pid != parent_pid
100
+ configure_logger if Process.pid != @parent_pid
87
101
  end
88
102
 
89
103
  def listen
@@ -103,20 +117,50 @@ module Locomotive::Wagon
103
117
  # TODO: new feature -> pick the right Rack handler (Thin, Puma, ...etc)
104
118
  require 'thin'
105
119
 
106
- # Thin in debug mode
107
- # Thin::Logging.debug = true
120
+ # Do not display the default Thin server startup message
121
+ Thin::Logging.logger = Logger.new(server_log_file)
122
+
123
+ # Thin in debug mode only if the THIN_DEBUG_ON has been set in the shell
124
+ Thin::Logging.debug = ENV['THIN_DEBUG_ON']
108
125
 
109
126
  app = Locomotive::Steam.to_app
110
127
 
111
- Thin::Server.new(options[:host], options[:port], { signals: true }, app).tap do |server|
128
+ Thin::Server.new(options[:host], options[:port], { signals: false }, app).tap do |server|
112
129
  server.threaded = true
130
+ server.log_file = server_log_file
113
131
  end
114
132
  end
115
133
 
116
134
  def configure_logger
117
135
  Locomotive::Common.reset
118
136
  Locomotive::Common.configure do |config|
119
- config.notifier = Locomotive::Common::Logger.setup(log_file)
137
+ logger = options[:daemonize] ? log_file : nil
138
+ config.notifier = Locomotive::Common::Logger.setup(logger)
139
+ end
140
+ end
141
+
142
+ def subscribe_to_notifications
143
+ # Page not found
144
+ ActiveSupport::Notifications.subscribe('steam.render.page_not_found') do |name, start, finish, id, payload|
145
+ fullpath, locale, default_locale = payload[:path], payload[:locale], payload[:default_locale]
146
+
147
+ filepath = File.join(File.expand_path(path), 'app', 'views', 'pages', fullpath + (locale != default_locale ? ".#{locale}" : '') + '.liquid')
148
+
149
+ message = "[Tip]".light_white + " add a new page in your Wagon site at this location: " + filepath.light_white
150
+
151
+ Locomotive::Common::Logger.info (' ' * 2) + message
152
+ end
153
+ end
154
+
155
+ def setup_signals
156
+ %w(INT TERM).each do |signal|
157
+ trap(signal) do
158
+ show_stop_message
159
+
160
+ EM.add_timer(1) do
161
+ server.stop
162
+ end
163
+ end
120
164
  end
121
165
  end
122
166
 
@@ -132,6 +176,14 @@ module Locomotive::Wagon
132
176
  File.expand_path(File.join(path, 'log', 'wagon.log'))
133
177
  end
134
178
 
179
+ def show_start_message
180
+ shell.say "Your site is served now.\nBrowse http://#{options[:host]}:#{options[:port]}\n\n", :green
181
+ end
182
+
183
+ def show_stop_message
184
+ shell.say "\nShutting down Wagon server"
185
+ end
186
+
135
187
  end
136
188
 
137
189
  end
@@ -13,7 +13,7 @@ module Locomotive
13
13
  def __attributes__
14
14
  %i(name type label hint required localized unique position
15
15
  text_formatting select_options
16
- target inverse_of order_by ui_enabled)
16
+ target inverse_of order_by ui_enabled default)
17
17
  end
18
18
 
19
19
  def type
@@ -48,8 +48,8 @@ module Locomotive
48
48
  end
49
49
 
50
50
  def ui_enabled
51
- return nil unless is_relationship?
52
- self[:order_by]
51
+ return nil if self[:ui_enabled].nil?
52
+ self[:ui_enabled]
53
53
  end
54
54
 
55
55
  def select_options
@@ -18,14 +18,14 @@ module Locomotive
18
18
  end
19
19
  end
20
20
 
21
- %i(robots_txt timezone seo_title meta_keywords meta_description).each do |name|
21
+ %i(robots_txt timezone seo_title meta_keywords meta_description metafields_schema metafields).each do |name|
22
22
  define_method(name) do
23
23
  self[name]
24
24
  end
25
25
  end
26
26
 
27
27
  def __attributes__
28
- %i(name handle robots_txt locales timezone seo_title meta_keywords meta_description picture)
28
+ %i(name handle robots_txt locales timezone seo_title meta_keywords meta_description picture metafields_schema metafields)
29
29
  end
30
30
 
31
31
  def edited?
@@ -37,7 +37,7 @@ module Locomotive
37
37
  class UpdateSiteDecorator < SiteDecorator
38
38
 
39
39
  def __attributes__
40
- %i(picture locales)
40
+ %i(picture locales metafields_schema metafields)
41
41
  end
42
42
 
43
43
  end
@@ -4,6 +4,18 @@ module Locomotive
4
4
  class SnippetDecorator < Locomotive::Steam::Decorators::TemplateDecorator
5
5
 
6
6
  include ToHashConcern
7
+ include PersistAssetsConcern
8
+
9
+ attr_accessor :__content_assets_pusher__
10
+
11
+ def initialize(object, locale = nil, content_assets_pusher)
12
+ self.__content_assets_pusher__ = content_assets_pusher
13
+ super(object, locale, nil)
14
+ end
15
+
16
+ def __attributes__
17
+ %i(name slug template)
18
+ end
7
19
 
8
20
  def id
9
21
  slug
@@ -13,16 +25,12 @@ module Locomotive
13
25
  {}.tap do |translations|
14
26
  __getobj__.template_path.translations.each do |locale, _|
15
27
  __with_locale__(locale) do
16
- translations[locale] = self.liquid_source
28
+ translations[locale] = replace_with_content_assets!(self.liquid_source)
17
29
  end
18
30
  end
19
31
  end
20
32
  end
21
33
 
22
- def __attributes__
23
- %i(name slug template)
24
- end
25
-
26
34
  end
27
35
 
28
36
  end
@@ -62,6 +62,8 @@ module Locomotive
62
62
  end
63
63
 
64
64
  def other_locales
65
+ return @other_locales if @other_locales
66
+
65
67
  # Rules:
66
68
  # #1 default: [fr, en, es], asked: [en, de], result => [en]
67
69
  # #2 default: [fr, en, de], asked: [es], result => []
@@ -74,7 +76,7 @@ module Locomotive
74
76
  locales = options[:default_locales]
75
77
  locales.shift
76
78
 
77
- locales & (_locales || [])
79
+ @other_locales = locales & (_locales || [])
78
80
  end
79
81
 
80
82
  end