my_wiki_generator 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. data/my_wiki/grep.txt +238 -0
  2. data/my_wiki/my_wiki_generator.rb +248 -0
  3. data/my_wiki/templates/POST_GENERATION_REMINDER +1 -0
  4. data/my_wiki/templates/app/controllers/application.rb +75 -0
  5. data/my_wiki/templates/app/controllers/content_history_controller.rb +49 -0
  6. data/my_wiki/templates/app/controllers/login_controller.rb +93 -0
  7. data/my_wiki/templates/app/controllers/my_wiki_admin_controller.rb +26 -0
  8. data/my_wiki/templates/app/controllers/my_wiki_controller.rb +250 -0
  9. data/my_wiki/templates/app/controllers/page_admin_controller.rb +51 -0
  10. data/my_wiki/templates/app/controllers/user_admin_controller.rb +34 -0
  11. data/my_wiki/templates/app/helpers/application_helper.rb +3 -0
  12. data/my_wiki/templates/app/helpers/content_history_helper.rb +2 -0
  13. data/my_wiki/templates/app/helpers/login_helper.rb +2 -0
  14. data/my_wiki/templates/app/helpers/my_wiki_admin_helper.rb +2 -0
  15. data/my_wiki/templates/app/helpers/my_wiki_helper.rb +94 -0
  16. data/my_wiki/templates/app/helpers/page_admin_helper.rb +2 -0
  17. data/my_wiki/templates/app/helpers/user_admin_helper.rb +2 -0
  18. data/my_wiki/templates/app/models/attachment.rb +55 -0
  19. data/my_wiki/templates/app/models/content.rb +32 -0
  20. data/my_wiki/templates/app/models/content_history.rb +49 -0
  21. data/my_wiki/templates/app/models/content_sweeper.rb +7 -0
  22. data/my_wiki/templates/app/models/my_wiki_mailer.rb +29 -0
  23. data/my_wiki/templates/app/models/role.rb +18 -0
  24. data/my_wiki/templates/app/models/setting.rb +7 -0
  25. data/my_wiki/templates/app/models/user.rb +60 -0
  26. data/my_wiki/templates/app/views/content_history/_form.rhtml +19 -0
  27. data/my_wiki/templates/app/views/content_history/edit.rhtml +9 -0
  28. data/my_wiki/templates/app/views/content_history/list.rhtml +27 -0
  29. data/my_wiki/templates/app/views/content_history/new.rhtml +8 -0
  30. data/my_wiki/templates/app/views/content_history/show.rhtml +21 -0
  31. data/my_wiki/templates/app/views/layouts/my_wiki.rhtml +105 -0
  32. data/my_wiki/templates/app/views/login/edit.rhtml +25 -0
  33. data/my_wiki/templates/app/views/login/login.rhtml +23 -0
  34. data/my_wiki/templates/app/views/login/logout.rhtml +10 -0
  35. data/my_wiki/templates/app/views/login/signup.rhtml +23 -0
  36. data/my_wiki/templates/app/views/login/welcome.rhtml +13 -0
  37. data/my_wiki/templates/app/views/my_wiki/_form.rhtml +11 -0
  38. data/my_wiki/templates/app/views/my_wiki/css.rhtml +224 -0
  39. data/my_wiki/templates/app/views/my_wiki/diff.rhtml +4 -0
  40. data/my_wiki/templates/app/views/my_wiki/edit.rhtml +34 -0
  41. data/my_wiki/templates/app/views/my_wiki/fileinfo.rhtml +22 -0
  42. data/my_wiki/templates/app/views/my_wiki/list.rhtml +1 -0
  43. data/my_wiki/templates/app/views/my_wiki/mails.rhtml +1 -0
  44. data/my_wiki/templates/app/views/my_wiki/new.rhtml +6 -0
  45. data/my_wiki/templates/app/views/my_wiki/recent.rhtml +3 -0
  46. data/my_wiki/templates/app/views/my_wiki/search.rhtml +5 -0
  47. data/my_wiki/templates/app/views/my_wiki/search_result.rhtml +10 -0
  48. data/my_wiki/templates/app/views/my_wiki/show.rhtml +31 -0
  49. data/my_wiki/templates/app/views/my_wiki_admin/index.rhtml +5 -0
  50. data/my_wiki/templates/app/views/my_wiki_admin/setting.rhtml +64 -0
  51. data/my_wiki/templates/app/views/my_wiki_mailer/inform.rhtml +3 -0
  52. data/my_wiki/templates/app/views/page_admin/_form.rhtml +22 -0
  53. data/my_wiki/templates/app/views/page_admin/edit.rhtml +9 -0
  54. data/my_wiki/templates/app/views/page_admin/list.rhtml +55 -0
  55. data/my_wiki/templates/app/views/page_admin/new.rhtml +8 -0
  56. data/my_wiki/templates/app/views/page_admin/show.rhtml +8 -0
  57. data/my_wiki/templates/app/views/user_admin/_form.rhtml +10 -0
  58. data/my_wiki/templates/app/views/user_admin/change_password.rhtml +9 -0
  59. data/my_wiki/templates/app/views/user_admin/list.rhtml +25 -0
  60. data/my_wiki/templates/app/views/user_admin/signup.rhtml +20 -0
  61. data/my_wiki/templates/components/admin/menu/menu.rhtml +5 -0
  62. data/my_wiki/templates/components/admin/menu_controller.rb +3 -0
  63. data/my_wiki/templates/components/list/list/list.rhtml +11 -0
  64. data/my_wiki/templates/components/list/list_controller.rb +11 -0
  65. data/my_wiki/templates/components/sidebar/sidebar/show.rhtml +7 -0
  66. data/my_wiki/templates/components/sidebar/sidebar_controller.rb +9 -0
  67. data/my_wiki/templates/config/routes.rb +35 -0
  68. data/my_wiki/templates/db/migrate/001_my_wiki_migration.rb +75 -0
  69. data/my_wiki/templates/lib/diff/lcs.rb +1105 -0
  70. data/my_wiki/templates/lib/diff/lcs/array.rb +21 -0
  71. data/my_wiki/templates/lib/diff/lcs/block.rb +51 -0
  72. data/my_wiki/templates/lib/diff/lcs/callbacks.rb +322 -0
  73. data/my_wiki/templates/lib/diff/lcs/change.rb +169 -0
  74. data/my_wiki/templates/lib/diff/lcs/hunk.rb +257 -0
  75. data/my_wiki/templates/lib/diff/lcs/ldiff.rb +226 -0
  76. data/my_wiki/templates/lib/diff/lcs/string.rb +19 -0
  77. data/my_wiki/templates/lib/login_system.rb +87 -0
  78. data/my_wiki/templates/lib/markup/simple_markup.rb +489 -0
  79. data/my_wiki/templates/lib/markup/simple_markup/fragments.rb +329 -0
  80. data/my_wiki/templates/lib/markup/simple_markup/inline.rb +338 -0
  81. data/my_wiki/templates/lib/markup/simple_markup/lines.rb +151 -0
  82. data/my_wiki/templates/lib/markup/simple_markup/preprocess.rb +68 -0
  83. data/my_wiki/templates/lib/markup/simple_markup/to_flow.rb +188 -0
  84. data/my_wiki/templates/lib/markup/simple_markup/to_html.rb +302 -0
  85. data/my_wiki/templates/lib/markup/simple_markup/to_latex.rb +333 -0
  86. data/my_wiki/templates/lib/my_wiki_plugin.rb +60 -0
  87. data/my_wiki/templates/lib/my_wiki_plugins/christel.rb +5 -0
  88. data/my_wiki/templates/lib/my_wiki_plugins/join.rb +3 -0
  89. data/my_wiki/templates/lib/my_wiki_plugins/link_to_attach.rb +17 -0
  90. data/my_wiki/templates/lib/my_wiki_plugins/recent.rb +8 -0
  91. data/my_wiki/templates/public/javascripts/my_wiki.js +8 -0
  92. data/my_wiki/templates/public/stylesheets/my_wiki/back.jpg +0 -0
  93. data/my_wiki/templates/public/stylesheets/my_wiki/back1.jpg +0 -0
  94. data/my_wiki/templates/public/stylesheets/my_wiki/back2.jpg +0 -0
  95. data/my_wiki/templates/public/stylesheets/my_wiki/foot.jpg +0 -0
  96. data/my_wiki/templates/public/stylesheets/my_wiki/h1.gif +0 -0
  97. data/my_wiki/templates/public/stylesheets/my_wiki/h1.jpg +0 -0
  98. data/my_wiki/templates/public/stylesheets/my_wiki/menu.jpg +0 -0
  99. data/my_wiki/templates/public/stylesheets/my_wiki/menu2.jpg +0 -0
  100. data/my_wiki/templates/public/stylesheets/my_wiki/menu_c.jpg +0 -0
  101. data/my_wiki/templates/public/stylesheets/my_wiki/my_wiki.css +336 -0
  102. data/my_wiki/templates/public/stylesheets/my_wiki/title.jpg +0 -0
  103. metadata +181 -0
@@ -0,0 +1,333 @@
1
+ require 'markup/simple_markup/fragments'
2
+ require 'markup/simple_markup/inline'
3
+
4
+ require 'cgi'
5
+
6
+ module SM
7
+
8
+ # Convert SimpleMarkup to basic LaTeX report format
9
+
10
+ class ToLaTeX
11
+
12
+ BS = "\020" # \
13
+ OB = "\021" # {
14
+ CB = "\022" # }
15
+ DL = "\023" # Dollar
16
+
17
+ BACKSLASH = "#{BS}symbol#{OB}92#{CB}"
18
+ HAT = "#{BS}symbol#{OB}94#{CB}"
19
+ BACKQUOTE = "#{BS}symbol#{OB}0#{CB}"
20
+ TILDE = "#{DL}#{BS}sim#{DL}"
21
+ LESSTHAN = "#{DL}<#{DL}"
22
+ GREATERTHAN = "#{DL}>#{DL}"
23
+
24
+ def self.l(str)
25
+ str.tr('\\', BS).tr('{', OB).tr('}', CB).tr('$', DL)
26
+ end
27
+
28
+ def l(arg)
29
+ SM::ToLaTeX.l(arg)
30
+ end
31
+
32
+ LIST_TYPE_TO_LATEX = {
33
+ ListBase::BULLET => [ l("\\begin{itemize}"), l("\\end{itemize}") ],
34
+ ListBase::NUMBER => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\arabic" ],
35
+ ListBase::UPPERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\Alph" ],
36
+ ListBase::LOWERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\alph" ],
37
+ ListBase::LABELED => [ l("\\begin{description}"), l("\\end{description}") ],
38
+ ListBase::NOTE => [
39
+ l("\\begin{tabularx}{\\linewidth}{@{} l X @{}}"),
40
+ l("\\end{tabularx}") ],
41
+ }
42
+
43
+ InlineTag = Struct.new(:bit, :on, :off)
44
+
45
+ def initialize
46
+ init_tags
47
+ @list_depth = 0
48
+ @prev_list_types = []
49
+ end
50
+
51
+ ##
52
+ # Set up the standard mapping of attributes to LaTeX
53
+ #
54
+ def init_tags
55
+ @attr_tags = [
56
+ InlineTag.new(SM::Attribute.bitmap_for(:BOLD), l("\\textbf{"), l("}")),
57
+ InlineTag.new(SM::Attribute.bitmap_for(:TT), l("\\texttt{"), l("}")),
58
+ InlineTag.new(SM::Attribute.bitmap_for(:EM), l("\\emph{"), l("}")),
59
+ ]
60
+ end
61
+
62
+ ##
63
+ # Escape a LaTeX string
64
+ def escape(str)
65
+ # $stderr.print "FE: ", str
66
+ s = str.
67
+ # sub(/\s+$/, '').
68
+ gsub(/([_\${}&%#])/, "#{BS}\\1").
69
+ gsub(/\\/, BACKSLASH).
70
+ gsub(/\^/, HAT).
71
+ gsub(/~/, TILDE).
72
+ gsub(/</, LESSTHAN).
73
+ gsub(/>/, GREATERTHAN).
74
+ gsub(/,,/, ",{},").
75
+ gsub(/\`/, BACKQUOTE)
76
+ # $stderr.print "-> ", s, "\n"
77
+ s
78
+ end
79
+
80
+ ##
81
+ # Add a new set of LaTeX tags for an attribute. We allow
82
+ # separate start and end tags for flexibility
83
+ #
84
+ def add_tag(name, start, stop)
85
+ @attr_tags << InlineTag.new(SM::Attribute.bitmap_for(name), start, stop)
86
+ end
87
+
88
+
89
+ ##
90
+ # Here's the client side of the visitor pattern
91
+
92
+ def start_accepting
93
+ @res = ""
94
+ @in_list_entry = []
95
+ end
96
+
97
+ def end_accepting
98
+ @res.tr(BS, '\\').tr(OB, '{').tr(CB, '}').tr(DL, '$')
99
+ end
100
+
101
+ def accept_paragraph(am, fragment)
102
+ @res << wrap(convert_flow(am.flow(fragment.txt)))
103
+ @res << "\n"
104
+ end
105
+
106
+ def accept_verbatim(am, fragment)
107
+ @res << "\n\\begin{code}\n"
108
+ @res << fragment.txt.sub(/[\n\s]+\Z/, '')
109
+ @res << "\n\\end{code}\n\n"
110
+ end
111
+
112
+ def accept_rule(am, fragment)
113
+ size = fragment.param
114
+ size = 10 if size > 10
115
+ @res << "\n\n\\rule{\\linewidth}{#{size}pt}\n\n"
116
+ end
117
+
118
+ def accept_list_start(am, fragment)
119
+ @res << list_name(fragment.type, true) <<"\n"
120
+ @in_list_entry.push false
121
+ end
122
+
123
+ def accept_list_end(am, fragment)
124
+ if tag = @in_list_entry.pop
125
+ @res << tag << "\n"
126
+ end
127
+ @res << list_name(fragment.type, false) <<"\n"
128
+ end
129
+
130
+ def accept_list_item(am, fragment)
131
+ if tag = @in_list_entry.last
132
+ @res << tag << "\n"
133
+ end
134
+ @res << list_item_start(am, fragment)
135
+ @res << wrap(convert_flow(am.flow(fragment.txt))) << "\n"
136
+ @in_list_entry[-1] = list_end_for(fragment.type)
137
+ end
138
+
139
+ def accept_blank_line(am, fragment)
140
+ # @res << "\n"
141
+ end
142
+
143
+ def accept_heading(am, fragment)
144
+ @res << convert_heading(fragment.head_level, am.flow(fragment.txt))
145
+ end
146
+
147
+ # This is a higher speed (if messier) version of wrap
148
+
149
+ def wrap(txt, line_len = 76)
150
+ res = ""
151
+ sp = 0
152
+ ep = txt.length
153
+ while sp < ep
154
+ # scan back for a space
155
+ p = sp + line_len - 1
156
+ if p >= ep
157
+ p = ep
158
+ else
159
+ while p > sp and txt[p] != ?\s
160
+ p -= 1
161
+ end
162
+ if p <= sp
163
+ p = sp + line_len
164
+ while p < ep and txt[p] != ?\s
165
+ p += 1
166
+ end
167
+ end
168
+ end
169
+ res << txt[sp...p] << "\n"
170
+ sp = p
171
+ sp += 1 while sp < ep and txt[sp] == ?\s
172
+ end
173
+ res
174
+ end
175
+
176
+ #######################################################################
177
+
178
+ private
179
+
180
+ #######################################################################
181
+
182
+ def on_tags(res, item)
183
+ attr_mask = item.turn_on
184
+ return if attr_mask.zero?
185
+
186
+ @attr_tags.each do |tag|
187
+ if attr_mask & tag.bit != 0
188
+ res << tag.on
189
+ end
190
+ end
191
+ end
192
+
193
+ def off_tags(res, item)
194
+ attr_mask = item.turn_off
195
+ return if attr_mask.zero?
196
+
197
+ @attr_tags.reverse_each do |tag|
198
+ if attr_mask & tag.bit != 0
199
+ res << tag.off
200
+ end
201
+ end
202
+ end
203
+
204
+ def convert_flow(flow)
205
+ res = ""
206
+ flow.each do |item|
207
+ case item
208
+ when String
209
+ # $stderr.puts "Converting '#{item}'"
210
+ res << convert_string(item)
211
+ when AttrChanger
212
+ off_tags(res, item)
213
+ on_tags(res, item)
214
+ when Special
215
+ res << convert_special(item)
216
+ else
217
+ raise "Unknown flow element: #{item.inspect}"
218
+ end
219
+ end
220
+ res
221
+ end
222
+
223
+ # some of these patterns are taken from SmartyPants...
224
+
225
+ def convert_string(item)
226
+
227
+ escape(item).
228
+
229
+
230
+ # convert ... to elipsis (and make sure .... becomes .<elipsis>)
231
+ gsub(/\.\.\.\./, '.\ldots{}').gsub(/\.\.\./, '\ldots{}').
232
+
233
+ # convert single closing quote
234
+ gsub(%r{([^ \t\r\n\[\{\(])\'}) { "#$1'" }.
235
+ gsub(%r{\'(?=\W|s\b)}) { "'" }.
236
+
237
+ # convert single opening quote
238
+ gsub(/'/, '`').
239
+
240
+ # convert double closing quote
241
+ gsub(%r{([^ \t\r\n\[\{\(])\"(?=\W)}) { "#$1''" }.
242
+
243
+ # convert double opening quote
244
+ gsub(/"/, "``").
245
+
246
+ # convert copyright
247
+ gsub(/\(c\)/, '\copyright{}')
248
+
249
+ end
250
+
251
+ def convert_special(special)
252
+ handled = false
253
+ Attribute.each_name_of(special.type) do |name|
254
+ method_name = "handle_special_#{name}"
255
+ if self.respond_to? method_name
256
+ special.text = send(method_name, special)
257
+ handled = true
258
+ end
259
+ end
260
+ raise "Unhandled special: #{special}" unless handled
261
+ special.text
262
+ end
263
+
264
+ def convert_heading(level, flow)
265
+ res =
266
+ case level
267
+ when 1 then "\\chapter{"
268
+ when 2 then "\\section{"
269
+ when 3 then "\\subsection{"
270
+ when 4 then "\\subsubsection{"
271
+ else "\\paragraph{"
272
+ end +
273
+ convert_flow(flow) +
274
+ "}\n"
275
+ end
276
+
277
+ def list_name(list_type, is_open_tag)
278
+ tags = LIST_TYPE_TO_LATEX[list_type] || raise("Invalid list type: #{list_type.inspect}")
279
+ if tags[2] # enumerate
280
+ if is_open_tag
281
+ @list_depth += 1
282
+ if @prev_list_types[@list_depth] != tags[2]
283
+ case @list_depth
284
+ when 1
285
+ roman = "i"
286
+ when 2
287
+ roman = "ii"
288
+ when 3
289
+ roman = "iii"
290
+ when 4
291
+ roman = "iv"
292
+ else
293
+ raise("Too deep list: level #{@list_depth}")
294
+ end
295
+ @prev_list_types[@list_depth] = tags[2]
296
+ return l("\\renewcommand{\\labelenum#{roman}}{#{tags[2]}{enum#{roman}}}") + "\n" + tags[0]
297
+ end
298
+ else
299
+ @list_depth -= 1
300
+ end
301
+ end
302
+ tags[ is_open_tag ? 0 : 1]
303
+ end
304
+
305
+ def list_item_start(am, fragment)
306
+ case fragment.type
307
+ when ListBase::BULLET, ListBase::NUMBER, ListBase::UPPERALPHA, ListBase::LOWERALPHA
308
+ "\\item "
309
+
310
+ when ListBase::LABELED
311
+ "\\item[" + convert_flow(am.flow(fragment.param)) + "] "
312
+
313
+ when ListBase::NOTE
314
+ convert_flow(am.flow(fragment.param)) + " & "
315
+ else
316
+ raise "Invalid list type"
317
+ end
318
+ end
319
+
320
+ def list_end_for(fragment_type)
321
+ case fragment_type
322
+ when ListBase::BULLET, ListBase::NUMBER, ListBase::UPPERALPHA, ListBase::LOWERALPHA, ListBase::LABELED
323
+ ""
324
+ when ListBase::NOTE
325
+ "\\\\\n"
326
+ else
327
+ raise "Invalid list type"
328
+ end
329
+ end
330
+
331
+ end
332
+
333
+ end
@@ -0,0 +1,60 @@
1
+ require 'action_view/helpers/date_helper'
2
+
3
+ class <%= class_name %>Plugin
4
+ org_methods = methods.collect{|m| m.to_sym}
5
+ Pathname.new(File.join(File.dirname(__FILE__), '<%= file_name %>_plugins')).children.each do |file|
6
+ if file.extname == ".rb"
7
+ self.class.class_eval file.read
8
+ end
9
+ end
10
+ @@plugin_methods = methods.collect{|m| m.to_sym} - org_methods
11
+
12
+ self.class.class_eval 'include ActionView::Helpers::DateHelper'
13
+
14
+ def self.plugin_method?(symbol)
15
+ @@plugin_methods.include? symbol.to_sym
16
+ end
17
+
18
+ def self.valid_arguments?(str)
19
+ if str =~ /\((.*)\)/
20
+ valid_arguments? $1.strip
21
+ else
22
+ while true
23
+ case str
24
+ when /^'.*?[^\\]'(.*)/, /\d*\.?\d+(.*)/
25
+ str = $1.strip
26
+ if str =~ /,(.*)/
27
+ str = $1.strip
28
+ elsif str.empty?
29
+ break true
30
+ else
31
+ break false
32
+ end
33
+ # when /\d*\.?\d+(.*)/
34
+ # str = $1.strip
35
+ # if str =~ /,(.*)/
36
+ # str = $1.strip
37
+ # elsif str.empty?
38
+ # break true
39
+ # else
40
+ # break false
41
+ # end
42
+ else
43
+ return (str.nil? or str.empty?)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def self.controller=(controller)
50
+ @@controller = controller
51
+ end
52
+
53
+ def self.controller
54
+ @@controller
55
+ end
56
+
57
+ def self.params
58
+ @@controller.params
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ def christel(message, url="")
2
+ "<img src=\"http://gedo-style.com/crstl/crstl.php?m=#{
3
+ URI.encode(message.chomp.toutf8)
4
+ }&u=#{url.chomp}\" alt=\"#{message}\" />"
5
+ end
@@ -0,0 +1,3 @@
1
+ def join(one, two, three, *others)
2
+ "#{one}, #{two}, #{three}, #{others}"
3
+ end
@@ -0,0 +1,17 @@
1
+ def link_to_attach(filename)
2
+ # "<a href=\"#{controller.url_for :controller=>'<%= file_name %>',
3
+ # :action=>'download',
4
+ # :id=>params[:id],
5
+ # :filename=>filename}\">#{filename}</a>"
6
+ id = if params.has_key? :id then params[:id] else Content.title2id(params[:title]) end
7
+ "<a href=\"/rails/attached/#{id}/#{filename}\" alt=\"#{filename}\">#{filename}</a>"
8
+ end
9
+
10
+ def attached_image(filename)
11
+ # "<img src=\"#{controller.url_for :controller=>'<%= file_name %>',
12
+ # :action=>'download',
13
+ # :id=>params[:id],
14
+ # :filename=>filename}\" alt=\"#{filename}\" />"
15
+ id = if params.has_key? :id then params[:id] else Content.title2id(params[:title]) end
16
+ "<img src=\"/rails/attached/#{id}/#{filename}\" alt=\"#{filename}\" />"
17
+ end
@@ -0,0 +1,8 @@
1
+ def recent(num=20)
2
+ "<ul>#{
3
+ (Content.find :all, :order=>'updated_at DESC', :limit=>num).collect do |content|
4
+ url = controller.url_for :controller=>'<%= file_name %>', :action=>'show', :title=>content.title
5
+ "<li title=\"#{time_ago_in_words(content.updated_at)}\"><a href=\"#{url}\">#{content.title}</a></li>\n"
6
+ end
7
+ }</ul>\n"
8
+ end
@@ -0,0 +1,8 @@
1
+ function retrospectTo(elm) {
2
+ if (confirm('以前のバージョンを表示しますか?')) {
3
+ document.location = elm.value;
4
+ }
5
+ else {
6
+ elm.value = elm.options[0].value;
7
+ }
8
+ }