Class: Content
Constant Summary
Constants inherited
from Zarchitect
Zarchitect::ASSETDIR, Zarchitect::ASSETSDIR, Zarchitect::BUILDIR, Zarchitect::CONFIGDIR, Zarchitect::DEBUGSDIR, Zarchitect::DRAFTDIR, Zarchitect::FILEDIR, Zarchitect::FILESDIR, Zarchitect::HTMLDIR, Zarchitect::LAYOUTDIR, Zarchitect::NODEDIR, Zarchitect::SHARESDIR, Zarchitect::VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Zarchitect
#main, #rss
Constructor Details
#initialize(post) ⇒ Content
Returns a new instance of Content.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/zarchitect/content.rb', line 4
def initialize(post)
@post = post
@source = @post.source_path.clone
@source.gsub!('/', '_')
@source.sub!('.md', '')
@nodes = Array.new
return if @post.conf.has_option?("script")
@raw = File.open(@post.source_path) { |f| f.read }
@raw = @raw.lines
i = 0
z = 0
@raw.each do |l|
if l.start_with?("---")
z += 1
end
break if z == 2
i += 1
end
@raw = @raw.drop(i+1)
@raw = @raw.join
end
|
Instance Attribute Details
#nodes ⇒ Object
Returns the value of attribute nodes.
2
3
4
|
# File 'lib/zarchitect/content.rb', line 2
def nodes
@nodes
end
|
Instance Method Details
#full_preview?(n) ⇒ Boolean
173
174
175
|
# File 'lib/zarchitect/content.rb', line 173
def full_preview?(n)
(@nodes.count <= n)
end
|
#html ⇒ Object
152
153
154
155
156
157
158
|
# File 'lib/zarchitect/content.rb', line 152
def html
str = String.new
@nodes.each do |n|
str << n.html
end
str
end
|
#markup ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/zarchitect/content.rb', line 26
def markup
from_script if @post.conf.has_option?("script")
return if @post.conf.has_option?("script")
if !File.exist?(@post.html_path) ||
(File.stat(@post.source_path).mtime > File.stat(@post.html_path).mtime)
GPI.print "Processing markdown", GPI::CLU.check_option('v')
chtml = @raw
@img_id = 0
@img_id_inc = 1
new_string = ""
regexp = /
\A
MEDIA:(?<filetype>img|img_full|video|yt|audio):
(?<id>[a-zA-Z0-9|._\-\/]+):"(?<caption>.*)":?(?<width>[0-9px%]*)
/x
chtml.each_line do |str|
if str.include?('MEDIA')
GPI.print "media processor: #{str}", GPI::CLU.check_option('v')
end
@m = regexp.match(str)
if @m
GPI.print "matched regex", GPI::CLU.check_option('v')
@caption = @m[:caption]
new_html = ""
case @m[:filetype]
when 'img'
html = media_img
when 'img_full'
html = media_img_full
when 'video'
html = media_video
when 'audio'
html = media_audio
when 'yt'
html = media_youtube
else
html = "[failed to render media]"
end
html.each_line do |substr|
if substr.lstrip
new_html << substr.lstrip
else
new_html << substr
end
end
if new_html.include?('\n')
str.sub!(@m[0], new_html.chomp!)
else
str.sub!(@m[0], new_html)
end
end
new_string << str
end
tfound = false
tables = Array.new
ar = new_string.split("\n")
ar.each_with_index do |l,i|
if l[0] == "|" && l[-1] == "|"
if tfound
tables.last.add_line l
else
tables.push HTMLTable.new
tables.last.add_line l
tables.last.starts_at i
tfound = true
end
else
if tfound
tables.last.ends_at i-1
tfound = false
tables.last.process
end
end
end
tables.each do |t|
ar = t.replace(ar)
end
ar.delete_if { |x| x.nil? }
str = ar.join("\n")
if @post.conf.has_option?("katex")
str2 = ""
tmp = ""
i = 0
l = str.length
while (i < l)
if str[i] == "<" && str[i+1] == "?" && str[i+2] == "k" &&
str[i+3] == "t" && str[i+4] == "x"
i += 5
tmp = ""
loop do
if str[i] == "?" && str[i+1] == ">"
GPI.print "Rendering Katex string", GPI::CLU.check_option('v')
str2 << Katex.render(tmp.strip)
i += 1
break
else
tmp << str[i]
i += 1
end
end
else
str2 << str[i]
end
i += 1
end
str = str2
end
markdown = Redcarpet::Markdown.new(RougeHTML,
autolink: true)
chtml = markdown.render(str)
parse(chtml)
else
parse(nil)
end
end
|
#preview(n) ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/zarchitect/content.rb', line 160
def preview(n)
if full_preview?(n)
html
else
str = String.new
@nodes.each_with_index do |node,i|
break if i == n
str << node.html
end
str
end
end
|