Class: Jekyll::SimpleAssets::AssetTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-simple-assets/content-hash.rb

Direct Known Subclasses

ContentHashTag, PathTag

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, text, tokens) ⇒ AssetTag

Returns a new instance of AssetTag.



32
33
34
35
# File 'lib/jekyll-simple-assets/content-hash.rb', line 32

def initialize (tag_name, text, tokens)
	super
	@text = text
end

Instance Method Details

#get_value(context, expression) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jekyll-simple-assets/content-hash.rb', line 37

def get_value (context, expression)
	result = nil

	unless expression.empty?
		lookup_path = expression.split('.')
		result = context
		lookup_path.each do |variable|
			result = result[variable] if result
		end
	end

	case result
	when 'true'
		result = true
	when 'false'
		result = false
	end

	result || expression
end

#render(context) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/jekyll-simple-assets/content-hash.rb', line 58

def render (context)
	site = SimpleAssets::site(context.registers[:site])

	page = context.environments.first['page']

	args = Shellwords.split(@text)

	page_path = context['page']['path'].sub(/^\//, '')

	asset_path = get_value(context, args[0]).sub(/^\//, '')

	if SimpleAssets::hashing_enabled?
		SimpleAssets::page_assets_map[page_path] ||= {}
		SimpleAssets::page_assets_map[page_path][asset_path] ||= {}
		SimpleAssets::page_assets_map[page_path][asset_path][@type] ||= []

		placeholder = SimpleAssets::get_placeholder(asset_path)

		unless SimpleAssets::page_assets_map[page_path][asset_path][@type].include? placeholder
			SimpleAssets::page_assets_map[page_path][asset_path][@type] << placeholder
		end

		"#{ @type }::#{ placeholder }"
	else
		if @type == 'path'
			SimpleAssets::relative_url(asset_path)
		else
			placeholder[0, SimpleAssets::hash_length]
		end
	end
end