Class: Jekyll::Assets::Extensible

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/assets/extensible.rb

Direct Known Subclasses

Default, HTML, Proxy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(asset:, args:, ctx:) ⇒ Extensible



15
16
17
18
19
20
21
# File 'lib/jekyll/assets/extensible.rb', line 15

def initialize(asset:, args:, ctx:)
  @args = args
  @env = ctx.registers[:site].sprockets
  @jekyll = @env.jekyll
  @asset = asset
  @ctx = ctx
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/jekyll/assets/extensible.rb', line 9

def args
  @args
end

#assetObject (readonly)

Returns the value of attribute asset.



11
12
13
# File 'lib/jekyll/assets/extensible.rb', line 11

def asset
  @asset
end

#ctxObject (readonly)

Returns the value of attribute ctx.



8
9
10
# File 'lib/jekyll/assets/extensible.rb', line 8

def ctx
  @ctx
end

#envObject (readonly)

Returns the value of attribute env.



12
13
14
# File 'lib/jekyll/assets/extensible.rb', line 12

def env
  @env
end

#jekyllObject (readonly)

Returns the value of attribute jekyll.



10
11
12
# File 'lib/jekyll/assets/extensible.rb', line 10

def jekyll
  @jekyll
end

Class Method Details

.for?(type:, args:) ⇒ true, false

Note:

a type is a “content type”

– Allows you to use types to determine if this class fits. –

Parameters:

  • type (String)

    the content type.

  • args (Hash)

    the arguments.

Returns:

  • (true, false)


66
67
68
# File 'lib/jekyll/assets/extensible.rb', line 66

def self.for?(type:, args:)
  for_type?(type) && for_args?(args)
end

.for_args?(args) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
# File 'lib/jekyll/assets/extensible.rb', line 71

def self.for_args?(args)
  return true if arg_keys.empty?
  arg_keys.collect { |k| args.key?(k) }.none? do |k|
    k == false
  end
end

.for_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
# File 'lib/jekyll/assets/extensible.rb', line 79

def self.for_type?(type)
  return true if content_types.empty?
  content_types.any? do |k|
    k.is_a?(Regexp) ? type =~ k : k.to_s == type.to_s
  end
end

.inherited(kls = nil) ⇒ Array<Class>

Note:

you should be using this when using extensible.

– Allows us to keep track of inheritence. –

Parameters:

  • kls (<Any>) (defaults to: nil)

    the class.

Returns:

  • (Array<Class>)


29
30
31
32
33
# File 'lib/jekyll/assets/extensible.rb', line 29

def self.inherited(kls = nil)
  @inherited ||= []
  return @inherited if kls.nil?
  @inherited << kls
end

.internal!Object



46
47
48
49
50
# File 'lib/jekyll/assets/extensible.rb', line 46

def self.internal!
  if name.start_with?("Jekyll::Assets")
    requirements[:internal] = true
  end
end

.internal?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/jekyll/assets/extensible.rb', line 53

def self.internal?
  requirements[
    :internal
  ]
end

.requirementsObject



36
37
38
39
40
41
42
43
# File 'lib/jekyll/assets/extensible.rb', line 36

def self.requirements
  @requirements ||= {
    internal: false,
    args: [], types: [
      #
    ]
  }
end