module Ngannotate::ProcessorCommon
Public Class Methods
included(base)
click to toggle source
# File lib/ngannotate/processor_common.rb, line 3 def self.included(base) base.extend ClassMethods end
Public Instance Methods
config()
click to toggle source
# File lib/ngannotate/processor_common.rb, line 44 def config ::Rails.configuration.ng_annotate end
exec_context()
click to toggle source
# File lib/ngannotate/processor_common.rb, line 40 def exec_context @exec_context ||= self.class.shared_exec_context end
ignore_file?(input)
click to toggle source
@return true if current file is ignored
# File lib/ngannotate/processor_common.rb, line 71 def ignore_file?(input) match_input(config.ignore_paths, input) end
logger()
click to toggle source
# File lib/ngannotate/processor_common.rb, line 22 def logger ::Rails.logger end
match_input(paths, input)
click to toggle source
@return truthy value if input matches any of paths
# File lib/ngannotate/processor_common.rb, line 78 def match_input(paths, input) file = input[:filename] paths.any? do |p| if p.is_a? Proc p.call(file) elsif p.is_a? Regexp p.match(file) else file.index(p) end end end
need_process?(input)
click to toggle source
Is processing done for current file. This is determined by 4 checks
-
config.paths
-
config.ignore_paths
-
config.process
-
NG_FORCE=true env option
# File lib/ngannotate/processor_common.rb, line 56 def need_process?(input) force_process = ENV['NG_FORCE'] == 'true' process_file?(input) && (force_process || config.process) end
parse_ngannotate_options()
click to toggle source
Parse extra options for ngannotate
# File lib/ngannotate/processor_common.rb, line 94 def parse_ngannotate_options opt = config.options.clone if ENV['NG_OPT'] opt_str = ENV['NG_OPT'] if opt_str opt = Hash[opt_str.split(',').map { |e| e.split('=') }] opt.symbolize_keys! end end regexp = ENV['NG_REGEXP'] if regexp opt[:regexp] = regexp end opt end
process_data(input)
click to toggle source
# File lib/ngannotate/processor_common.rb, line 26 def process_data(input) data = input[:data] file = input[:filename] handle = need_process?(input) state = handle ? :process : (ignore_file?(input) ? :ignore : :skip) logger.info "ng-#{state}: #{file}" return data unless handle opt = { add: true }.merge!(parse_ngannotate_options) r = exec_context.call 'window.annotate', data, opt r['src'] end
process_file?(input)
click to toggle source
@return true if current file should be processed
# File lib/ngannotate/processor_common.rb, line 64 def process_file?(input) !ignore_file?(input) && match_input(config.paths, input) end