Class: ConvertorFile
- Inherits:
-
Object
- Object
- ConvertorFile
- Defined in:
- lib/convertor-file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#current_dir ⇒ Object
readonly
Returns the value of attribute current_dir.
-
#current_file ⇒ Object
readonly
Returns the value of attribute current_file.
-
#original_dir ⇒ Object
readonly
Returns the value of attribute original_dir.
-
#original_file ⇒ Object
readonly
Returns the value of attribute original_file.
Instance Method Summary collapse
- #copy(path) ⇒ Object
- #extract_to_partials(destination) ⇒ Object
- #find_and_replace(find, replace) ⇒ Object
-
#initialize(path) ⇒ ConvertorFile
constructor
A new instance of ConvertorFile.
Constructor Details
#initialize(path) ⇒ ConvertorFile
Returns a new instance of ConvertorFile.
7 8 9 10 11 12 13 |
# File 'lib/convertor-file.rb', line 7 def initialize(path) @original_dir = @current_dir = File.dirname(path) @original_file = @current_file = path @contents = File.new(path).read @convertor_tag = ConvertorTag.new(@contents) end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
5 6 7 |
# File 'lib/convertor-file.rb', line 5 def contents @contents end |
#current_dir ⇒ Object (readonly)
Returns the value of attribute current_dir.
5 6 7 |
# File 'lib/convertor-file.rb', line 5 def current_dir @current_dir end |
#current_file ⇒ Object (readonly)
Returns the value of attribute current_file.
5 6 7 |
# File 'lib/convertor-file.rb', line 5 def current_file @current_file end |
#original_dir ⇒ Object (readonly)
Returns the value of attribute original_dir.
5 6 7 |
# File 'lib/convertor-file.rb', line 5 def original_dir @original_dir end |
#original_file ⇒ Object (readonly)
Returns the value of attribute original_file.
5 6 7 |
# File 'lib/convertor-file.rb', line 5 def original_file @original_file end |
Instance Method Details
#copy(path) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/convertor-file.rb', line 15 def copy(path) FileUtils.mkdir_p(File.dirname(path)) FileUtils.copy(@current_file, path) @current_dir = File.dirname(path) @current_file = path end |
#extract_to_partials(destination) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/convertor-file.rb', line 23 def extract_to_partials(destination) FileUtils.mkdir_p(destination) @convertor_tag..each do |tag| File.open(destination + "_#{tag}.html.erb", "w") do |f| f.write @convertor_tag.text_inside_tag(tag) find_and_replace(@convertor_tag.text_with_tag(tag), "<%= render :partial => 'shared/#{tag}' %>") end end end |
#find_and_replace(find, replace) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/convertor-file.rb', line 34 def find_and_replace(find, replace) @contents.gsub!(find, replace) File.open(@current_file, "w") do |f| f.write @contents end end |