new generator to initialize the site metafields schema
did
committed Mar 04, 2016
commit 4306934d55165962aee72e19af95896748d05d2d
Showing 3
changed files with
119 additions
and 0 deletions
generators/site_metafields/schema.yml.tt
+56
-0
| @@ | @@ -0,0 +1,56 @@ |
| + | # Site metafield schema |
| + | # |
| + | # Syntax: |
| + | # |
| + | # - <namespace_1>: # no empty spaces, only digits and underscores |
| + | # label: <my label> # used as the label of a tab in the back-office |
| + | # # label: # if you want to provide the label in another language (back-office) |
| + | # # en: <your label in English if the local of the current user is English> |
| + | # # fr: <your label in French> |
| + | # position: <0..n> # position of the tab in the menu |
| + | # fields: |
| + | # <name_1>: |
| + | # label: <my label> # used as the label of the HTML input. Use a hash if you want it in another languages. |
| + | # hint: <my hint> # used as the hint of the HTML input. Use a hash if you want it in another languages. |
| + | # type: <string|text|integer|float|file|image|boolean|select|color> |
| + | # localized: <true|false> # if the value is scoped by the current locale when rendering the site. |
| + | # position: <0..n> # position of the input in the form |
| + | # select_options: [array] |
| + | # # select_options: |
| + | # # <option_value_1>: <label> # use a hash instead if you want it in another languages. |
| + | # # <option_value_2>: <label> # use a hash instead if you want it in another languages. |
| + | # # <name_2>: |
| + | # # ... |
| + | # |
| + | # - <namespace_2>: |
| + | # # ... |
| + | # |
| + | # |
| + | # Simple example: |
| + | # |
| + | # shop: |
| + | # label: My shop location |
| + | # fields: |
| + | # address: |
| + | # type: string |
| + | # hint: "Ex: 7 allee Albert Camus" |
| + | # city: |
| + | # type: string |
| + | # hint: "Chicago, Paris, Blagnac, Toulouse" |
| + | # zip_code: |
| + | # type: string |
| + | # hint: "Digits only" |
| + | # hours: |
| + | # type: text |
| + | # hint: "Free text here" |
| + | # theme: |
| + | # fields: |
| + | # background_image: |
| + | # type: image |
| + | # hint: full screen image (min: 3000px x 3000px) |
| + | # link_color: |
| + | # type: color |
| + | # font: |
| + | # type: select |
| + | # select_options: ['helvetica', 'Noto'] |
| + | |
locomotive/wagon/cli.rb b/lib/locomotive/wagon/cli.rb
+9
-0
| @@ | @@ -151,6 +151,15 @@ module Locomotive |
| end | |
| end | |
| + | desc 'site_metafields', 'Generate the missing file to describe the site metafields' |
| + | def site_metafields |
| + | force_color_if_asked(options) |
| + | |
| + | if path = check_path! |
| + | Locomotive::Wagon.generate :site_metafields, [path], self.options |
| + | end |
| + | end |
| + | |
| protected | |
| # Read the YAML config file of a Locomotive site. | |
locomotive/wagon/generators/site_metafields.rb b/lib/locomotive/wagon/generators/site_metafields.rb
+54
-0
| @@ | @@ -0,0 +1,54 @@ |
| + | require 'thor/group' |
| + | require 'active_support' |
| + | require 'active_support/core_ext' |
| + | |
| + | module Locomotive |
| + | module Wagon |
| + | module Generators |
| + | class SiteMetafields < Thor::Group |
| + | |
| + | include Thor::Actions |
| + | include Locomotive::Wagon::CLI::ForceColor |
| + | |
| + | argument :target_path # path to the site |
| + | |
| + | def create_metafields_schema |
| + | path = File.join(target_path, 'config', 'metafields_schema.yml') |
| + | |
| + | template 'schema.yml.tt', path |
| + | end |
| + | |
| + | def add_instructions |
| + | append_to_file 'config/site.yml', <<-EOF |
| + | |
| + | # Each site can have its own set of custom properties organized in namespaces. |
| + | # First, define namespaces and their fields in the config/metafields_schema.yml file. |
| + | # Finally, set default values below as described in the example. |
| + | # You can access them in your liquid templates and snippets: |
| + | # {{ site.metafields.<namespace>.<field> }} |
| + | # |
| + | # Example: |
| + | # |
| + | # metafields: |
| + | # shop: |
| + | # address: 700 South Laflin Street |
| + | # theme: |
| + | # background_image: "/samples/background.png" |
| + | EOF |
| + | end |
| + | |
| + | def self.source_root |
| + | File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'generators', 'site_metafields') |
| + | end |
| + | |
| + | protected |
| + | |
| + | def snippets_path |
| + | File.join(target_path, 'app', 'views', 'snippets') |
| + | end |
| + | |
| + | end |
| + | |
| + | end |
| + | end |
| + | end |