class Pakyow::Generator::File
Attributes
content[RW]
context[RW]
logical_path[RW]
path[RW]
Public Class Methods
new(path, source_path, context: self)
click to toggle source
# File lib/pakyow/generator.rb, line 65 def initialize(path, source_path, context: self) @path, @context = path, context @logical_path = Pathname.new(path).relative_path_from( Pathname.new(source_path) ).to_s @content = ::File.read(@path) end
Public Instance Methods
generate(destination_path, options)
click to toggle source
# File lib/pakyow/generator.rb, line 75 def generate(destination_path, options) options.each do |key, value| @context.instance_variable_set(:"@#{key}", value) end # Process the file. # Processor.new.call(self) # Build the generated file path. # destination_path_for_file = ::File.join(destination_path, @logical_path) # Make sure the directory exists. # FileUtils.mkdir_p(::File.dirname(destination_path_for_file)) # Skip keep files. # unless ::File.basename(@logical_path) == "keep" # Write the file. # ::File.open(destination_path_for_file, "w+") do |file| file.write(@content) end end end