Class: Middleman::Cli::Article
- Inherits:
-
Thor
- Object
- Thor
- Middleman::Cli::Article
- Includes:
- Thor::Actions
- Defined in:
- lib/middleman-blog/commands/article.rb
Overview
This class provides an “article” command for the middleman CLI.
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Tell Thor to exit with a nonzero exit code on failure.
-
.source_root ⇒ String
Template files are relative to this file.
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
Tell Thor to exit with a nonzero exit code on failure
21 22 23 |
# File 'lib/middleman-blog/commands/article.rb', line 21 def self.exit_on_failure? true end |
.source_root ⇒ String
Template files are relative to this file
16 17 18 |
# File 'lib/middleman-blog/commands/article.rb', line 16 def self.source_root File.dirname(__FILE__) end |
Instance Method Details
#article(title) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/middleman-blog/commands/article.rb', line 29 def article(title) shared_instance = ::Middleman::Application.server.inst # This only exists when the config.rb sets it! if shared_instance.respond_to? :blog @title = title @slug = title.parameterize @date = [:date] ? Time.zone.parse([:date]) : Time.zone.now article_path = shared_instance.blog..sources. sub(':year', @date.year.to_s). sub(':month', @date.month.to_s.rjust(2,'0')). sub(':day', @date.day.to_s.rjust(2,'0')). sub(':title', @slug) template "article.tt", File.join(shared_instance.source_dir, article_path + shared_instance.blog..default_extension) else raise Thor::Error.new "You need to activate the blog extension in config.rb before you can create an article" end end |