Class: Gumdrop::Content
Overview
All content (layouts, partials, images, html, js css, etc) found in the source directory are represented as a Content object in memory
Instance Attribute Summary collapse
Instance Method Summary
collapse
#parent, #site
#log
#clear_events, #event_block, #fire
Constructor Details
#initialize(source_path, generator = nil, &block) ⇒ Content
Returns a new instance of Content.
10
11
12
13
14
15
16
|
# File 'lib/gumdrop/content.rb', line 10
def initialize(source_path, generator=nil, &block)
@source_path= source_path
@generator= generator
@ignore= false
@block= block
@params= Util::HashObject.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
122
123
124
125
126
127
128
|
# File 'lib/gumdrop/content.rb', line 122
def method_missing(sym, *args, &block)
if params.has_key? sym
params[sym]
else
super
end
end
|
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
8
9
10
|
# File 'lib/gumdrop/content.rb', line 8
def params
@params
end
|
#source_path ⇒ Object
Returns the value of attribute source_path.
8
9
10
|
# File 'lib/gumdrop/content.rb', line 8
def source_path
@source_path
end
|
Instance Method Details
#binary? ⇒ Boolean
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/gumdrop/content.rb', line 58
def binary?
@is_binary ||= begin
if generated? or has_block? or missing?
false
else
s = (File.read(source_path, File.stat(source_path).blksize) || "").split(//)
((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
end
end
end
|
#body ⇒ Object
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/gumdrop/content.rb', line 99
def body @body ||= case
when has_block?
@block.call
when missing?, binary?
nil
else
File.read @source_path
end
end
|
#exists? ⇒ Boolean
71
72
73
|
# File 'lib/gumdrop/content.rb', line 71
def exists?
has_block? or File.exists? @source_path
end
|
#ext ⇒ Object
50
51
52
|
# File 'lib/gumdrop/content.rb', line 50
def ext
@ext ||= File.extname filename
end
|
#filename ⇒ Object
42
43
44
|
# File 'lib/gumdrop/content.rb', line 42
def filename
@filename ||= _target_filename
end
|
#generated? ⇒ Boolean
79
80
81
|
# File 'lib/gumdrop/content.rb', line 79
def generated?
!@generator.nil?
end
|
#generator? ⇒ Boolean
95
96
97
|
# File 'lib/gumdrop/content.rb', line 95
def generator?
ext == '.generator'
end
|
#has_block? ⇒ Boolean
83
84
85
|
# File 'lib/gumdrop/content.rb', line 83
def has_block?
!@block.nil?
end
|
#layout? ⇒ Boolean
91
92
93
|
# File 'lib/gumdrop/content.rb', line 91
def layout?
ext == '.layout'
end
|
#level ⇒ Object
34
35
36
|
# File 'lib/gumdrop/content.rb', line 34
def level
@level ||= (path.split('/').length - 1)
end
|
#missing? ⇒ Boolean
75
76
77
|
# File 'lib/gumdrop/content.rb', line 75
def missing?
!exists?
end
|
#mtime ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/gumdrop/content.rb', line 110
def mtime
@mtime ||= if exists? and !generated?
File.new(@source_path).mtime
else
Time.now
end
end
|
#partial? ⇒ Boolean
87
88
89
|
# File 'lib/gumdrop/content.rb', line 87
def partial?
source_filename[0] == "_"
end
|
#path ⇒ Object
30
31
32
|
# File 'lib/gumdrop/content.rb', line 30
def path
@path ||= _source_path
end
|
#slug ⇒ Object
26
27
28
|
# File 'lib/gumdrop/content.rb', line 26
def slug
@slug ||= uri.gsub('/', '-').gsub(ext, '')
end
|
#source_filename ⇒ Object
38
39
40
|
# File 'lib/gumdrop/content.rb', line 38
def source_filename
@source_filename ||= File.basename source_path
end
|
#to_s ⇒ Object
118
119
120
|
# File 'lib/gumdrop/content.rb', line 118
def to_s
uri
end
|
#type ⇒ Object
46
47
48
|
# File 'lib/gumdrop/content.rb', line 46
def type
@type ||= File.extname source_filename
end
|
#uri ⇒ Object
54
55
56
|
# File 'lib/gumdrop/content.rb', line 54
def uri
@uri ||= _uri
end
|