Class: Wst::Content

Inherits:
Object
  • Object
show all
Includes:
Configuration
Defined in:
lib/content.rb

Direct Known Subclasses

HamlContent, MdContent

Instance Method Summary collapse

Methods included from Configuration

#config, config, #defaultLinks, defaultLinks, links_file_path, read_config, read_configuration, read_default_links, read_translations, translation_files, valid_location?

Constructor Details

#initialize(file_path, child = nil) ⇒ Content

Returns a new instance of Content.



10
11
12
13
14
15
16
17
18
19
# File 'lib/content.rb', line 10

def initialize file_path, child = nil
  @file_path = file_path
  @plain_content = ""
  @datas = Hash.new
  @cats = ""
  @child = child
  @content = content

  read_content
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/content.rb', line 37

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

Instance Method Details

#account(name) ⇒ Object



77
78
79
80
# File 'lib/content.rb', line 77

def  name
  return nil unless account? name
  return config["accounts"][name]
end

#account?(name) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/content.rb', line 72

def account? name
  return false unless config.has_key? "accounts"
  return config["accounts"].has_key? name
end

#childObject



21
22
23
# File 'lib/content.rb', line 21

def child
  @child
end

#contentObject



25
26
27
28
29
30
31
# File 'lib/content.rb', line 25

def content
  c = self
  while !c.child.nil?
    c = c.child
  end
  c
end

#datasObject



59
60
61
# File 'lib/content.rb', line 59

def datas
  @datas
end

#dirObject



33
34
35
# File 'lib/content.rb', line 33

def dir
  File.dirname @file_path
end

#gravatarObject



67
68
69
70
# File 'lib/content.rb', line 67

def gravatar
  hash = Digest::MD5.hexdigest(email)
  "http://www.gravatar.com/avatar/#{hash}"
end

#gravatar?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/content.rb', line 63

def gravatar?
  email?
end

#raw_contentObject



47
48
49
# File 'lib/content.rb', line 47

def raw_content
  @plain_content
end

#urlObject



55
56
57
# File 'lib/content.rb', line 55

def url
  @url ||= ''
end

#url=(url) ⇒ Object



51
52
53
# File 'lib/content.rb', line 51

def url= url
  @url = url
end