Module: Bebox::FilesHelper
- Included in:
- Environment, Node, Profile, Project, Provision, Role, VagrantHelper
- Defined in:
- lib/bebox/files_helper.rb
Class Method Summary collapse
- .included(base) ⇒ Object
-
.templates_path ⇒ Object
Get the templates path inside the gem.
Instance Method Summary collapse
-
#file_content_trimmed(path) ⇒ Object
Get the content of a file with trimmed spaces.
-
#generate_file_from_template(template_path, file_path, options) ⇒ Object
Generate a file from a template.
-
#render_erb_template(template_path, options) ⇒ Object
Render a template for file content.
-
#write_content_to_file(file_path, content) ⇒ Object
Write content to a file.
Class Method Details
.included(base) ⇒ Object
5 6 7 |
# File 'lib/bebox/files_helper.rb', line 5 def self.included(base) base.extend(self) end |
.templates_path ⇒ Object
Get the templates path inside the gem
33 34 35 |
# File 'lib/bebox/files_helper.rb', line 33 def self.templates_path File.join((File. '..', File.dirname(__FILE__)), 'templates') end |
Instance Method Details
#file_content_trimmed(path) ⇒ Object
Get the content of a file with trimmed spaces
28 29 30 |
# File 'lib/bebox/files_helper.rb', line 28 def file_content_trimmed(path) File.read(path).gsub(/\s+/, ' ').strip end |
#generate_file_from_template(template_path, file_path, options) ⇒ Object
Generate a file from a template
10 11 12 |
# File 'lib/bebox/files_helper.rb', line 10 def generate_file_from_template(template_path, file_path, ) write_content_to_file(file_path, render_erb_template(template_path, )) end |
#render_erb_template(template_path, options) ⇒ Object
Render a template for file content
15 16 17 18 |
# File 'lib/bebox/files_helper.rb', line 15 def render_erb_template(template_path, ) require 'tilt' Tilt::ERBTemplate.new(template_path).render(nil, ) end |
#write_content_to_file(file_path, content) ⇒ Object
Write content to a file
21 22 23 24 25 |
# File 'lib/bebox/files_helper.rb', line 21 def write_content_to_file(file_path, content) File.open(file_path, 'w') do |f| f.write content end end |