Class: Locomotive::Wagon::Generators::PublicForm

Inherits:
Thor::Group
  • Object
show all
Includes:
CLI::ForceColor, Thor::Actions
Defined in:
lib/locomotive/wagon/generators/public_form.rb

Instance Method Summary collapse

Methods included from CLI::ForceColor

#force_color_if_asked

Instance Method Details

#add_metafieldsObject



56
57
58
59
60
61
62
63
64
# File 'lib/locomotive/wagon/generators/public_form.rb', line 56

def add_metafields
  append_to_file 'config/site.yml', <<-YAML

metafields:
  google:
    recaptcha_site_key: "<GOOGLE SITE KEY>"
    recaptcha_secret: "<GOOGLE SECRET>"
  YAML
end

#add_metafields_schemaObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/locomotive/wagon/generators/public_form.rb', line 40

def add_metafields_schema
  append_to_file 'config/metafields_schema.yml', <<-YAML

google:
  label: Google API Integration
  fields:
    recaptcha_site_key:
      hint: reCAPTCHA - Site key
      type: string
      hint: "Visit: https://developers.google.com/recaptcha/intro"
    recaptcha_secret:
      hint: reCAPTCHA - Secret key
      type: string
  YAML
end

#create_content_typeObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/locomotive/wagon/generators/public_form.rb', line 15

def create_content_type
  slug = ask("What's the slug of the content type? (ex.: user_messages)")
  @content_type_slug = slug = slug.underscore

  file_path = File.join(content_types_path, slug)

  template "content_type.yml.tt", "#{file_path}.yml", {
    name: slug.humanize,
    slug: slug
  }
end

#create_page_formObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/locomotive/wagon/generators/public_form.rb', line 27

def create_page_form
  slug = ask("What's the slug of your page? (ex.: contact-us)")
  slug = slug.dasherize

  file_path = File.join(pages_path, slug)

  template "page.liquid.tt", "#{file_path}.liquid", {
    title:        slug.humanize,
    handle:       slug.underscore,
    content_type: @content_type_slug
  }
end


66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/locomotive/wagon/generators/public_form.rb', line 66

def print_next_instructions
  say <<-TEXT

Congratulations, your public form has been generated with success!

In order to complete the Google reCAPTCHA configuration, visit https://developers.google.com/recaptcha/intro.
Create a developer account if you don't have one and register your site.

Once done, copy and paste your Google SITE KEY and Google SECRET KEY in the config/site.yml file.

TEXT
end