Class: Octopress::Ink::Assets::Template

Inherits:
Asset
  • Object
show all
Defined in:
lib/octopress-ink/assets/template.rb

Direct Known Subclasses

LocalTemplate

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, #data, #destination, #disable, #disabled?, #ext, #filename, #is_disabled, #path, #payload, #read, #remove_jekyll_asset, #replaced?

Constructor Details

#initialize(*args) ⇒ Template

Returns a new instance of Template.



7
8
9
10
11
# File 'lib/octopress-ink/assets/template.rb', line 7

def initialize(*args)
  super(*args)
  @pages = []
  @existing_pages = {}
end

Instance Attribute Details

#pagesObject (readonly)

Returns the value of attribute pages.



5
6
7
# File 'lib/octopress-ink/assets/template.rb', line 5

def pages
  @pages
end

Instance Method Details

#addObject



13
# File 'lib/octopress-ink/assets/template.rb', line 13

def add; end

#infoObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/octopress-ink/assets/template.rb', line 15

def info
  message = "  - #{asset_info}\n"

  unless disabled?
    self.pages.each do |page|
      if existing_page = @existing_pages[page.url]
        message << "     #{page.url.ljust(33)} Disabled: /#{existing_page.path} already exists\n"
      else
        message << "     #{page.url}\n"
      end
    end
  end

  message
end

#new_page(data = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/octopress-ink/assets/template.rb', line 31

def new_page(data={})
  return if disabled?
  page = Ink::Page.new(Octopress.site, File.dirname(self.path), '.', File.basename(self.path))
  page.data.merge!(data)
  page.plugin = plugin
  page.asset = self
  self.pages << page

  if existing_page = page_exists?(page)
    if existing_page.respond_to?(:plugin)
      @replacement = existing_page.plugin.name
    else
      @existing_pages[existing_page.url] = existing_page
    end
    false
  else
    page
  end
end

#page_exists?(page) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/octopress-ink/assets/template.rb', line 51

def page_exists?(page)
  Octopress.site.pages.find {|p| p.url == page.url}
end