Created
February 7, 2015 08:20
-
-
Save bryanaka/0531468204c8524e94a3 to your computer and use it in GitHub Desktop.
es6_module_transpiler.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# credit to @elucid from http://elucid.github.io/ember_rails_to_ember_cli/ | |
# config/initializers/es6_module_transpiler.rb | |
prefix = 'your-project' | |
pattern = Regexp.new File.join(Rails.root, 'app/assets/javascripts') | |
ES6ModuleTranspiler.add_prefix_pattern pattern, prefix | |
ES6ModuleTranspiler.transform = lambda do |name| | |
name_parts = name.downcase.sub("#{prefix}/", '').split(/[^a-z]/) | |
has_suffix = name_parts.length > 1 && name_parts.first.chomp('s') == name_parts.last | |
bad_characters = name.match(/[^a-z\d\/\-]/) | |
if bad_characters or has_suffix | |
raise NameError.new %Q[Module name "#{name}" is incompatible with ember-cli naming conventions] | |
end | |
name | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment