Class: AssetFinder::Javascript::Normalizer
- Inherits:
-
Object
- Object
- AssetFinder::Javascript::Normalizer
- Defined in:
- lib/asset_finder/javascript/normalizer.rb
Constant Summary collapse
- DEFAULT_PATTERNS =
[ /^(.*)\.js\.coffee$/, /^(.*)\.coffee$/, /^(.*)\.js$/ ].freeze
Instance Method Summary collapse
-
#initialize(root_dir, patterns = [], normalize_index_file: true) ⇒ Normalizer
constructor
A new instance of Normalizer.
- #normalize(path) ⇒ Object
Constructor Details
#initialize(root_dir, patterns = [], normalize_index_file: true) ⇒ Normalizer
Returns a new instance of Normalizer.
10 11 12 13 14 |
# File 'lib/asset_finder/javascript/normalizer.rb', line 10 def initialize(root_dir, patterns = [], normalize_index_file: true) @root_dir = root_dir.to_s @patterns = patterns + DEFAULT_PATTERNS @normalize_index_file = normalize_index_file end |
Instance Method Details
#normalize(path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/asset_finder/javascript/normalizer.rb', line 16 def normalize(path) @patterns.each do |pattern| if path.match(pattern) normalized_path = $1.delete_prefix(@root_dir) normalized_path = normalized_path.delete_suffix('/index') if @normalize_index_file return normalized_path + '.js' end end nil end |