Class: Html2fortitude::SourceTemplate
- Inherits:
-
Object
- Object
- Html2fortitude::SourceTemplate
- Defined in:
- lib/html2fortitude/source_template.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#line_count ⇒ Object
readonly
Returns the value of attribute line_count.
Instance Method Summary collapse
-
#initialize(filename, contents, options) ⇒ SourceTemplate
constructor
A new instance of SourceTemplate.
- #output_filename ⇒ Object
- #write_transformed_content! ⇒ Object
Constructor Details
#initialize(filename, contents, options) ⇒ SourceTemplate
Returns a new instance of SourceTemplate.
7 8 9 10 11 12 13 14 15 |
# File 'lib/html2fortitude/source_template.rb', line 7 def initialize(filename, contents, ) .assert_valid_keys(:output, :class_name, :class_base, :superclass, :method, :assigns, :do_end, :new_style_hashes) @filename = filename @contents = contents @options = @line_count = @contents.split(/(\r|\n|\r\n)/).length end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/html2fortitude/source_template.rb', line 5 def filename @filename end |
#line_count ⇒ Object (readonly)
Returns the value of attribute line_count.
5 6 7 |
# File 'lib/html2fortitude/source_template.rb', line 5 def line_count @line_count end |
Instance Method Details
#output_filename ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/html2fortitude/source_template.rb', line 37 def output_filename if (! [:output]) && (filename == "-") "-" elsif (! [:output]) if filename =~ /^(.*)\.html\.erb$/i || filename =~ /^(.*)\.rhtml$/i "#{$1}.rb" else "#{filename}.rb" end elsif File.directory?([:output]) File.join(File.([:output]), "#{output_class_name.underscore}.rb") else File.([:output]) end end |
#write_transformed_content! ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/html2fortitude/source_template.rb', line 17 def write_transformed_content! = { :class_name => output_class_name, :superclass => [:superclass], :method => [:method], :assigns => [:assigns], :do_end => [:do_end], :new_style_hashes => [:new_style_hashes] } html = HTML.new(contents, ).render if output_filename == '-' puts html else FileUtils.mkdir_p(File.dirname(output_filename)) File.open(output_filename, 'w') { |f| f << html } end end |