Class: Middleman::Sprockets::Resource

Inherits:
Middleman::Sitemap::Resource
  • Object
show all
Defined in:
lib/middleman-sprockets/resource.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(store, path, source_file, sprockets_path, environment) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
11
12
13
14
15
# File 'lib/middleman-sprockets/resource.rb', line 7

def initialize store, path, source_file, sprockets_path, environment
  @app  = store.app
  @path = path
  @sprockets_path = sprockets_path
  @environment    = environment
  @errored        = false

  super(store, path, source_file)
end

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/middleman-sprockets/resource.rb', line 47

def binary?
  false
end

#errored?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/middleman-sprockets/resource.rb', line 18

def errored?
  @errored
end

#render(*_args) ⇒ Object



28
29
30
31
32
# File 'lib/middleman-sprockets/resource.rb', line 28

def render *_args
  ::Middleman::Util.instrument 'sprockets.render', asset: self do
    sprockets_asset.source
  end
end

#sprockets_assetObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/middleman-sprockets/resource.rb', line 35

def sprockets_asset
  ::Middleman::Util.instrument 'sprockets.asset_lookup', asset: self do
    @environment[@sprockets_path] || raise(::Sprockets::FileNotFound, @sprockets_path)
  end
rescue StandardError => e
  raise e if @app.build?

  @errored = true
  Error.new(e, ext)
end

#template?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/middleman-sprockets/resource.rb', line 23

def template?
  true
end