Class: Middleman::Cli::Tansu
- Inherits:
-
Thor
- Object
- Thor
- Middleman::Cli::Tansu
- Includes:
- Thor::Actions
- Defined in:
- lib/middleman-tansu/command.rb
Overview
This class provides a “tansu” command for middleman CLI.
“tansu” command has some options:
-
‘-f’: set file extension, default “md”
-
‘-d’: set date(yyyy-mm-dd). Default is now. This is used in Frontmatter.
-
‘-a’: set author name. Default “ENV”.
-
‘-z’: set timezone.
-
‘–frontmatter’: add data to Frontmatter
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
-
#initialize(*args) ⇒ Tansu
constructor
A new instance of Tansu.
- #tansu(path) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Tansu
Returns a new instance of Tansu.
21 22 23 24 |
# File 'lib/middleman-tansu/command.rb', line 21 def initialize(*args) super Time.zone = ENV['TZ'] || 'UTC' end |
Class Method Details
.exit_on_failure? ⇒ Boolean
Tell Thor to exit with a nonzero exit code on failure
31 32 33 |
# File 'lib/middleman-tansu/command.rb', line 31 def self.exit_on_failure? true end |
.source_root ⇒ Object
26 27 28 |
# File 'lib/middleman-tansu/command.rb', line 26 def self.source_root ENV['MM_ROOT'] end |
Instance Method Details
#tansu(path) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/middleman-tansu/command.rb', line 53 def tansu(path) paths = path.split('/') title = paths.pop ext = [:file] Time.zone = [:timezone] || ENV['TZ'] || 'UTC' date = [:date] ? Time.zone.parse([:date]) : Time.zone.now = [:author] || ENV['USER'] add_frontmatter = [:frontmatter] if Regexp.new(".html.#{ext}$") !~ title filename = "#{title}.html.#{ext}" end dir = destination_dir(paths) file = File.join(dir, filename) FileUtils.mkdir_p dir unless Dir.exist?(dir) if File.exist?(file) say "#{display_path(file)} is exist" exit end File.open(file, 'w') do |f| f.puts frontmatter(title, , date, add_frontmatter) end say "create tansu page: #{display_path(file)}" end |