Class: Wikisys::Wiki
- Inherits:
-
Object
show all
- Includes:
- FileFetch, RXFReadWriteModule
- Defined in:
- lib/wikisys.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from FileFetch
#fetch_file, #fetch_filepath, #read
Constructor Details
#initialize(filepath = '.', entries: 'entries.json', debug: false) ⇒ Wiki
Returns a new instance of Wiki.
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/wikisys.rb', line 56
def initialize(filepath='.', entries: 'entries.json', debug: false)
@filepath = filepath
@page = ''
@debug = debug
@hc = HashCache.new(size:30)
@entries = if entries.is_a? DxLite then
entries
elsif File.exists?(entries) then
DxLite.new(entries)
else
DxLite.new('entries/entry(title, tags)')
end
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
53
54
55
|
# File 'lib/wikisys.rb', line 53
def content
@content
end
|
Returns the value of attribute tags.
53
54
55
|
# File 'lib/wikisys.rb', line 53
def tags
@tags
end
|
#title ⇒ Object
Returns the value of attribute title.
53
54
55
|
# File 'lib/wikisys.rb', line 53
def title
@title
end
|
#to_xml ⇒ Object
Returns the value of attribute to_xml.
54
55
56
|
# File 'lib/wikisys.rb', line 54
def to_xml
@to_xml
end
|
Instance Method Details
#build_xml(filename) ⇒ Object
Also known as:
modify_build
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
|
# File 'lib/wikisys.rb', line 122
def build_xml(filename)
puts 'inside modify_buld' if @debug
@title, @content, @tags = read_md(filename)
puts '@title: ' + @title.inspect if @debug
puts '_ @content: ' + @content.inspect if @debug
r = @entries.find_by_title @title
puts 'r: ' + r.inspect if @debug
if r.nil? and @tags then
r = @entries.create title: @title, tags: @tags.join(' ')
end
filename = File.basename(@filepath.sub(/\.md$/,'.xml'))
xmlfile = File.join(@filepath, 'xml', filename)
write_xml(xmlfile, make_xml(@title, @content, @tags))
r.tags = @tags.join(' ') if r and r.tags != @tags
end
|
#create_breadcrumb(filepath, links) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/wikisys.rb', line 80
def create_breadcrumb(filepath, links)
doc = Rexle.new(read_file(filepath))
heading = doc.root.element('heading')
= Rexle.new(HtmlCom::Menu.new(:breadcrumb, links).to_html)
heading.insert_before .root
write_file filepath, doc.root.xml
end
|
#new_build(filename) ⇒ Object
152
153
154
155
156
157
158
159
160
|
# File 'lib/wikisys.rb', line 152
def new_build(filename)
@title, @content, @tags = read_md(filename)
@entries.create title: @title, tags: @tags.join(' ')
puts 'md contents: ' + [@title, @content, @tags].inspect if @debug
write_xml(@title, build_xml(@title, @content, @tags))
end
|
#new_md(filepath, s) ⇒ Object
used by wikisys::controler#import_mw
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/wikisys.rb', line 164
def new_md(filepath, s)
write_file(filepath, md)
end
|
#page(title) ⇒ Object
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/wikisys.rb', line 92
def page(title)
r = @entries.find_by_title title
@page = r ? read_md(title) : make_page(title)
@to_xml = build_xml @page
@entries.save
return @page
end
|
#page=(raw_content) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/wikisys.rb', line 103
def page=(raw_content)
title = raw_content.lines.first.chomp
r = @entries.find_by_title title
make_page(title, raw_content.lines.last.chomp[/(?<=\+ )/]) unless r
write_md title, raw_content
title, content, tags = read_md()
@to_xml = build_xml title, content, tags
write_xml title, @to_xml
@entries.save
@page = raw_content
end
|
#read_file(file = 'index.html') ⇒ Object
175
176
177
|
# File 'lib/wikisys.rb', line 175
def read_file(file='index.html')
@hc.read(file) { FileX.read(file) }
end
|
#to_css ⇒ Object
179
180
181
|
# File 'lib/wikisys.rb', line 179
def to_css()
fetch_file 'pg.css'
end
|
#write_html(filename) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/wikisys.rb', line 183
def write_html(filename)
FileX.mkdir_p File.join(@filepath, 'html')
xml = read_file File.join(@filepath, 'xml', filename)
puts 'about to fetch_file' if @debug
xsl = fetch_file 'pg.xsl'
puts 'xsl: ' + xsl.inspect if @debug
html_file = File.join(@filepath, 'html', filename.sub(/\.xml$/,'.html'))
write_file(html_file, transform(xsl, xml))
end
|