Class: ERB::Processor::ForSingleFile
- Inherits:
-
Object
- Object
- ERB::Processor::ForSingleFile
- Defined in:
- lib/erb/processor/for_single_file.rb
Overview
Processes a single file template
Constant Summary collapse
- ERB_TEMPLATE_REGEX =
/.erb$/i- FOR_WRITING =
"w+"
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#template_path ⇒ Object
readonly
Returns the value of attribute template_path.
Class Method Summary collapse
Instance Method Summary collapse
- #commented_processed_header ⇒ Object
-
#initialize(template_path) ⇒ ForSingleFile
constructor
A new instance of ForSingleFile.
- #processed_content ⇒ Object
- #processed_header ⇒ Object
- #processed_path ⇒ Object
- #run ⇒ Object
- #template_content ⇒ Object
Constructor Details
#initialize(template_path) ⇒ ForSingleFile
Returns a new instance of ForSingleFile.
19 20 21 22 |
# File 'lib/erb/processor/for_single_file.rb', line 19 def initialize(template_path) @logger = Logging.logger[self] @template_path = template_path end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
17 18 19 |
# File 'lib/erb/processor/for_single_file.rb', line 17 def logger @logger end |
#template_path ⇒ Object (readonly)
Returns the value of attribute template_path.
17 18 19 |
# File 'lib/erb/processor/for_single_file.rb', line 17 def template_path @template_path end |
Class Method Details
.template_file?(path) ⇒ Boolean
13 14 15 |
# File 'lib/erb/processor/for_single_file.rb', line 13 def self.template_file?(path) ERB_TEMPLATE_REGEX.match?(path) end |
Instance Method Details
#commented_processed_header ⇒ Object
45 46 47 |
# File 'lib/erb/processor/for_single_file.rb', line 45 def commented_processed_header LanguageCommenter.new(processed_path, processed_header).commented_text end |
#processed_content ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/erb/processor/for_single_file.rb', line 37 def processed_content erb_processor = self ERB.new(template_content, trim_mode: "<>-").result binding rescue StandardError => e raise e.class, "\n#{template_path}:0: #{e}", e.backtrace end |
#processed_header ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/erb/processor/for_single_file.rb', line 49 def processed_header "\n WARNING: DO NOT EDIT directly\n\n HOWTO Modify this file\n 1. Edit the file \#{template_path}\n 2. $ erb-processor .\n\n PROCESSED_HEADER\nend\n" |
#processed_path ⇒ Object
33 34 35 |
# File 'lib/erb/processor/for_single_file.rb', line 33 def processed_path template_path.sub(ERB_TEMPLATE_REGEX, "") end |
#run ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/erb/processor/for_single_file.rb', line 25 def run logger.info { "Processing #{template_path}..." } File.open(processed_path, FOR_WRITING) do |output| output.print processed_content end logger.info { "Wrote #{processed_path}" } end |
#template_content ⇒ Object
61 62 63 |
# File 'lib/erb/processor/for_single_file.rb', line 61 def template_content File.read(template_path) end |