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

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
  dot_options.send(method.to_sym) || super
end

Instance Method Details

#dirObject



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_optionsObject

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
  @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, options
  @src_path = src_path
  @options = 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