Class: Paste::Parser::Sprockets

Inherits:
Object
  • Object
show all
Defined in:
lib/paste/parser/sprockets.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(glue, source) ⇒ Sprockets

Returns a new instance of Sprockets.



9
10
11
12
13
14
# File 'lib/paste/parser/sprockets.rb', line 9

def initialize glue, source
  @glue   = glue
  @source = source
  @file   = glue.find source
  reset_if_needed
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/paste/parser/sprockets.rb', line 7

def file
  @file
end

#glueObject (readonly)

Returns the value of attribute glue.



7
8
9
# File 'lib/paste/parser/sprockets.rb', line 7

def glue
  @glue
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/paste/parser/sprockets.rb', line 7

def source
  @source
end

Instance Method Details

#copy_if_neededObject



26
27
28
29
30
31
32
33
34
# File 'lib/paste/parser/sprockets.rb', line 26

def copy_if_needed
  dest = glue.destination(source)

  if !File.exists?(dest) || File.mtime(dest) != File.mtime(@file)
    FileUtils.mkdir_p File.dirname(dest)
    FileUtils.cp @file, dest
    File.utime File.mtime(@file), File.mtime(@file), dest
  end
end

#css_dependenciesObject



21
22
23
24
# File 'lib/paste/parser/sprockets.rb', line 21

def css_dependencies
  reset_if_needed
  @css_dependencies
end

#js_dependenciesObject



16
17
18
19
# File 'lib/paste/parser/sprockets.rb', line 16

def js_dependencies
  reset_if_needed
  @js_dependencies
end

#reset_if_neededObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/paste/parser/sprockets.rb', line 36

def reset_if_needed
  if @js_dependencies.nil? || @css_dependencies.nil? ||
      @last_updated.nil? || @last_updated < File.mtime(@file)

    @last_updated    = Time.now

    @secretary = ::Sprockets::Secretary.new(
      :root         => glue.root,
      :expand_paths => false,
      :load_path    => glue.load_path,
      :source_files => [@file]
    )

    generate_dependencies
  end
end