locomotivecms_wagon 3.0.0.rc0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +1 -1
  4. data/Gemfile +2 -2
  5. data/README.md +4 -4
  6. data/generators/blank/Gemfile.tt +0 -6
  7. data/generators/blank/app/assets/javascripts/sections/_manager.js +3 -2
  8. data/generators/blank/app/views/pages/layouts/default.liquid +1 -1
  9. data/generators/blank/config/metafields_schema.yml +5 -0
  10. data/generators/blank/package.json.tt +1 -1
  11. data/generators/blank/public/samples/images/default.svg +1 -0
  12. data/generators/content_type/app/content_types/%slug%.yml.tt +6 -0
  13. data/generators/section/%type%.js.tt +1 -1
  14. data/generators/section/template.liquid.tt +117 -142
  15. data/generators/site_metafields/schema.yml.tt +5 -0
  16. data/generators/webpack/app/assets/javascripts/sections/_manager.js +3 -2
  17. data/generators/webpack/package.json.tt +1 -1
  18. data/lib/locomotive/wagon/cli.rb +13 -23
  19. data/lib/locomotive/wagon/commands/concerns/api_concern.rb +1 -0
  20. data/lib/locomotive/wagon/commands/concerns/steam_concern.rb +1 -1
  21. data/lib/locomotive/wagon/commands/delete_command.rb +2 -2
  22. data/lib/locomotive/wagon/commands/generate_command.rb +6 -1
  23. data/lib/locomotive/wagon/commands/push_command.rb +30 -3
  24. data/lib/locomotive/wagon/commands/push_sub_commands/push_pages_command.rb +4 -0
  25. data/lib/locomotive/wagon/commands/push_sub_commands/push_site_command.rb +4 -3
  26. data/lib/locomotive/wagon/commands/serve_command.rb +35 -54
  27. data/lib/locomotive/wagon/commands/sync_sub_commands/sync_pages_command.rb +2 -0
  28. data/lib/locomotive/wagon/decorators/concerns/persist_assets_concern.rb +1 -1
  29. data/lib/locomotive/wagon/decorators/content_type_decorator.rb +10 -1
  30. data/lib/locomotive/wagon/decorators/site_decorator.rb +14 -4
  31. data/lib/locomotive/wagon/generators/section.rb +3 -3
  32. data/lib/locomotive/wagon/generators/site/base.rb +2 -4
  33. data/lib/locomotive/wagon/middlewares/error_page.rb +18 -4
  34. data/lib/locomotive/wagon/tools/listen.rb +6 -1
  35. data/lib/locomotive/wagon/version.rb +1 -1
  36. data/locomotivecms_wagon.gemspec +8 -8
  37. data/spec/fixtures/cassettes/authenticate.yml +42 -42
  38. data/spec/fixtures/cassettes/delete.yml +238 -238
  39. data/spec/fixtures/cassettes/push.yml +2006 -2027
  40. data/spec/fixtures/cassettes/sync.yml +2290 -2311
  41. data/spec/fixtures/default/icon.png +0 -0
  42. data/spec/integration/commands/push_command_spec.rb +39 -9
  43. data/spec/integration/commands/sync_command_spec.rb +7 -1
  44. data/spec/support/vcr.rb +13 -0
  45. data/spec/unit/decorators/site_decorator_spec.rb +4 -3
  46. metadata +23 -24
  47. data/TODO +0 -57
@@ -14,6 +14,7 @@
14
14
  # hint: <my hint> # used as the hint of the HTML input. Use a hash if you want it in another languages.
15
15
  # type: <string|text|integer|float|image|boolean|select|color>
16
16
  # localized: <true|false> # if the value is scoped by the current locale when rendering the site.
17
+ # sample: <any value> # value only used in Wagon for testing purpose. Will not be deployed
17
18
  # position: <0..n> # position of the input in the form
18
19
  # select_options: [array]
19
20
  # # select_options:
@@ -34,15 +35,19 @@
34
35
  # address:
35
36
  # type: string
36
37
  # hint: "Ex: 7 allee Albert Camus"
38
+ # sample: "700 S Laflin St"
37
39
  # city:
38
40
  # type: string
39
41
  # hint: "Chicago, Paris, Blagnac, Toulouse"
42
+ # sample: "Chicago"
40
43
  # zip_code:
41
44
  # type: string
42
45
  # hint: "Digits only"
46
+ # sample: "60607"
43
47
  # hours:
44
48
  # type: text
45
49
  # hint: "Free text here"
50
+ # sample: "6:00am - 8:00pm"
46
51
  # theme:
47
52
  # fields:
48
53
  # background_image:
@@ -11,7 +11,7 @@ class Manager {
11
11
 
12
12
  start() {
13
13
  this.eachType((type, actions) => {
14
- this.queryAll(`.locomotive-section[data-locomotive-section-type="${type}"]`).forEach((section, index) => {
14
+ this.queryAll(`[data-locomotive-section-type="${type}"]`).forEach((section, index) => {
15
15
  this.runAction(actions, 'load', section);
16
16
  });
17
17
  });
@@ -40,7 +40,8 @@ class Manager {
40
40
 
41
41
  applyRuleToEvent(actionName, event) {
42
42
  const { sectionId, blockId } = event.detail;
43
- const section = document.getElementById(`locomotive-section-${sectionId}`);
43
+ const section = document.getElementById(`locomotive-section-${sectionId}`) ||
44
+ this.queryOne(`[data-locomotive-section-id="${sectionId}"]`);
44
45
  const type = section.getAttribute('data-locomotive-section-type');
45
46
  const block = this.queryOne(`[data-locomotive-block="section-${sectionId}-block-${blockId}"]`, section);
46
47
 
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "Wagon assets",
2
+ "name": "WagonAssets",
3
3
  "version": "1.0.0",
4
4
  "description": "Assets source for the Wagon site",
5
5
  "main": "index.js",
@@ -232,15 +232,14 @@ module Locomotive
232
232
  end
233
233
 
234
234
  desc 'init NAME [PATH] [GENERATOR_OPTIONS]', 'Create a brand new site'
235
- method_option :template, aliases: '-t', type: 'string', default: 'blank', desc: 'instead of building from a blank site, you can also have a pre-fetched site from a template (see the templates command)'
236
235
  method_option :lib, aliases: '-l', type: 'string', desc: 'Path to an external ruby lib or generator'
237
- method_option :skip_bundle, type: 'boolean', default: false, desc: "Don't run bundle install"
236
+ method_option :skip_bundle, type: 'boolean', default: true, desc: "Don't run bundle install"
238
237
  method_option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs'
239
238
  def init(name, path = '.', *generator_options)
240
239
  force_color_if_asked(options)
241
240
  require 'locomotive/wagon/generators/site'
242
241
  require File.expand_path(options[:lib]) if options[:lib]
243
- generator = Locomotive::Wagon::Generators::Site.get(options[:template])
242
+ generator = Locomotive::Wagon::Generators::Site.get(:blank)
244
243
  if generator.nil?
245
244
  say "Unknown site template '#{options[:template]}'", :red
246
245
  exit(1)
@@ -340,6 +339,7 @@ module Locomotive
340
339
  option :resources, aliases: '-r', type: 'array', default: nil, desc: 'Only push the resource(s) passed in argument'
341
340
  option :filter, aliases: '-f', type: 'array', default: nil, desc: 'Push specific resource entries'
342
341
  option :data, aliases: '-d', type: 'boolean', default: false, desc: 'Push the content entries and the editable elements (by default, they are not)'
342
+ option :env, aliases: '-e', type: 'string', default: 'local', desc: 'The env used to the data of the pages and content entries'
343
343
  option :shell, type: 'boolean', default: true, desc: 'Use shell to ask for missing connection information like the site handle (in this case, take a random one)'
344
344
  option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs'
345
345
  def deploy(env, path = '.')
@@ -416,26 +416,16 @@ module Locomotive
416
416
  #
417
417
  def print_next_instructions_when_site_created(name, path, skip_bundle)
418
418
  say "\nCongratulations, your site \"#{name}\" has been created successfully !", :green
419
- say 'Next steps:', :bold
420
-
421
- next_instructions = <<-BASH
422
- cd #{path}/#{name}
423
-
424
- #{'bundle install' unless skip_bundle}
425
- #{'bundle exec' unless skip_bundle} wagon serve
426
-
427
- # In a another terminal
428
- yarn
429
- yarn start
430
-
431
- open http://0.0.0.0:3333
432
- BASH
433
-
434
- # next_instructions = "\tcd #{path}/#{name}\n\t"
435
- # next_instructions += "bundle install\n\t" unless skip_bundle
436
- # next_instructions += "#{'bundle exec ' unless skip_bundle}wagon serve\n\topen http://0.0.0.0:3333"
437
-
438
- say next_instructions
419
+ say "\nNext steps:\n", :bold
420
+ say "\n# Run the local web server", :on_blue
421
+ say "\n\tcd #{path}/#{name}"
422
+ say "\tbundle install" unless skip_bundle
423
+ say "\t#{'bundle exec ' unless skip_bundle}wagon serve"
424
+ say "\n# Compile assets (in a another terminal)", :on_blue
425
+ say "\n\tyarn"
426
+ say "\tyarn start"
427
+ say "\n# Preview your site!", :on_blue
428
+ say "\n\topen http://0.0.0.0:3333\n\n", :bold
439
429
  end
440
430
 
441
431
  # Print the exception.
@@ -11,6 +11,7 @@ module Locomotive::Wagon
11
11
 
12
12
  # Instance of the API client to request resources of a site: pages, theme_assets, ...etc.
13
13
  def api_site_client(connection)
14
+ return if connection.nil?
14
15
  return @api_site_client if @api_site_client
15
16
 
16
17
  _host, _credentials = connection['host'], connection.slice('email', 'api_key', 'password')
@@ -9,7 +9,7 @@ module Locomotive::Wagon
9
9
 
10
10
  Locomotive::Steam.configure do |config|
11
11
  config.mode = :test
12
- config.adapter = { name: :filesystem, path: path, env: :local }
12
+ config.adapter = { name: :filesystem, path: path, env: options[:env]&.to_sym || :local }
13
13
  config.asset_path = File.expand_path(File.join(path, 'public'))
14
14
  config.minify_assets = false
15
15
  end
@@ -9,8 +9,8 @@ module Locomotive::Wagon
9
9
  include DeployFileConcern
10
10
 
11
11
  SITE_RESOURCE = 'site'
12
- SINGLE_RESOURCES = %w(page content_type snippet translation).freeze
13
- ALL_RESOURCES = %w(content_types snippets theme_assets translations).freeze
12
+ SINGLE_RESOURCES = %w(page content_type snippet section translation).freeze
13
+ ALL_RESOURCES = %w(content_types snippets theme_assets sections translations).freeze
14
14
 
15
15
  # @param [ String ] env The environment to delete from
16
16
  # @param [ String ] path The path to a wagon site to delete from
@@ -7,7 +7,12 @@ module Locomotive::Wagon
7
7
  end
8
8
 
9
9
  def generate
10
- Bundler.require 'misc'
10
+ begin
11
+ ::Bundler.require 'misc'
12
+ rescue Exception => e
13
+ # Bundler is not defined or there is an issue
14
+ # with one of the gems in the misc group
15
+ end
11
16
 
12
17
  generator = generator_klass.new(args, options, { behavior: :skip })
13
18
  generator.destination_root = args.last
@@ -36,6 +36,14 @@ module Locomotive::Wagon
36
36
 
37
37
  api_client = build_api_site_client(connection_information)
38
38
 
39
+ return if api_client.nil?
40
+
41
+ # Ask for a confirmation (Warning) if we deploy with the -d option
42
+ # since it alters content on the remote engine
43
+ if options[:data]
44
+ return unless ask_for_performing("Warning! You're about to deploy data which will alter the content of your site.")
45
+ end
46
+
39
47
  if options[:verbose]
40
48
  PushLogger.new
41
49
  _push(api_client)
@@ -90,9 +98,14 @@ module Locomotive::Wagon
90
98
  # the deployment env exists and contains all the information we need to move on
91
99
  information
92
100
  else
101
+ # warn the user that we're going to create a new site. Ask her/him if we continue
102
+ return unless ask_for_performing('You are about to deploy a new site')
103
+
93
104
  # mandatory to sign in
94
105
  load_credentials_from_netrc
95
106
 
107
+ return if self.credentials.nil?
108
+
96
109
  # create the remote site on the platform
97
110
  site = create_remote_site
98
111
 
@@ -131,7 +144,9 @@ module Locomotive::Wagon
131
144
  # retrieve email + api_key. If no entry present in the .netrc, raise an error
132
145
  self.credentials = read_credentials_from_netrc(self.api_host)
133
146
 
134
- raise 'You need to run `wagon auth` before going further' if self.credentials.nil?
147
+ if self.credentials.nil?
148
+ shell.say "Sorry, we were unable to find the credentials for this platform.\nPlease first login using the \"bundle exec wagon auth\"", :yellow
149
+ end
135
150
  end
136
151
 
137
152
  def ask_for_platform_url
@@ -155,11 +170,12 @@ module Locomotive::Wagon
155
170
  begin
156
171
  attributes = @api_site_client.current_site.get.attributes
157
172
  rescue Locomotive::Coal::UnknownResourceError
158
- raise 'Sorry, we were unable to find your site on the remote platform. Check the information in your config/deploy.yml file.'
173
+ shell.say 'Sorry, we were unable to find your site on the remote platform. Check the information in your config/deploy.yml file.', :red
174
+ raise 'Unable to find your site on the remote platform'
159
175
  end
160
176
 
161
177
  _site = Locomotive::Steam::Site.new(attributes)
162
- @remote_site = SiteDecorator.new(_site)
178
+ @remote_site = RemoteSiteDecorator.new(_site)
163
179
  end
164
180
 
165
181
  def require_misc_gems
@@ -168,6 +184,17 @@ module Locomotive::Wagon
168
184
  Bundler.require 'misc'
169
185
  end
170
186
 
187
+ def ask_for_performing(message)
188
+ shell.say(message, :yellow)
189
+
190
+ unless shell.yes?("Are you sure you want to perform this action? (answer yes or no)")
191
+ shell.say("Deployment canceled!", :yellow)
192
+ return false
193
+ end
194
+
195
+ true
196
+ end
197
+
171
198
  def print_result_message
172
199
  shell.say "\n\nYour site has been deployed.", :green
173
200
 
@@ -126,9 +126,13 @@ module Locomotive::Wagon
126
126
 
127
127
  template_path = entity.template_path[default_locale]
128
128
 
129
+ # no template path (use case: deploying new pages from a different env)
130
+ return true if template_path.nil?
131
+
129
132
  # not localized?
130
133
  return true if template_path == false
131
134
 
135
+
132
136
  # part of the filter?
133
137
  _path = template_path.gsub('./app/views/pages/', '')
134
138
  !@only_entities.any? { |regexp| regexp.match(_path) }
@@ -7,9 +7,7 @@ module Locomotive::Wagon
7
7
  end
8
8
 
9
9
  def decorate(entity)
10
- UpdateSiteDecorator.new(entity).tap do |decorator|
11
- decorator.__content_assets_pusher__ = self.content_assets_pusher
12
- end
10
+ UpdateSiteDecorator.new(entity, default_locale, path, content_assets_pusher)
13
11
  end
14
12
 
15
13
  def persist(decorated_entity)
@@ -18,6 +16,9 @@ module Locomotive::Wagon
18
16
  # push the picture only if there is no existing remote picture
19
17
  _attributes.delete(:picture) if remote_site['picture_url'].present?
20
18
 
19
+ # timezone can be pushed with the -d option
20
+ _attributes.delete(:timezone) unless with_data?
21
+
21
22
  # push the locales as long as there is no content on the remote site yet
22
23
  _attributes.delete(:locales) if remote_site.edited?
23
24
 
@@ -18,31 +18,28 @@ module Locomotive::Wagon
18
18
  end
19
19
 
20
20
  def start
21
- # make sure the Thin server is not running
21
+ # make sure a server is not running
22
22
  stop(true) if options[:force]
23
23
 
24
24
  # Steam is our rendering engine
25
25
  require_steam
26
26
 
27
- if options[:daemonize]
28
- daemonize
29
- else
30
- setup_signals
27
+ setup_signals
31
28
 
32
- show_start_message
29
+ show_start_message
33
30
 
34
- show_rack_middleware_stack if options[:debug]
35
- end
31
+ show_rack_middleware_stack if options[:debug]
36
32
 
37
33
  # if a page, a content type or any resources of the site is getting modified,
38
34
  # then the cache of Steam will be cleared.
39
- listen if @parent_pid.nil? || Process.pid != @parent_pid
35
+ listen
40
36
 
41
37
  # let's start!
42
- server.start
43
-
44
- rescue SystemExit => e
45
- show_start_message if @parent_pid == Process.pid
38
+ begin
39
+ server.start
40
+ rescue NoMethodError # Prevent the NilClass error from Puma to be displayed
41
+ nil
42
+ end
46
43
  end
47
44
 
48
45
  def stop(force = false)
@@ -75,7 +72,7 @@ module Locomotive::Wagon
75
72
 
76
73
  Locomotive::Steam.configure do |config|
77
74
  config.mode = :test
78
- config.adapter = { name: :filesystem, path: File.expand_path(path), env: options[:env].to_sym }
75
+ config.adapter = { name: :filesystem, path: File.expand_path(path), env: options[:env]&.to_sym || :local }
79
76
  config.asset_path = File.expand_path(File.join(path, 'public'))
80
77
  config.minify_assets = false
81
78
 
@@ -93,52 +90,36 @@ module Locomotive::Wagon
93
90
  Bundler.require 'misc'
94
91
  end
95
92
 
96
- def daemonize
97
- # very important to get the parent pid in order to differenciate the sub process from the parent one
98
- @parent_pid = Process.pid
99
-
100
- # 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.
101
- # So, close the current logger and set it up again when daemonized.
102
- Locomotive::Common::Logger.close
103
-
104
- server.log_file = server_log_file
105
- server.pid_file = server_pid_file
106
-
107
- server.daemonize
108
-
109
- # A "new logger" inside the daemon.
110
- configure_logger if Process.pid != @parent_pid
111
- end
112
-
113
93
  def listen
114
- require_relative '../tools/listen'
115
- require 'locomotive/steam/adapters/filesystem/simple_cache_store'
94
+ require 'puma/plugin'
116
95
 
117
- cache = Locomotive::Steam::Adapters::Filesystem::SimpleCacheStore.new
96
+ Puma::Plugins.add_background -> {
97
+ require_relative '../tools/listen'
98
+ require 'locomotive/steam/adapters/filesystem/simple_cache_store'
118
99
 
119
- Locomotive::Wagon::Listen.start(path, cache, options)
120
- end
100
+ cache = Locomotive::Steam::Adapters::Filesystem::SimpleCacheStore.new
121
101
 
122
- def server
123
- @server ||= build_server
102
+ Locomotive::Wagon::Listen.start(path, cache, options)
103
+ }
124
104
  end
125
105
 
126
- def build_server
127
- # TODO: new feature -> pick the right Rack handler (Thin, Puma, ...etc)
128
- require 'thin'
129
-
130
- # Do not display the default Thin server startup message
131
- Thin::Logging.logger = Logger.new(server_log_file)
132
-
133
- # Thin in debug mode only if the THIN_DEBUG_ON has been set in the shell
134
- Thin::Logging.debug = ENV['THIN_DEBUG_ON']
135
-
136
- app = Locomotive::Steam.to_app
137
-
138
- Thin::Server.new(options[:host], options[:port], { signals: false }, app).tap do |server|
139
- server.threaded = true
140
- server.log_file = server_log_file
141
- end
106
+ def server
107
+ @server ||= build_puma_server
108
+ end
109
+
110
+ def build_puma_server
111
+ require 'rack/handler/puma'
112
+
113
+ Rack::Handler::Puma.run(Locomotive::Steam.to_app, {
114
+ daemon: options[:daemonize],
115
+ pidfile: server_pid_file,
116
+ redirect_stdout: options[:daemonize] ? server_log_file : nil,
117
+ Threads: ENV['PUMA_THREADS'] || '1:4',
118
+ Host: options[:host],
119
+ Port: options[:port],
120
+ Verbose: ENV['PUMA_DEBUG_ON'] || false,
121
+ Silent: true
122
+ })
142
123
  end
143
124
 
144
125
  def configure_logger
@@ -47,10 +47,12 @@ module Locomotive::Wagon
47
47
  private
48
48
 
49
49
  def sections_content(page)
50
+ return {} if page.sections_content.blank?
50
51
  JSON.parse(page.sections_content)
51
52
  end
52
53
 
53
54
  def sections_dropzone_content(page)
55
+ return [] if page.sections_dropzone_content.blank?
54
56
  JSON.parse(page.sections_dropzone_content)
55
57
  end
56
58
 
@@ -7,7 +7,7 @@ module Locomotive::Wagon
7
7
  def replace_with_content_assets!(text)
8
8
  return text if text.blank?
9
9
 
10
- text.to_s.gsub(/([^a-zA-Z0-9]|^)(\/samples\/[\/a-zA-Z0-9_-]+\.[a-zA-Z0-9]+)/) do
10
+ text.to_s.gsub(/([^a-zA-Z0-9]|^)(\/samples\/[\/a-zA-Z0-9_-]+(\.[a-zA-Z0-9]+)*)/) do
11
11
  url = __content_assets_pusher__.persist($2) || $2
12
12
  $1 + url
13
13
  end
@@ -16,7 +16,8 @@ module Locomotive
16
16
  public_submission_enabled
17
17
  public_submission_accounts
18
18
  public_submission_title_template
19
- entry_template display_settings filter_fields)
19
+ public_submission_email_attachments
20
+ recaptcha_required entry_template display_settings filter_fields)
20
21
  end
21
22
 
22
23
  def fields
@@ -58,6 +59,10 @@ module Locomotive
58
59
  self[:public_submission_title_template]
59
60
  end
60
61
 
62
+ def public_submission_email_attachments
63
+ self[:public_submission_email_attachments]
64
+ end
65
+
61
66
  def entry_template
62
67
  self[:entry_template]
63
68
  end
@@ -74,6 +79,10 @@ module Locomotive
74
79
  self[:tree_parent_field_name]
75
80
  end
76
81
 
82
+ def recaptcha_required
83
+ self[:recaptcha_required]
84
+ end
85
+
77
86
  def with_relationships?
78
87
  __getobj__.fields.associations.count > 0
79
88
  end