Class: Middleman::Cli::Article
- Inherits:
-
Thor
- Object
- Thor
- Middleman::Cli::Article
- Includes:
- Blog::UriTemplates, 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 ⇒ Object
Instance Method Summary collapse
Methods included from Blog::UriTemplates
apply_uri_template, date_to_params, safe_parameterize, uri_template
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 ⇒ Object
16 17 18 |
# File 'lib/middleman-blog/commands/article.rb', line 16 def self.source_root ENV['MM_ROOT'] end |
Instance Method Details
#article(title) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/middleman-blog/commands/article.rb', line 35 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 = safe_parameterize(title) @date = [:date] ? Time.zone.parse([:date]) : Time.zone.now @lang = [:lang] || ( I18n.default_locale if defined? I18n ) blog_inst = shared_instance.blog([:blog]) path_template = blog_inst.source_template params = date_to_params(@date).merge(lang: @lang.to_s, title: @slug) article_path = apply_uri_template path_template, params template blog_inst..new_article_template, File.join(shared_instance.source_dir, article_path + blog_inst..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 |