Class: Rake::Pipeline::Web::Filters::NeuterBatch

Inherits:
Object
  • Object
show all
Defined in:
lib/rake-pipeline-web-filters/neuter_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, known_files) ⇒ NeuterBatch

Returns a new instance of NeuterBatch


4
5
6
7
8
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 4

def initialize(config, known_files)
  @config = config || {}
  @known_files = known_files
  @required = []
end

Instance Method Details

#closure_wrap(source) ⇒ Object


40
41
42
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 40

def closure_wrap(source)
  @config[:closure_wrap] ? "(function() {\n#{source}\n})();\n\n" : source
end

#file_wrapper(klass, *args) ⇒ Object


10
11
12
13
14
15
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 10

def file_wrapper(klass, *args)
  file = klass.new(*args)
  file.extend NeuterWrapper
  file.batch(self)
  file
end

#filename_comment(input) ⇒ Object


44
45
46
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 44

def filename_comment(input)
  @config[:filename_comment] ? @config[:filename_comment].call(input) + "\n" : ""
end

#required(req) ⇒ Object


17
18
19
20
21
22
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 17

def required(req)
  unless @known_files.include?(req)
    warn "Included '#{req}', which is not listed in :additional_dependencies. The pipeline may not invalidate properly."
  end
  @required << req
end

#required?(req) ⇒ Boolean

Returns:

  • (Boolean)

24
25
26
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 24

def required?(req)
  @required.include?(req)
end

#strip_requires(source) ⇒ Object


28
29
30
31
32
33
34
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 28

def strip_requires(source)
  requires = []
  regexp = @config[:require_regexp] || %r{^\s*require\(['"]([^'"]*)['"]\);?\s*}
  # FIXME: This $1 may not be reliable with other regexps
  source.gsub!(regexp){ requires << $1; '' }
  requires
end

#transform_path(path, input) ⇒ Object


36
37
38
# File 'lib/rake-pipeline-web-filters/neuter_filter.rb', line 36

def transform_path(path, input)
  @config[:path_transform] ? @config[:path_transform].call(path, input) : path
end