Class: Octopress::Ink::Assets::PageAsset
- Inherits:
-
Asset
- Object
- Asset
- Octopress::Ink::Assets::PageAsset
show all
- Defined in:
- lib/octopress-ink/assets/page.rb
Constant Summary
Constants inherited
from Asset
Asset::FRONT_MATTER
Instance Attribute Summary collapse
Attributes inherited from Asset
#base, #dir, #exists, #file, #plugin, #replacement, #root
Instance Method Summary
collapse
Methods inherited from Asset
#asset_info, #content, #copy, #destination, #disable, #disabled?, #ext, #info, #is_disabled, #path, #payload, #read, #remove_jekyll_asset, #replaced?
Constructor Details
#initialize(plugin, base, file) ⇒ PageAsset
Returns a new instance of PageAsset.
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/octopress-ink/assets/page.rb', line 11
def initialize(plugin, base, file)
@root = plugin.assets_path
@plugin = plugin
@base = base
@filename = file
@dir = File.dirname(file)
@file = File.basename(file)
@exists = {}
@permalink_name = file.sub(File.extname(file), '')
@data = {}
file_check
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
9
10
11
|
# File 'lib/octopress-ink/assets/page.rb', line 9
def data
@data
end
|
#filename ⇒ Object
Returns the value of attribute filename.
8
9
10
|
# File 'lib/octopress-ink/assets/page.rb', line 8
def filename
@filename
end
|
#permalink_name ⇒ Object
Returns the value of attribute permalink_name.
9
10
11
|
# File 'lib/octopress-ink/assets/page.rb', line 9
def permalink_name
@permalink_name
end
|
Instance Method Details
#add ⇒ Object
Add page to Jekyll pages if no other page has a conflicting destination
26
27
28
29
30
31
32
|
# File 'lib/octopress-ink/assets/page.rb', line 26
def add
if page.url && !find_page(page)
Octopress.site.pages << page
plugin.config['permalinks'] ||= {}
permalink_config ||= page.url
end
end
|
#deep_merge(data = {}) ⇒ Object
38
39
40
|
# File 'lib/octopress-ink/assets/page.rb', line 38
def deep_merge(data={})
Jekyll::Utils.deep_merge_hashes(page.data, data)
end
|
#find_page(page) ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/octopress-ink/assets/page.rb', line 50
def find_page(page)
site_dir = Octopress.site.dest
dest = page.destination(site_dir)
Octopress.site.pages.clone.each do |p|
return p if p.destination(site_dir) == dest
end
return false
end
|
#lang ⇒ Object
84
85
86
|
# File 'lib/octopress-ink/assets/page.rb', line 84
def lang
data['lang']
end
|
#merge_data(data = {}) ⇒ Object
34
35
36
|
# File 'lib/octopress-ink/assets/page.rb', line 34
def merge_data(data={})
page.data.merge!(data)
end
|
#new_page(data = {}) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/octopress-ink/assets/page.rb', line 42
def new_page(data={})
page = Ink::Page.new(Octopress.site, File.dirname(self.path), '.', File.basename(self.path))
page.data.merge!(data)
page.plugin = plugin
page.asset = self
page
end
|
#page ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/octopress-ink/assets/page.rb', line 60
def page
@page ||= begin
page = Page.new(Octopress.site, source_dir, page_dir, file)
if permalink_config
page.data['permalink'] = permalink_config
else
permalink = page.data['permalink']
end
page.data.merge!(@data)
page.plugin = plugin
page.asset = self
page
end
end
|
#permalink ⇒ Object
78
79
80
|
# File 'lib/octopress-ink/assets/page.rb', line 78
def permalink
page.url
end
|
#permalink=(url) ⇒ Object
88
89
90
91
|
# File 'lib/octopress-ink/assets/page.rb', line 88
def permalink=(url)
page.data['permalink'] = url
permalink_config = url
end
|
#permalink_config ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/octopress-ink/assets/page.rb', line 93
def permalink_config
if Octopress.multilingual? && lang
plugin.config(lang)['permalinks'][permalink_name]
else
plugin.config['permalinks'][permalink_name]
end
end
|
#permalink_config=(url) ⇒ Object
101
102
103
104
105
|
# File 'lib/octopress-ink/assets/page.rb', line 101
def permalink_config=(url)
if permalink_name
plugin.config['permalinks'][permalink_name] = url
end
end
|
#url ⇒ Object
82
|
# File 'lib/octopress-ink/assets/page.rb', line 82
def url; permalink; end
|