Class: Ngannotate::Processor
- Inherits:
-
Sprockets::Processor
- Object
- Sprockets::Processor
- Ngannotate::Processor
- Defined in:
- lib/ngannotate/processor.rb
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(context, locals) ⇒ Object
-
#force ⇒ Object
To allow testing assets compile in development environment.
- #parse_opt ⇒ Object
- #prepare ⇒ Object
-
#skip ⇒ Object
Skip processing in environments where it does not make sense.
Class Method Details
.name ⇒ Object
6 7 8 |
# File 'lib/ngannotate/processor.rb', line 6 def self.name 'Ngannotate::Processor' end |
Instance Method Details
#evaluate(context, locals) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ngannotate/processor.rb', line 34 def evaluate(context, locals) return data if skip opt = { add: true }.merge!(parse_opt) r = @context.call 'window.annotate', data, opt r['src'] end |
#force ⇒ Object
To allow testing assets compile in development environment
To explicitly force assets compile in development environment
NG_FORCE=true RAILS_ENV=development bundle exec rake assets:clean assets:precompile
22 23 24 |
# File 'lib/ngannotate/processor.rb', line 22 def force ENV['NG_FORCE'] == 'true' end |
#parse_opt ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ngannotate/processor.rb', line 42 def parse_opt opt = {} opt_str = ENV['NG_OPT'] if opt_str opt = Hash[opt_str.split(',').map { |e| e.split('=') }] opt.symbolize_keys! end if ENV['NG_REGEXP'] opt[:regexp] = ENV['NG_REGEXP'] end opt end |
#prepare ⇒ Object
10 11 12 13 14 |
# File 'lib/ngannotate/processor.rb', line 10 def prepare return if skip ngannotate_source = File.open(File.join(File.dirname(__FILE__), '../../vendor/ngannotate.js')).read @context = ExecJS.compile "window = {};" + ngannotate_source end |
#skip ⇒ Object
Skip processing in environments where it does not make sense. Override by NG_FORCE=true env variable
30 31 32 |
# File 'lib/ngannotate/processor.rb', line 30 def skip !force && (::Rails.env.development? || ::Rails.env.test?) end |