Class: Hanmoto::Task
- Inherits:
-
Object
- Object
- Hanmoto::Task
- Defined in:
- lib/hanmoto/task.rb
Constant Summary collapse
- EXTENSIONS =
{ text: 'txt', }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(view_dir:, layouts: {}) ⇒ Task
constructor
A new instance of Task.
- #run ⇒ Object
Constructor Details
#initialize(view_dir:, layouts: {}) ⇒ Task
Returns a new instance of Task.
13 14 15 16 |
# File 'lib/hanmoto/task.rb', line 13 def initialize(view_dir:, layouts: {}) @view_dir = view_dir @layouts = layouts end |
Class Method Details
.run(**args) ⇒ Object
9 10 11 |
# File 'lib/hanmoto/task.rb', line 9 def self.run(**args) new(**args).run end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hanmoto/task.rb', line 18 def run Dir.foreach(Rails.root.join('app', 'views', @view_dir)) do |file| next if file.start_with?('.') name, format = file.split('.', 3) layout = @layouts[format.to_sym] body = ApplicationController.renderer.render("#{@view_dir}/#{name}", layout: layout) path = output_path(name, format) File.write(path, body) ::Logger.new(::STDOUT).info("Writing #{path}") end end |