locomotivecms_wagon 2.0.1 → 2.1.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/generators/blank/config/metafields_schema.yml +56 -0
  4. data/generators/blank/config/site.yml.tt +14 -0
  5. data/generators/bootstrap/config/metafields_schema.yml +56 -0
  6. data/generators/bootstrap/config/site.yml.tt +14 -0
  7. data/generators/foundation5/config/metafields_schema.yml +56 -0
  8. data/generators/foundation5/config/site.yml.tt +14 -0
  9. data/generators/site_metafields/schema.yml.tt +56 -0
  10. data/lib/locomotive/wagon/cli.rb +11 -1
  11. data/lib/locomotive/wagon/commands/concerns/steam_concern.rb +4 -3
  12. data/lib/locomotive/wagon/commands/pull_command.rb +1 -1
  13. data/lib/locomotive/wagon/commands/pull_sub_commands/concerns/assets_concern.rb +8 -0
  14. data/lib/locomotive/wagon/commands/pull_sub_commands/pull_site_command.rb +24 -1
  15. data/lib/locomotive/wagon/commands/push_sub_commands/push_site_command.rb +3 -1
  16. data/lib/locomotive/wagon/commands/serve_command.rb +15 -0
  17. data/lib/locomotive/wagon/commands/sync_command.rb +1 -1
  18. data/lib/locomotive/wagon/commands/sync_sub_commands/sync_site_command.rb +31 -0
  19. data/lib/locomotive/wagon/decorators/concerns/persist_assets_concern.rb +8 -0
  20. data/lib/locomotive/wagon/decorators/content_entry_decorator.rb +1 -0
  21. data/lib/locomotive/wagon/decorators/site_decorator.rb +13 -1
  22. data/lib/locomotive/wagon/generators/site_metafields.rb +54 -0
  23. data/lib/locomotive/wagon/tools/yaml_ext.rb +21 -0
  24. data/lib/locomotive/wagon/version.rb +1 -1
  25. data/locomotivecms_wagon.gemspec +4 -4
  26. data/spec/fixtures/cassettes/authenticate.yml +41 -82
  27. data/spec/fixtures/cassettes/delete.yml +159 -159
  28. data/spec/fixtures/cassettes/push.yml +1015 -1015
  29. data/spec/integration/cli_spec.rb +1 -1
  30. data/spec/unit/decorators/content_entry_decorator_spec.rb +10 -0
  31. data/spec/unit/tools/yaml_ext_spec.rb +46 -0
  32. metadata +21 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c16813277aecf384b3c2a2b8b3eeab3db1da8237
4
- data.tar.gz: c031bdde8b3277407a0c45e840729e54b2254f9d
3
+ metadata.gz: 571f69b042f72f8bf9c9ac09260ed1f5f19af3e1
4
+ data.tar.gz: 199bdd8684cfc28ba142652e6652713ee8e633f8
5
5
  SHA512:
6
- metadata.gz: a8ca25014447c4c0909a95fe53bf7869d3469cfd21c67af9a38a3a6201b91c0feaaf3901b7c0b579aaa9ec9de6653ebbfa8fc09afec754f9f02fd6e618931735
7
- data.tar.gz: 9cd1c6e2702d962229a20c98a3f3e0be6a1b35bc17da1318644673fa834c8c5d9b13e7a95c183c79ae3c4b8314ce3881609ee59cf01975086fe4be69cb8dfd8d
6
+ metadata.gz: 13ee04e4560d5a032cd52e10774db4bd1e40e0d288e5bd58aad6b25334a83f4a0047b4c293361caf5f2db6afbbe2dfd23144b7939cbf0a9c26a5caa6f4f3a107
7
+ data.tar.gz: 40027558ba5aa6b28528be62b6496ea11fcf76d3e77dc158d8b20975c805bc2ba26dd469c88a04914068828cc8c79e54c517788c4c1844f9d574e66888cfa56a
data/Gemfile CHANGED
@@ -6,9 +6,9 @@ gemspec
6
6
  gem 'rb-fsevent', '~> 0.9.1'
7
7
 
8
8
  # Development
9
- # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'ee5b98e', require: false
10
- # gem 'locomotivecms_coal', github: 'locomotivecms/coal', ref: '32b2844', require: false
11
- # gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '3046b79893', require: false
9
+ # gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '257047b', require: false
10
+ # gem 'locomotivecms_coal', github: 'locomotivecms/coal', ref: 'f4ff435', require: false
11
+ # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: '62c274f', require: false
12
12
 
13
13
  # Local development
14
14
  # gem 'locomotivecms_coal', path: '../gems/coal', require: false
@@ -0,0 +1,56 @@
1
+ # Site metafield schema
2
+ #
3
+ # Syntax:
4
+ #
5
+ # - <namespace_1>: # no empty spaces, only digits and underscores
6
+ # label: <my label> # used as the label of a tab in the back-office
7
+ # # label: # if you want to provide the label in another language (back-office)
8
+ # # en: <your label in English if the local of the current user is English>
9
+ # # fr: <your label in French>
10
+ # position: <0..n> # position of the tab in the menu
11
+ # fields:
12
+ # <name_1>:
13
+ # label: <my label> # used as the label of the HTML input. Use a hash if you want it in another languages.
14
+ # hint: <my hint> # used as the hint of the HTML input. Use a hash if you want it in another languages.
15
+ # type: <string|text|integer|float|file|image|boolean|select|color>
16
+ # localized: <true|false> # if the value is scoped by the current locale when rendering the site.
17
+ # position: <0..n> # position of the input in the form
18
+ # select_options: [array]
19
+ # # select_options:
20
+ # # <option_value_1>: <label> # use a hash instead if you want it in another languages.
21
+ # # <option_value_2>: <label> # use a hash instead if you want it in another languages.
22
+ # # <name_2>:
23
+ # # ...
24
+ #
25
+ # - <namespace_2>:
26
+ # # ...
27
+ #
28
+ #
29
+ # Simple example:
30
+ #
31
+ # shop:
32
+ # label: My shop location
33
+ # fields:
34
+ # address:
35
+ # type: string
36
+ # hint: "Ex: 7 allee Albert Camus"
37
+ # city:
38
+ # type: string
39
+ # hint: "Chicago, Paris, Blagnac, Toulouse"
40
+ # zip_code:
41
+ # type: string
42
+ # hint: "Digits only"
43
+ # hours:
44
+ # type: text
45
+ # hint: "Free text here"
46
+ # theme:
47
+ # fields:
48
+ # background_image:
49
+ # type: image
50
+ # hint: full screen image (min: 3000px x 3000px)
51
+ # link_color:
52
+ # type: color
53
+ # font:
54
+ # type: select
55
+ # select_options: ['helvetica', 'Noto']
56
+
@@ -26,3 +26,17 @@ locales: [en]
26
26
  seo_title: <%= @name %>
27
27
  meta_keywords: "some meta keywords"
28
28
  meta_description: "some meta description"
29
+
30
+ # Each site can have its own set of custom properties organized in namespaces.
31
+ # First, define namespaces and their fields in the config/metafields_schema.yml file.
32
+ # Finally, set default values below as described in the example.
33
+ # You can access them in your liquid templates and snippets:
34
+ # {{ site.metafields.<namespace>.<field> }}
35
+ #
36
+ # Example:
37
+ #
38
+ # metafields:
39
+ # shop:
40
+ # address: 700 South Laflin Street
41
+ # theme:
42
+ # background_image: "/samples/background.png"
@@ -0,0 +1,56 @@
1
+ # Site metafield schema
2
+ #
3
+ # Syntax:
4
+ #
5
+ # - <namespace_1>: # no empty spaces, only digits and underscores
6
+ # label: <my label> # used as the label of a tab in the back-office
7
+ # # label: # if you want to provide the label in another language (back-office)
8
+ # # en: <your label in English if the local of the current user is English>
9
+ # # fr: <your label in French>
10
+ # position: <0..n> # position of the tab in the menu
11
+ # fields:
12
+ # <name_1>:
13
+ # label: <my label> # used as the label of the HTML input. Use a hash if you want it in another languages.
14
+ # hint: <my hint> # used as the hint of the HTML input. Use a hash if you want it in another languages.
15
+ # type: <string|text|integer|float|file|image|boolean|select|color>
16
+ # localized: <true|false> # if the value is scoped by the current locale when rendering the site.
17
+ # position: <0..n> # position of the input in the form
18
+ # select_options: [array]
19
+ # # select_options:
20
+ # # <option_value_1>: <label> # use a hash instead if you want it in another languages.
21
+ # # <option_value_2>: <label> # use a hash instead if you want it in another languages.
22
+ # # <name_2>:
23
+ # # ...
24
+ #
25
+ # - <namespace_2>:
26
+ # # ...
27
+ #
28
+ #
29
+ # Simple example:
30
+ #
31
+ # shop:
32
+ # label: My shop location
33
+ # fields:
34
+ # address:
35
+ # type: string
36
+ # hint: "Ex: 7 allee Albert Camus"
37
+ # city:
38
+ # type: string
39
+ # hint: "Chicago, Paris, Blagnac, Toulouse"
40
+ # zip_code:
41
+ # type: string
42
+ # hint: "Digits only"
43
+ # hours:
44
+ # type: text
45
+ # hint: "Free text here"
46
+ # theme:
47
+ # fields:
48
+ # background_image:
49
+ # type: image
50
+ # hint: full screen image (min: 3000px x 3000px)
51
+ # link_color:
52
+ # type: color
53
+ # font:
54
+ # type: select
55
+ # select_options: ['helvetica', 'Noto']
56
+
@@ -26,3 +26,17 @@ locales: [en]
26
26
  seo_title: <%= @name %>
27
27
  meta_keywords: "some meta keywords"
28
28
  meta_description: "some meta description"
29
+
30
+ # Each site can have its own set of custom properties organized in namespaces.
31
+ # First, define namespaces and their fields in the config/metafields_schema.yml file.
32
+ # Finally, set default values below as described in the example.
33
+ # You can access them in your liquid templates and snippets:
34
+ # {{ site.metafields.<namespace>.<field> }}
35
+ #
36
+ # Example:
37
+ #
38
+ # metafields:
39
+ # shop:
40
+ # address: 700 South Laflin Street
41
+ # theme:
42
+ # background_image: "/samples/background.png"
@@ -0,0 +1,56 @@
1
+ # Site metafield schema
2
+ #
3
+ # Syntax:
4
+ #
5
+ # - <namespace_1>: # no empty spaces, only digits and underscores
6
+ # label: <my label> # used as the label of a tab in the back-office
7
+ # # label: # if you want to provide the label in another language (back-office)
8
+ # # en: <your label in English if the local of the current user is English>
9
+ # # fr: <your label in French>
10
+ # position: <0..n> # position of the tab in the menu
11
+ # fields:
12
+ # <name_1>:
13
+ # label: <my label> # used as the label of the HTML input. Use a hash if you want it in another languages.
14
+ # hint: <my hint> # used as the hint of the HTML input. Use a hash if you want it in another languages.
15
+ # type: <string|text|integer|float|file|image|boolean|select|color>
16
+ # localized: <true|false> # if the value is scoped by the current locale when rendering the site.
17
+ # position: <0..n> # position of the input in the form
18
+ # select_options: [array]
19
+ # # select_options:
20
+ # # <option_value_1>: <label> # use a hash instead if you want it in another languages.
21
+ # # <option_value_2>: <label> # use a hash instead if you want it in another languages.
22
+ # # <name_2>:
23
+ # # ...
24
+ #
25
+ # - <namespace_2>:
26
+ # # ...
27
+ #
28
+ #
29
+ # Simple example:
30
+ #
31
+ # shop:
32
+ # label: My shop location
33
+ # fields:
34
+ # address:
35
+ # type: string
36
+ # hint: "Ex: 7 allee Albert Camus"
37
+ # city:
38
+ # type: string
39
+ # hint: "Chicago, Paris, Blagnac, Toulouse"
40
+ # zip_code:
41
+ # type: string
42
+ # hint: "Digits only"
43
+ # hours:
44
+ # type: text
45
+ # hint: "Free text here"
46
+ # theme:
47
+ # fields:
48
+ # background_image:
49
+ # type: image
50
+ # hint: full screen image (min: 3000px x 3000px)
51
+ # link_color:
52
+ # type: color
53
+ # font:
54
+ # type: select
55
+ # select_options: ['helvetica', 'Noto']
56
+
@@ -26,3 +26,17 @@ locales: [en]
26
26
  seo_title: <%= @name %>
27
27
  meta_keywords: "some meta keywords"
28
28
  meta_description: "some meta description"
29
+
30
+ # Each site can have its own set of custom properties organized in namespaces.
31
+ # First, define namespaces and their fields in the config/metafields_schema.yml file.
32
+ # Finally, set default values below as described in the example.
33
+ # You can access them in your liquid templates and snippets:
34
+ # {{ site.metafields.<namespace>.<field> }}
35
+ #
36
+ # Example:
37
+ #
38
+ # metafields:
39
+ # shop:
40
+ # address: 700 South Laflin Street
41
+ # theme:
42
+ # background_image: "/samples/background.png"
@@ -0,0 +1,56 @@
1
+ # Site metafield schema
2
+ #
3
+ # Syntax:
4
+ #
5
+ # - <namespace_1>: # no empty spaces, only digits and underscores
6
+ # label: <my label> # used as the label of a tab in the back-office
7
+ # # label: # if you want to provide the label in another language (back-office)
8
+ # # en: <your label in English if the local of the current user is English>
9
+ # # fr: <your label in French>
10
+ # position: <0..n> # position of the tab in the menu
11
+ # fields:
12
+ # <name_1>:
13
+ # label: <my label> # used as the label of the HTML input. Use a hash if you want it in another languages.
14
+ # hint: <my hint> # used as the hint of the HTML input. Use a hash if you want it in another languages.
15
+ # type: <string|text|integer|float|file|image|boolean|select|color>
16
+ # localized: <true|false> # if the value is scoped by the current locale when rendering the site.
17
+ # position: <0..n> # position of the input in the form
18
+ # select_options: [array]
19
+ # # select_options:
20
+ # # <option_value_1>: <label> # use a hash instead if you want it in another languages.
21
+ # # <option_value_2>: <label> # use a hash instead if you want it in another languages.
22
+ # # <name_2>:
23
+ # # ...
24
+ #
25
+ # - <namespace_2>:
26
+ # # ...
27
+ #
28
+ #
29
+ # Simple example:
30
+ #
31
+ # shop:
32
+ # label: My shop location
33
+ # fields:
34
+ # address:
35
+ # type: string
36
+ # hint: "Ex: 7 allee Albert Camus"
37
+ # city:
38
+ # type: string
39
+ # hint: "Chicago, Paris, Blagnac, Toulouse"
40
+ # zip_code:
41
+ # type: string
42
+ # hint: "Digits only"
43
+ # hours:
44
+ # type: text
45
+ # hint: "Free text here"
46
+ # theme:
47
+ # fields:
48
+ # background_image:
49
+ # type: image
50
+ # hint: full screen image (min: 3000px x 3000px)
51
+ # link_color:
52
+ # type: color
53
+ # font:
54
+ # type: select
55
+ # select_options: ['helvetica', 'Noto']
56
+
@@ -151,6 +151,15 @@ module Locomotive
151
151
  end
152
152
  end
153
153
 
154
+ desc 'site_metafields', 'Generate the missing file to describe the site metafields'
155
+ def site_metafields
156
+ force_color_if_asked(options)
157
+
158
+ if path = check_path!
159
+ Locomotive::Wagon.generate :site_metafields, [path], self.options
160
+ end
161
+ end
162
+
154
163
  protected
155
164
 
156
165
  # Read the YAML config file of a Locomotive site.
@@ -268,7 +277,8 @@ module Locomotive
268
277
  option :daemonize, aliases: '-d', type: 'boolean', default: false, desc: 'Run daemonized Thin server in the background'
269
278
  option :live_reload_port, aliases: '-l', type: 'string', default: '35729', desc: 'The port the LiveReload javascript lib needs to listen for changes (35729 by default)'
270
279
  option :force, aliases: '-f', type: 'boolean', default: false, desc: 'Stop the current daemonized Thin server if found before starting a new one'
271
- option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs'
280
+ option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'Display the full error stack trace if an error occurs'
281
+ option :debug, type: 'boolean', default: false, desc: 'Display some debugging information (rack middleware stack)'
272
282
  def serve(path = '.')
273
283
  force_color_if_asked(options)
274
284
  if check_path!(path)
@@ -8,9 +8,10 @@ module Locomotive::Wagon
8
8
  return @steam_services if @steam_services
9
9
 
10
10
  Locomotive::Steam.configure do |config|
11
- config.mode = :test
12
- config.adapter = { name: :filesystem, path: path }
13
- config.asset_path = File.expand_path(File.join(path, 'public'))
11
+ config.mode = :test
12
+ config.adapter = { name: :filesystem, path: path }
13
+ config.asset_path = File.expand_path(File.join(path, 'public'))
14
+ config.minify_assets = true
14
15
  end
15
16
 
16
17
  @steam_services = Locomotive::Steam::Services.build_instance.tap do |services|
@@ -62,7 +62,7 @@ module Locomotive::Wagon
62
62
  end
63
63
 
64
64
  def print_result_message
65
- shell.say "\n\nThe templates, theme assets and content have been pulled from the remote version.", :green
65
+ shell.try(:say, "\n\nThe templates, theme assets and content have been pulled from the remote version.", :green)
66
66
  true
67
67
  end
68
68
 
@@ -1,5 +1,7 @@
1
1
  require 'tempfile'
2
2
 
3
+ require_relative '../../../tools/yaml_ext.rb'
4
+
3
5
  module Locomotive::Wagon
4
6
 
5
7
  module AssetsConcern
@@ -30,6 +32,12 @@ module Locomotive::Wagon
30
32
  end
31
33
  end
32
34
 
35
+ def replace_asset_urls_in_hash(hash)
36
+ Locomotive::Wagon::YamlExt.transform(hash) do |value|
37
+ replace_asset_urls(value)
38
+ end
39
+ end
40
+
33
41
  private
34
42
 
35
43
  def find_unique_filepath(filepath, binary_file, index = 1)
@@ -3,7 +3,7 @@ module Locomotive::Wagon
3
3
  class PullSiteCommand < PullBaseCommand
4
4
 
5
5
  def _pull
6
- attributes = current_site.attributes.slice('name', 'locales', 'domains', 'timezone', 'seo_title', 'meta_keywords', 'meta_description', 'picture_thumbnail_url')
6
+ attributes = current_site.attributes.slice('name', 'locales', 'domains', 'timezone', 'seo_title', 'meta_keywords', 'meta_description', 'picture_thumbnail_url', 'metafields', 'metafields_schema')
7
7
 
8
8
  locales.each_with_index do |locale, index|
9
9
  if index == 0
@@ -13,6 +13,10 @@ module Locomotive::Wagon
13
13
  end
14
14
  end if locales.size > 1
15
15
 
16
+ decode_metafields(attributes)
17
+
18
+ write_metafields_schema(attributes.delete('metafields_schema'))
19
+
16
20
  write_icon(attributes.delete('picture_thumbnail_url'))
17
21
 
18
22
  write_to_file(File.join('config', 'site.yml')) do
@@ -35,6 +39,25 @@ module Locomotive::Wagon
35
39
  end
36
40
  end
37
41
 
42
+ def write_metafields_schema(schema)
43
+ return if schema.blank?
44
+
45
+ File.open(File.join(path, 'config', 'metafields_schema.yml'), 'wb') do |file|
46
+ file.write JSON.parse(schema).to_yaml
47
+ end
48
+ end
49
+
50
+ def decode_metafields(attributes)
51
+ metafields = attributes['metafields']
52
+
53
+ return if metafields.blank?
54
+
55
+ # metafields come under a JSON string format.
56
+ metafields = JSON.parse(metafields)
57
+
58
+ attributes['metafields'] = replace_asset_urls_in_hash(metafields)
59
+ end
60
+
38
61
  def localized_attributes(&block)
39
62
  %w(seo_title meta_keywords meta_description).each do |name|
40
63
  yield(name)
@@ -7,7 +7,9 @@ module Locomotive::Wagon
7
7
  end
8
8
 
9
9
  def decorate(entity)
10
- UpdateSiteDecorator.new(entity)
10
+ UpdateSiteDecorator.new(entity).tap do |decorator|
11
+ decorator.__content_assets_pusher__ = self.content_assets_pusher
12
+ end
11
13
  end
12
14
 
13
15
  def persist(decorated_entity)
@@ -28,6 +28,8 @@ module Locomotive::Wagon
28
28
  setup_signals
29
29
 
30
30
  show_start_message
31
+
32
+ show_rack_middleware_stack if options[:debug]
31
33
  end
32
34
 
33
35
  # if a page, a content type or any resources of the site is getting modified,
@@ -132,6 +134,9 @@ module Locomotive::Wagon
132
134
  end
133
135
 
134
136
  def configure_logger
137
+ # make sure the logs folder exist and get rid of that ugly error message if it doesn't
138
+ FileUtils.mkdir_p(File.join(path, 'log'))
139
+
135
140
  Locomotive::Common.reset
136
141
  Locomotive::Common.configure do |config|
137
142
  logger = options[:daemonize] ? log_file : nil
@@ -176,6 +181,16 @@ module Locomotive::Wagon
176
181
  File.expand_path(File.join(path, 'log', 'wagon.log'))
177
182
  end
178
183
 
184
+ def show_rack_middleware_stack
185
+ shell.say "[Rendering stack]".colorize(color: :light_white, background: :blue)
186
+
187
+ Locomotive::Steam.configuration.middleware.list.each do |middleware|
188
+ shell.say "\t" + middleware.first.first.inspect
189
+ end
190
+
191
+ shell.say "\n"
192
+ end
193
+
179
194
  def show_start_message
180
195
  shell.say "Your site is served now.\nBrowse http://#{options[:host]}:#{options[:port]}\n\n", :green
181
196
  end
@@ -15,7 +15,7 @@ module Locomotive::Wagon
15
15
 
16
16
  class SyncCommand < Struct.new(:env, :path, :options, :shell)
17
17
 
18
- RESOURCES = %w(pages content_entries translations).freeze
18
+ RESOURCES = %w(site pages content_entries translations).freeze
19
19
 
20
20
  include ApiConcern
21
21
  include DeployFileConcern
@@ -0,0 +1,31 @@
1
+ module Locomotive::Wagon
2
+
3
+ class SyncSiteCommand < PullSiteCommand
4
+
5
+ include Locomotive::Wagon::BaseConcern
6
+
7
+ def _sync
8
+ attributes = current_site.attributes.slice('metafields')
9
+
10
+ # convert to hash + download assets and use the asset local version
11
+ decode_metafields(attributes)
12
+
13
+ # modify the config/site.yml file accordingly
14
+ replace_metafields_in_file(attributes['metafields'])
15
+ end
16
+
17
+ protected
18
+
19
+ def replace_metafields_in_file(metafields)
20
+ return if metafields.blank?
21
+
22
+ content = File.read(File.join(path, 'config', 'site.yml'))
23
+
24
+ content.gsub!(/^metafields:\n.+\n\s+.*?\n/m, { 'metafields' => metafields }.to_yaml.to_s.gsub(/\A---\n/, ''))
25
+
26
+ File.write(File.join(path, 'config', 'site.yml'), content)
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -1,3 +1,5 @@
1
+ require_relative '../../tools/yaml_ext.rb'
2
+
1
3
  module Locomotive::Wagon
2
4
 
3
5
  module PersistAssetsConcern
@@ -11,6 +13,12 @@ module Locomotive::Wagon
11
13
  end
12
14
  end
13
15
 
16
+ def replace_with_content_assets_in_hash!(hash)
17
+ Locomotive::Wagon::YamlExt.transform(hash) do |value|
18
+ replace_with_content_assets!(value)
19
+ end
20
+ end
21
+
14
22
  def asset_io(local_path)
15
23
  __content_assets_pusher__.decorate(local_path).source
16
24
  end
@@ -45,6 +45,7 @@ module Locomotive
45
45
  end
46
46
 
47
47
  def decorate_date_time_field(value)
48
+ return nil if value.nil?
48
49
  value.utc.try(:iso8601)
49
50
  end
50
51
 
@@ -4,11 +4,23 @@ module Locomotive
4
4
  class SiteDecorator < SimpleDelegator
5
5
 
6
6
  include ToHashConcern
7
+ include PersistAssetsConcern
8
+
9
+ attr_accessor :__content_assets_pusher__
7
10
 
8
11
  def domains
9
12
  (__getobj__.domains || []) - ['localhost']
10
13
  end
11
14
 
15
+ def metafields_schema
16
+ self[:metafields_schema].try(:to_json)
17
+ end
18
+
19
+ def metafields
20
+ replace_with_content_assets_in_hash!(self[:metafields])
21
+ self[:metafields].try(:to_json)
22
+ end
23
+
12
24
  def picture
13
25
  picture_path = __getobj__.picture
14
26
  if picture_path && File.exists?(picture_path)
@@ -18,7 +30,7 @@ module Locomotive
18
30
  end
19
31
  end
20
32
 
21
- %i(robots_txt timezone seo_title meta_keywords meta_description metafields_schema metafields).each do |name|
33
+ %i(robots_txt timezone seo_title meta_keywords meta_description).each do |name|
22
34
  define_method(name) do
23
35
  self[name]
24
36
  end
@@ -0,0 +1,54 @@
1
+ require 'thor/group'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ module Locomotive
6
+ module Wagon
7
+ module Generators
8
+ class SiteMetafields < Thor::Group
9
+
10
+ include Thor::Actions
11
+ include Locomotive::Wagon::CLI::ForceColor
12
+
13
+ argument :target_path # path to the site
14
+
15
+ def create_metafields_schema
16
+ path = File.join(target_path, 'config', 'metafields_schema.yml')
17
+
18
+ template 'schema.yml.tt', path
19
+ end
20
+
21
+ def add_instructions
22
+ append_to_file 'config/site.yml', <<-EOF
23
+
24
+ # Each site can have its own set of custom properties organized in namespaces.
25
+ # First, define namespaces and their fields in the config/metafields_schema.yml file.
26
+ # Finally, set default values below as described in the example.
27
+ # You can access them in your liquid templates and snippets:
28
+ # {{ site.metafields.<namespace>.<field> }}
29
+ #
30
+ # Example:
31
+ #
32
+ # metafields:
33
+ # shop:
34
+ # address: 700 South Laflin Street
35
+ # theme:
36
+ # background_image: "/samples/background.png"
37
+ EOF
38
+ end
39
+
40
+ def self.source_root
41
+ File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'generators', 'site_metafields')
42
+ end
43
+
44
+ protected
45
+
46
+ def snippets_path
47
+ File.join(target_path, 'app', 'views', 'snippets')
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,21 @@
1
+ module Locomotive
2
+ module Wagon
3
+
4
+ module YamlExt
5
+
6
+ def self.transform(hash, &block)
7
+ return if hash.blank? || !hash.respond_to?(:has_key?)
8
+
9
+ hash.each do |key, value|
10
+ case value
11
+ when Hash then transform(value, &block)
12
+ when Array then value.each { |v| transform(v, &block) }
13
+ when String then hash[key] = yield(value)
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  module Locomotive
2
2
  module Wagon
3
- VERSION = '2.0.1'
3
+ VERSION = '2.1.0.rc3'
4
4
  end
5
5
  end