Class: Postnhost::Generators::StaticPagesGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/postnhost/static_pages/static_pages_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_static_pagesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/postnhost/static_pages/static_pages_generator.rb', line 8

def create_static_pages
  if slugs.empty?
    say("Please provide at least one page slug, e.g. bin/rails g postnhost:static_pages terms privacy", :red)
    return
  end

  slugs.each do |raw_slug|
    slug = raw_slug.to_s.strip
    unless valid_slug?(slug)
      say("Skipping invalid slug '#{raw_slug}'. Use lowercase letters, numbers, underscores, or hyphens.", :yellow)
      next
    end

    title = slug.tr("_-", " ").split.map(&:capitalize).join(" ")
    create_file "app/views/postnhost/static_pages/#{slug}.html.erb", static_page_template(slug, title)
  end
end