lib/octopress-ink/assets/page.rb in octopress-ink-1.0.0.rc.48 vs lib/octopress-ink/assets/page.rb in octopress-ink-1.0.0.rc.49

- old
+ new

@@ -4,11 +4,11 @@ module Octopress module Ink module Assets class PageAsset < Asset attr_reader :filename - attr_accessor :data, :permalink_name + attr_accessor :data, :permalink_name, :cloned, :clone_of def initialize(plugin, base, file) @root = plugin.assets_path @plugin = plugin @base = base @@ -25,26 +25,30 @@ # def add if page.url && !find_page(page) Octopress.site.pages << page plugin.config['permalinks'] ||= {} - plugin.config['permalinks'][@permalink_name] ||= page.url + permalink_config ||= page.url end end - def clone(permalink, permalink_name=nil) + def clone(data={}) + self.cloned = true p = PageAsset.new(plugin, base, file) - p.permalink_name = permalink_name - p.permalink ||= permalink + p.clone_of = self + p.data = data p end def merge_data(data={}) - self.data.merge!(data) - self + page.data.merge!(data) end + def deep_merge(data={}) + Jekyll::Utils.deep_merge_hashes(page.data, data) + end + def find_page(page) site_dir = Octopress.site.dest dest = page.destination(site_dir) Octopress.site.pages.clone.each do |p| @@ -53,28 +57,62 @@ return false end def page @page ||= begin - page = Page.new(Octopress.site, source_dir, page_dir, file, self) + 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 end end def info message = super - name = permalink_name << page.ext - message.sub!(/#{filename}\s*/, name.ljust(35)) - message.ljust(25) << (permalink || page.permalink || '') + return message if disabled? + + if clone_of + " #{permalink}" + elsif cloned + message << "\n #{permalink}" + else + name = permalink_name << page.ext + message.sub!(/#{filename}\s*/, name.ljust(35)) + message.ljust(25) << permalink + end end def permalink - @permalink ||= plugin.config['permalinks'][permalink_name] + page.url end + + def url; permalink; end + def lang + data['lang'] + end + def permalink=(url) - @permalink = url + page.data['permalink'] = url + permalink_config = url + end + + def permalink_config + if Octopress.multilingual? && lang + plugin.config(lang)['permalinks'][permalink_name] + else + plugin.config['permalinks'][permalink_name] + end + end + + def permalink_config=(url) if permalink_name plugin.config['permalinks'][permalink_name] = url end end