Module: New::Interpolate
- Included in:
- Template
- Defined in:
- lib/new/interpolate.rb
Constant Summary collapse
- FILENAME_RENAME_MATCH =
regex to match capital underscored template options names ie [PROJECT_NAME]
/\[([A-Z_.]+)\]/
Instance Method Summary collapse
- #dir ⇒ Object
-
#dot_options ⇒ Object
Convert options to OpenStruct so we can use dot notation in the templates.
-
#interpolate(src_path, options) ⇒ Object
Convienance method for processing everything.
- #to_filename(filename) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object (private)
Allow templates to call option values directly
40 41 42 |
# File 'lib/new/interpolate.rb', line 40 def method_missing method .send(method.to_sym) || super end |
Instance Method Details
#dir ⇒ Object
19 20 21 |
# File 'lib/new/interpolate.rb', line 19 def dir File.file?(@src_path) ? @dest_path : File.join(@dest_path, File.basename(@src_path)) end |
#dot_options ⇒ Object
Convert options to OpenStruct so we can use dot notation in the templates
25 26 27 |
# File 'lib/new/interpolate.rb', line 25 def @dot_options ||= RecursiveOpenStruct.new(@options) end |
#interpolate(src_path, options) ⇒ Object
Convienance method for processing everything
10 11 12 13 14 15 16 17 |
# File 'lib/new/interpolate.rb', line 10 def interpolate src_path, @src_path = src_path @options = copy_to_tmp process_paths process_files end |
#to_filename(filename) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/new/interpolate.rb', line 29 def to_filename filename filename.downcase .gsub(/[^\w\s_-]+/, '') .gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2') .gsub(/\s+/, '_') end |