Class: Village::Generators::ArticlesGenerator
- Defined in:
- lib/generators/village/articles/articles_generator.rb
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#check_date ⇒ Object
17 18 19 20 21 22 |
# File 'lib/generators/village/articles/articles_generator.rb', line 17 def check_date if .date && .date !~ /^\d{4}-\d{2}-\d{2}$/ puts 'Invalid date - please use the following format: YYYY-MM-DD, eg. 2011-01-01.' exit end end |
#check_slug ⇒ Object
10 11 12 13 14 15 |
# File 'lib/generators/village/articles/articles_generator.rb', line 10 def check_slug unless slug =~ /^[A-Za-z0-9\-\.]+$/ puts 'Invalid slug - valid characters include letters, digits and dashes.' exit end end |
#generate_article ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/generators/village/articles/articles_generator.rb', line 24 def generate_article @date_str, @slug, @extension = File.basename(filename).match(/^(\d+-\d+-\d+)-(.*)(\.[^.]+)$/).captures create_file "app/views/articles/#{@date_str}-#{@slug}#{@extension}" do "---\n" + "title: #{@slug.titleize}\n" + "summary: summary goes here ...\n" + "categories: ['category']\n" + "tags: ['tag']\n" + "---\n\n" + "CONTENT GOES HERE ..." end end |