class Wst::Content
Public Class Methods
new(file_path, child = nil)
click to toggle source
# File lib/wst/content.rb, line 26 def initialize file_path, child = nil @file_path = file_path @plain_content = "" @datas = Hash.new @cats = "" @child = child @content = content read_content end
save!(file_path, datas, content)
click to toggle source
param [String] file_path Relative path of the file to save param [Hash] datas Header datas param [String] content Content
to write
# File lib/wst/content.rb, line 15 def save! file_path, datas, content FileUtils.mkdir_p File.dirname file_path File.open(file_path, "w") do |file| file.write datas.to_yaml file.write "---\n" file.write "\n" file.write content end end
Public Instance Methods
account(name)
click to toggle source
# File lib/wst/content.rb, line 93 def account name return nil unless account? name return config["accounts"][name] end
account?(name)
click to toggle source
# File lib/wst/content.rb, line 88 def account? name return false unless config.has_key? "accounts" return config["accounts"].has_key? name end
child()
click to toggle source
# File lib/wst/content.rb, line 37 def child @child end
content()
click to toggle source
# File lib/wst/content.rb, line 41 def content c = self while !c.child.nil? c = c.child end c end
content_url()
click to toggle source
# File lib/wst/content.rb, line 71 def content_url @url ||= '' end
content_url=(url)
click to toggle source
# File lib/wst/content.rb, line 67 def content_url= url @url = url end
datas()
click to toggle source
# File lib/wst/content.rb, line 75 def datas @datas end
dir()
click to toggle source
# File lib/wst/content.rb, line 49 def dir File.dirname @file_path end
gravatar()
click to toggle source
# File lib/wst/content.rb, line 83 def gravatar hash = Digest::MD5.hexdigest(email) "http://www.gravatar.com/avatar/#{hash}" end
gravatar?()
click to toggle source
# File lib/wst/content.rb, line 79 def gravatar? email? end
method_missing(m, *args, &block)
click to toggle source
# File lib/wst/content.rb, line 53 def method_missing(m, *args, &block) if m =~ /^(.*)\?$/ return @datas.has_key? $1 elsif @datas.has_key? m.to_s return @datas[m.to_s] else return nil end end
raw_content()
click to toggle source
# File lib/wst/content.rb, line 63 def raw_content @plain_content end
Protected Instance Methods
default_links_path()
click to toggle source
# File lib/wst/content.rb, line 100 def default_links_path "#{config['path']}/links.md" end
read_content()
click to toggle source
# File lib/wst/content.rb, line 104 def read_content @plain_content = File.open(@file_path, "r:utf-8").read begin if @plain_content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m @plain_content = $' @datas = YAML.load $1 end rescue => e puts "YAML Exception reading #{@file_path}: #{e.message}" end end