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
Constant Summary
collapse
- KNOWN_BINARY =
%w(.jpe .jpeg .jpg .png .tiff .gif)
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.
13
14
15
16
17
18
19
|
# File 'lib/gumdrop/content.rb', line 13
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
140
141
142
143
144
145
146
|
# File 'lib/gumdrop/content.rb', line 140
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.
11
12
13
|
# File 'lib/gumdrop/content.rb', line 11
def params
@params
end
|
#source_path ⇒ Object
Returns the value of attribute source_path.
11
12
13
|
# File 'lib/gumdrop/content.rb', line 11
def source_path
@source_path
end
|
Instance Method Details
#binary? ⇒ Boolean
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/gumdrop/content.rb', line 74
def binary?
@is_binary ||= begin
if generated? or has_block? or missing?
false
elsif KNOWN_BINARY.include? ext or site.unrenderable? path
true
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
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/gumdrop/content.rb', line 117
def body @body ||= case
when has_block?
@block.call
when missing?, binary?
nil
else
File.read @source_path
end
end
|
#clean_uri ⇒ Object
70
71
72
|
# File 'lib/gumdrop/content.rb', line 70
def clean_uri
@clean_uri ||= uri.gsub(ext, '')
end
|
#dirname ⇒ Object
50
51
52
|
# File 'lib/gumdrop/content.rb', line 50
def dirname
@dirname ||= File.dirname source_path
end
|
#exists? ⇒ Boolean
89
90
91
|
# File 'lib/gumdrop/content.rb', line 89
def exists?
has_block? or File.exists? @source_path
end
|
#ext ⇒ Object
58
59
60
|
# File 'lib/gumdrop/content.rb', line 58
def ext
@ext ||= File.extname filename
end
|
#filename ⇒ Object
46
47
48
|
# File 'lib/gumdrop/content.rb', line 46
def filename
@filename ||= _target_filename
end
|
#generated? ⇒ Boolean
97
98
99
|
# File 'lib/gumdrop/content.rb', line 97
def generated?
!@generator.nil?
end
|
#generator? ⇒ Boolean
113
114
115
|
# File 'lib/gumdrop/content.rb', line 113
def generator?
ext == '.generator'
end
|
#has_block? ⇒ Boolean
101
102
103
|
# File 'lib/gumdrop/content.rb', line 101
def has_block?
!@block.nil?
end
|
#layout? ⇒ Boolean
109
110
111
|
# File 'lib/gumdrop/content.rb', line 109
def layout?
ext == '.layout'
end
|
#level ⇒ Object
38
39
40
|
# File 'lib/gumdrop/content.rb', line 38
def level
@level ||= (path.split('/').length - 1)
end
|
#missing? ⇒ Boolean
93
94
95
|
# File 'lib/gumdrop/content.rb', line 93
def missing?
!exists?
end
|
#mtime ⇒ Object
128
129
130
131
132
133
134
|
# File 'lib/gumdrop/content.rb', line 128
def mtime
@mtime ||= if exists? and !generated?
File.mtime @source_path
else
Time.now
end
end
|
#partial? ⇒ Boolean
105
106
107
|
# File 'lib/gumdrop/content.rb', line 105
def partial?
source_filename[0] == "_"
end
|
#path ⇒ Object
34
35
36
|
# File 'lib/gumdrop/content.rb', line 34
def path
@path ||= _source_path
end
|
#slug ⇒ Object
29
30
31
32
|
# File 'lib/gumdrop/content.rb', line 29
def slug
@slug ||= uri.gsub('/', '-').gsub(ext, '')
@params.slug || @slug
end
|
#source_filename ⇒ Object
42
43
44
|
# File 'lib/gumdrop/content.rb', line 42
def source_filename
@source_filename ||= File.basename source_path
end
|
#to_s ⇒ Object
136
137
138
|
# File 'lib/gumdrop/content.rb', line 136
def to_s
uri
end
|
#type ⇒ Object
54
55
56
|
# File 'lib/gumdrop/content.rb', line 54
def type
@type ||= File.extname source_filename
end
|
#uri ⇒ Object
62
63
64
|
# File 'lib/gumdrop/content.rb', line 62
def uri
@uri ||= _uri
end
|
#uripath ⇒ Object
66
67
68
|
# File 'lib/gumdrop/content.rb', line 66
def uripath
@uripath ||= File.dirname uri
end
|