Class: Pakyow::Generator::File
- Inherits:
-
Object
- Object
- Pakyow::Generator::File
- Includes:
- Common, Support::Pipeline::Object
- Defined in:
- lib/pakyow/generator.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#context ⇒ Object
Returns the value of attribute context.
-
#logical_path ⇒ Object
Returns the value of attribute logical_path.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #generate(destination_path, options) ⇒ Object
-
#initialize(path, source_path, context: self) ⇒ File
constructor
A new instance of File.
Methods included from Common
Constructor Details
#initialize(path, source_path, context: self) ⇒ File
Returns a new instance of File.
65 66 67 68 69 70 71 72 73 |
# 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 |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
63 64 65 |
# File 'lib/pakyow/generator.rb', line 63 def content @content end |
#context ⇒ Object
Returns the value of attribute context.
63 64 65 |
# File 'lib/pakyow/generator.rb', line 63 def context @context end |
#logical_path ⇒ Object
Returns the value of attribute logical_path.
63 64 65 |
# File 'lib/pakyow/generator.rb', line 63 def logical_path @logical_path end |
#path ⇒ Object
Returns the value of attribute path.
63 64 65 |
# File 'lib/pakyow/generator.rb', line 63 def path @path end |
Instance Method Details
#generate(destination_path, options) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/pakyow/generator.rb', line 75 def generate(destination_path, ) .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 |