sqliki_generator 0.0.2 → 0.0.4
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.
- data/USAGE +1 -0
- data/{sqliki_generator-0.0.2.gemspec → sqliki_generator-0.0.4.gemspec} +7 -6
- data/sqliki_generator.rb +1 -1
- data/templates/README +97 -3
- data/templates/controller_sqliki_controller.rb +9 -3
- data/templates/lib_roparojo.rb +140 -0
- data/templates/model_draft.rb +17 -118
- data/templates/model_page.rb +33 -2
- data/templates/view__form.rhtml +2 -1
- data/templates/view_inplace_edit.rhtml +15 -2
- metadata +7 -6
data/USAGE
CHANGED
@@ -2,19 +2,19 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
SPEC = Gem::Specification.new do |s|
|
4
4
|
s.name = %q{sqliki_generator}
|
5
|
-
s.version = "0.0.
|
6
|
-
s.date = %q{2005-
|
5
|
+
s.version = "0.0.4"
|
6
|
+
s.date = %q{2005-09-03}
|
7
7
|
s.summary = %q{[Rails] SQL-based wiki generator.}
|
8
8
|
s.require_paths = ["."]
|
9
9
|
s.email = %q{Markus@reality.com}
|
10
|
-
s.homepage = %q{http://
|
10
|
+
s.homepage = %q{http://rubyforge.org/projects/sqliki/}
|
11
11
|
s.description = %q{Generates code for (primative) a SQL-based wiki within your Rails app.}
|
12
12
|
s.authors = ["Markus J. Q. Roberts"]
|
13
13
|
s.files = %w{
|
14
14
|
USAGE
|
15
15
|
templates/lib_sanitize_html.rb
|
16
|
+
templates/lib_roparojo.rb
|
16
17
|
templates/README
|
17
|
-
templates/model_draft.rb
|
18
18
|
templates/view_edit.rhtml
|
19
19
|
templates/view__form.rhtml
|
20
20
|
templates/view_inplace_edit.rhtml
|
@@ -22,14 +22,15 @@ SPEC = Gem::Specification.new do |s|
|
|
22
22
|
templates/view_create.rhtml
|
23
23
|
templates/view_rollback.rhtml
|
24
24
|
templates/view_show.rhtml
|
25
|
+
templates/model_draft.rb
|
25
26
|
templates/model_link.rb
|
26
27
|
templates/model_page.rb
|
27
28
|
templates/controller_sqliki_controller.rb
|
28
29
|
sqliki_generator.rb
|
29
|
-
sqliki_generator-0.0.
|
30
|
+
sqliki_generator-0.0.4.gemspec
|
30
31
|
}
|
31
32
|
s.add_dependency('rails', [">= 0.13.1"])
|
32
|
-
s.add_dependency('
|
33
|
+
s.add_dependency('RedCloth')
|
33
34
|
end
|
34
35
|
|
35
36
|
if $0 == __FILE__
|
data/sqliki_generator.rb
CHANGED
@@ -16,7 +16,7 @@ class SqlikiGenerator < Rails::Generator::NamedBase
|
|
16
16
|
m.template "controller_sqliki_controller.rb",File.join("app/controllers", class_path, "#{file_name}_controller.rb")
|
17
17
|
|
18
18
|
# Libs.
|
19
|
-
%w{sanitize_html}.each do |x|
|
19
|
+
%w{sanitize_html roparojo}.each do |x|
|
20
20
|
m.template "lib_#{x}.rb",File.join("lib", class_path, "#{x}.rb")
|
21
21
|
end
|
22
22
|
|
data/templates/README
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
== Installation
|
2
2
|
|
3
|
-
NOTE: THIS IS
|
3
|
+
NOTE: THIS IS A LATE ALPHA VERSION OF SQLIKI
|
4
|
+
|
5
|
+
It is in use by several people, and almost ready to go beta.
|
6
|
+
But it is not feature-complete, and probably still has bugs.
|
4
7
|
|
5
8
|
Done generating SQLiki. but there are still a few things you have to
|
6
9
|
do manually.
|
@@ -82,6 +85,77 @@ CREATE TABLE links (
|
|
82
85
|
|
83
86
|
== Tips & Tricks
|
84
87
|
|
88
|
+
=== Inplace editing
|
89
|
+
|
90
|
+
This is still very alpha; it's working for me, but not yet well integrated in
|
91
|
+
the generator. If you want to hack on it, feel free, or you can wait until
|
92
|
+
I've given it a bit more testing/polish. Basically, in addition to SQLiki and
|
93
|
+
the usual ajax javascript, you will need to add something like this to your
|
94
|
+
application controller:
|
95
|
+
|
96
|
+
------------------------------------------------------------------------------------
|
97
|
+
after_filter :wikify
|
98
|
+
def wiki_fetch(word)
|
99
|
+
(p = Page.find(word)) ? p.current_draft.html : ''
|
100
|
+
end
|
101
|
+
def wiki_text(word)
|
102
|
+
word = $2 if word =~ /<a.*\/(show|new)\/(.+?)">.+?<\/a>/
|
103
|
+
word = $2 if word =~ /<a.*\/(show|new)\/(.+?)">.+?<\/a>/ #may only be needed because of another bug...
|
104
|
+
word = word.gsub(/\\/,'')
|
105
|
+
%Q{<div
|
106
|
+
id='web_#{word}'
|
107
|
+
class='wiki_edit_block'
|
108
|
+
ondblclick="#{remote_function(:url => { :controller => 'wiki', :action => 'inplace_edit', :id => word}, :update => "web_#{word}", :method => 'get')};"
|
109
|
+
>
|
110
|
+
#{wikify(wiki_fetch(word))}
|
111
|
+
</div>}
|
112
|
+
end
|
113
|
+
def wiki_link(word,mode=:show,content=word)
|
114
|
+
"<a class='wiki_#{mode}_link' href='http://127.0.0.1:2500/wiki/#{mode}/#{word}'>#{content}</a>"
|
115
|
+
end
|
116
|
+
def wikify(what = @response.body)
|
117
|
+
processing = true
|
118
|
+
what.gsub!(/wiki_(link|text|processing)\[(.+?)\]/) {
|
119
|
+
case $1
|
120
|
+
when 'processing' then processing = $2 == 'on'; ''
|
121
|
+
when 'text' then processing ? wiki_text($2) : "wiki_#{$1}[#{$2}]"
|
122
|
+
else processing ? wiki_link($2) : "wiki_#{$1}[#{$2}]"
|
123
|
+
end
|
124
|
+
}
|
125
|
+
what
|
126
|
+
end
|
127
|
+
------------------------------------------------------------------------------------
|
128
|
+
|
129
|
+
and something like this to your css so you can identify editable blocks (intentionally
|
130
|
+
ugly colours to prompt you to choose your own):
|
131
|
+
|
132
|
+
------------------------------------------------------------------------------------
|
133
|
+
|
134
|
+
div.wiki_edit_block { padding-right: 3px; }
|
135
|
+
div.wiki_edit_block:hover {
|
136
|
+
background-color: #8f0;
|
137
|
+
color: black;
|
138
|
+
padding-right: 0px;
|
139
|
+
border-right: solid 1px f08;
|
140
|
+
margin-right: 2px;
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
------------------------------------------------------------------------------------
|
145
|
+
|
146
|
+
Then, in your web pages, just put "wiki_text[MyPage]" wherever you want to get the
|
147
|
+
content from the wiki as in-place editable text (double click to edit).
|
148
|
+
|
149
|
+
Planned extentions:
|
150
|
+
|
151
|
+
* page-by-page access control (so that only authorized users can see/edit text)
|
152
|
+
*
|
153
|
+
|
154
|
+
Planned uses:
|
155
|
+
|
156
|
+
* A help system generator
|
157
|
+
*
|
158
|
+
|
85
159
|
== Changelog
|
86
160
|
|
87
161
|
0.0.1
|
@@ -90,6 +164,26 @@ CREATE TABLE links (
|
|
90
164
|
Made the name of the controller changeable
|
91
165
|
Removed the system specific path for RedCloth
|
92
166
|
Implemented Orphaned/Wanted/Recently_revised
|
93
|
-
Cleaned up the controller interface (w. the the
|
94
|
-
|
167
|
+
Cleaned up the controller interface (w. the the trick from
|
168
|
+
Tobias Luetke's Postback Generator)
|
169
|
+
0.0.3
|
170
|
+
Fixed two typos in the gemspec that were making it hard for
|
171
|
+
some people to install
|
172
|
+
0.0.4
|
173
|
+
Added ".id" to the Uses of "User.current_user" to fix a bug
|
174
|
+
which misattributed pages
|
175
|
+
Reworked & cleaned up page name canonicalization
|
176
|
+
Split RopoRoja (RedCloth wrapper) off to its own file in /lib/
|
177
|
+
Added rudamentary tab/notebook/accordion support (Sabre Airline
|
178
|
+
Solutions's rico.js library is needed for this; see
|
179
|
+
http://openrico.org/rico/home.page)
|
180
|
+
Got inplace_editing working (additional code needed in
|
181
|
+
application. See README_SQL/Tips & Tricks/Inplace editing)
|
182
|
+
Fixed a minor cross-browser ("Is the IE development team on
|
183
|
+
drugs?!") bug.
|
184
|
+
Began live testing with the goal of releasing a 0.1.0 beta in a
|
185
|
+
week or so.
|
186
|
+
|
187
|
+
|
188
|
+
|
95
189
|
|
@@ -3,7 +3,7 @@ class <%= class_name %>Controller < ApplicationController
|
|
3
3
|
include LoginSystem
|
4
4
|
before_filter :login_required
|
5
5
|
def identify_page
|
6
|
-
@page ||= Page.
|
6
|
+
@page ||= Page.find(Page.key_from_URL(params[:id]))
|
7
7
|
end
|
8
8
|
def index
|
9
9
|
list
|
@@ -55,9 +55,11 @@ class <%= class_name %>Controller < ApplicationController
|
|
55
55
|
end
|
56
56
|
def inplace_edit
|
57
57
|
if not identify_page
|
58
|
-
|
58
|
+
render :action => 'create', :layout => false
|
59
59
|
elsif @request.post? and @page.update_attributes(params[:page])
|
60
|
-
|
60
|
+
html
|
61
|
+
else
|
62
|
+
render :action => 'inplace_edit', :layout => false
|
61
63
|
end
|
62
64
|
end
|
63
65
|
def edit
|
@@ -72,5 +74,9 @@ class <%= class_name %>Controller < ApplicationController
|
|
72
74
|
identify_page.destroy if @request.post?
|
73
75
|
redirect_to :action => 'list'
|
74
76
|
end
|
77
|
+
#def wikify(what = @response.body)
|
78
|
+
# # don't wikify the wiki!
|
79
|
+
# super if %w{cancel_inplace_edit save_inplace}.include? @params[:action]
|
80
|
+
# end
|
75
81
|
end
|
76
82
|
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'redcloth'
|
2
|
+
|
3
|
+
class RopaRojo < RedCloth
|
4
|
+
def hard_break(text)
|
5
|
+
@rules.each do |rule_name|
|
6
|
+
method( rule_name ).call( text ) if rule_name.to_s.match /^pre_/
|
7
|
+
end
|
8
|
+
#super
|
9
|
+
end
|
10
|
+
def to_html(*rules,&callback)
|
11
|
+
@callback = callback
|
12
|
+
rules = DEFAULT_RULES if rules.empty?
|
13
|
+
text = super(*([:pre_accordion,:pre_wiki_words,:pre_make_divs,:post_add_toggle]+rules))
|
14
|
+
@rules.each do |rule_name|
|
15
|
+
method( rule_name ).call( text ) if rule_name.to_s.match /^post_/
|
16
|
+
end
|
17
|
+
text
|
18
|
+
end
|
19
|
+
def htmlesc(str,mode)
|
20
|
+
super
|
21
|
+
str
|
22
|
+
end
|
23
|
+
ACCEDENTAL_WIKI_WORD = /(([A-Z]+[a-z0-9]+){2,})/
|
24
|
+
def text_from(lines,block_type=nil)
|
25
|
+
result = []
|
26
|
+
while line = lines.shift and not (line =~ /^\.wiki_(?:accordion|notebook|tab)_end/)
|
27
|
+
result << case line
|
28
|
+
when /^\.wiki_accordion *(.*)$/
|
29
|
+
name = "accordionDiv#{@panel}"
|
30
|
+
"\n<div #{(shelve %Q{id="#{name}" class="accordionDiv"})}>"+
|
31
|
+
text_from(lines,'accordion')+
|
32
|
+
%Q{</div>
|
33
|
+
<script type="text/javascript" language="javascript">
|
34
|
+
// <![CDATA[
|
35
|
+
#{ shelve "new Rico.Accordion( $('#{name}'), {panelHeight:350} );"}
|
36
|
+
// ]]>
|
37
|
+
</script>
|
38
|
+
}
|
39
|
+
when /^\.wiki_notebook *(.*)$/
|
40
|
+
when /^\.wiki_tab *(.*)$/
|
41
|
+
@panel += 1
|
42
|
+
(shelve %Q{
|
43
|
+
<div id="panel#{@panel}">
|
44
|
+
<div id="panel#{@panel}Header" class="accordionTabTitleBar">})+$1+"</div>"+
|
45
|
+
(shelve %Q{<div id="panel#{@panel}Content" class="accordionTabContentBox"><div>})+
|
46
|
+
text_from(lines,'tab')+
|
47
|
+
"</div></div></div>"
|
48
|
+
else line
|
49
|
+
end
|
50
|
+
end
|
51
|
+
if line and block_type and line !~ /^\.wiki_#{block_type}_end/
|
52
|
+
lines.unshift line
|
53
|
+
line = nil
|
54
|
+
end
|
55
|
+
lines.unshift "\nERROR: expected '.wiki_#{block_type}_end'\n" if block_type and !line
|
56
|
+
lines.unshift "\nERROR: unexpected '#{line}'\n" if line and !block_type
|
57
|
+
result.join
|
58
|
+
end
|
59
|
+
def pre_accordion(text)
|
60
|
+
@panel = 1
|
61
|
+
lines = text.split(/^(\.wiki_(?:accordion|notebook|tab)(?:_end)?.*?)$/im)
|
62
|
+
text.replace text_from(lines)
|
63
|
+
end
|
64
|
+
# Bracket free text consists of either
|
65
|
+
# characters that are not "{" or "}",
|
66
|
+
# one or two "{"s, not followed by a third "{",
|
67
|
+
# one or two "}"s, not followed by a third "}",
|
68
|
+
#
|
69
|
+
BRACKET_FREE_TEXT = "((:?[^{}]|[{]{1,2}(?![{])|[}]{1,2}(?![}]))*?)"
|
70
|
+
DIV_BRACKETS = /\{\{\{#{BRACKET_FREE_TEXT}\}\}\}/m
|
71
|
+
ALT_TEXT = /
|
72
|
+
(
|
73
|
+
([\s\[{(]|[#{PUNCT}])? # $pre
|
74
|
+
" # start
|
75
|
+
(#{C}) # $atts
|
76
|
+
([^"]+?) # $text
|
77
|
+
\s?
|
78
|
+
(?:\(([^)]+?)\)(?="))? # $title
|
79
|
+
":
|
80
|
+
)?
|
81
|
+
/mx
|
82
|
+
XDIV_RE = /
|
83
|
+
(
|
84
|
+
([\s\[{(]|[#{PUNCT}])? # $pre
|
85
|
+
" # start
|
86
|
+
(#{C}) # $atts
|
87
|
+
([^"]+?) # $text
|
88
|
+
\s?
|
89
|
+
(?:\(([^)]+?)\)(?="))? # $title
|
90
|
+
":
|
91
|
+
)?
|
92
|
+
#{DIV_BRACKETS} # $div_block
|
93
|
+
/mx
|
94
|
+
DIV_RE = /#{ALT_TEXT}#{DIV_BRACKETS}/m
|
95
|
+
|
96
|
+
def pre_make_divs( text )
|
97
|
+
## break the text into <div> blocks based on {{{ ... }}}
|
98
|
+
while text.gsub!( DIV_RE ) { |m|
|
99
|
+
has_link,pre,atts,link_text,title,div_block = $~.captures
|
100
|
+
if has_link
|
101
|
+
@need_toggle_function = true
|
102
|
+
id = "div_#{rand(100000)}"
|
103
|
+
atts = shelve(" onclick=\"toggle('#{id}'); return false;\" #{ pba(atts) } title=\"#{ title||'more...' }\"")
|
104
|
+
"#{ pre }<a#{ atts }>#{ link_text }</a><div id=\"#{id}\" style=\"display:none\">#{div_block}</div>"
|
105
|
+
else
|
106
|
+
"<div #{shelve(attrs) }>#{div_block}</div>"
|
107
|
+
end
|
108
|
+
}; end
|
109
|
+
text
|
110
|
+
end
|
111
|
+
def post_add_toggle(text)
|
112
|
+
text << %q{
|
113
|
+
<script type="text/javascript" language="JavaScript">
|
114
|
+
<!--
|
115
|
+
function toggle(name) {
|
116
|
+
q=document.getElementById(name);
|
117
|
+
if (q.style.display == 'none')
|
118
|
+
{q.style.display = 'block';}
|
119
|
+
else
|
120
|
+
{q.style.display = 'none';};
|
121
|
+
}
|
122
|
+
//-->
|
123
|
+
</script>
|
124
|
+
} if @need_toggle_function
|
125
|
+
end
|
126
|
+
NOT_WIKI_WORD = /\\(([A-Z]+[a-z0-9]+){2,})/
|
127
|
+
WIKI_WORD = /#{ALT_TEXT}(([A-Z]+['a-z1-9]+){2,})/
|
128
|
+
WIKI_PHRASE = /#{ALT_TEXT}\[\[(.*?)\]\]/m
|
129
|
+
def pre_wiki_words(text)
|
130
|
+
text.gsub!(NOT_WIKI_WORD) { |m| shelve $1 }
|
131
|
+
[WIKI_PHRASE,WIKI_WORD].each {|pattern|
|
132
|
+
text.gsub!(pattern) { |m|
|
133
|
+
has_link,pre,atts,link_text,title,ww = $~.captures
|
134
|
+
(pre||'') + shelve(@callback.call(:wiki_link,pattern,pba(atts),link_text,ww))
|
135
|
+
}
|
136
|
+
}
|
137
|
+
text
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
data/templates/model_draft.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'sanitize_html'
|
2
|
-
require '
|
2
|
+
require 'roparojo'
|
3
|
+
require 'cgi'
|
3
4
|
|
4
5
|
class Draft < ActiveRecord::Base
|
5
6
|
acts_as_tree :foreign_key => 'based_on_draft_id'
|
@@ -13,129 +14,27 @@ class Draft < ActiveRecord::Base
|
|
13
14
|
def raw
|
14
15
|
body
|
15
16
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def to_html(*rules,&callback)
|
24
|
-
@callback = callback
|
25
|
-
rules = DEFAULT_RULES if rules.empty?
|
26
|
-
text = super(*([:pre_wiki_words,:pre_make_divs,:post_add_toggle]+rules))
|
27
|
-
end
|
28
|
-
def htmlesc(str,mode)
|
29
|
-
super
|
30
|
-
str
|
31
|
-
end
|
32
|
-
# Bracket free text consists of either
|
33
|
-
# characters that are not "{" or "}",
|
34
|
-
# one or two "{"s, not followed by a third "{",
|
35
|
-
# one or two "}"s, not followed by a third "}",
|
36
|
-
#
|
37
|
-
BRACKET_FREE_TEXT = "((:?[^{}]|[{]{1,2}(?![{])|[}]{1,2}(?![}]))*?)"
|
38
|
-
DIV_BRACKETS = /\{\{\{#{BRACKET_FREE_TEXT}\}\}\}/m
|
39
|
-
ALT_TEXT = /
|
40
|
-
(
|
41
|
-
([\s\[{(]|[#{PUNCT}])? # $pre
|
42
|
-
" # start
|
43
|
-
(#{C}) # $atts
|
44
|
-
([^"]+?) # $text
|
45
|
-
\s?
|
46
|
-
(?:\(([^)]+?)\)(?="))? # $title
|
47
|
-
":
|
48
|
-
)?
|
49
|
-
/mx
|
50
|
-
XDIV_RE = /
|
51
|
-
(
|
52
|
-
([\s\[{(]|[#{PUNCT}])? # $pre
|
53
|
-
" # start
|
54
|
-
(#{C}) # $atts
|
55
|
-
([^"]+?) # $text
|
56
|
-
\s?
|
57
|
-
(?:\(([^)]+?)\)(?="))? # $title
|
58
|
-
":
|
59
|
-
)?
|
60
|
-
#{DIV_BRACKETS} # $div_block
|
61
|
-
/mx
|
62
|
-
DIV_RE = /#{ALT_TEXT}#{DIV_BRACKETS}/m
|
63
|
-
|
64
|
-
def pre_make_divs( text )
|
65
|
-
## break the text into <div> blocks based on {{{ ... }}}
|
66
|
-
while text.gsub!( DIV_RE ) { |m|
|
67
|
-
has_link,pre,atts,link_text,title,div_block = $~.captures
|
68
|
-
if has_link
|
69
|
-
@need_toggle_function = true
|
70
|
-
id = "div_#{rand(100000)}"
|
71
|
-
atts = shelve(" onclick=\"toggle('#{id}'); return false;\" #{ pba(atts) } title=\"#{ title||'more...' }\"")
|
72
|
-
"#{ pre }<a#{ atts }>#{ link_text }</a><div id=\"#{id}\" style=\"display:none\">#{div_block}</div>"
|
73
|
-
else
|
74
|
-
"<div #{shelve(attrs) }>#{div_block}</div>"
|
75
|
-
end
|
76
|
-
}; end
|
77
|
-
text
|
78
|
-
end
|
79
|
-
def post_add_toggle(text)
|
80
|
-
text << %q{
|
81
|
-
<script type="text/javascript" language="JavaScript">
|
82
|
-
<!--
|
83
|
-
function toggle(name) {
|
84
|
-
q=document.getElementById(name);
|
85
|
-
if (q.style.display == 'none')
|
86
|
-
{q.style.display = 'block';}
|
87
|
-
else
|
88
|
-
{q.style.display = 'none';};
|
89
|
-
}
|
90
|
-
//-->
|
91
|
-
</script>
|
92
|
-
} if @need_toggle_function
|
93
|
-
end
|
94
|
-
NOT_WIKI_WORD = /\\(([A-Z]+[a-z0-9]+){2,})/
|
95
|
-
WIKI_WORD = /#{ALT_TEXT}(([A-Z]+[a-z1-9]+){2,})/
|
96
|
-
WIKI_PHRASE = /#{ALT_TEXT}\[\[(.*?)\]\]/m
|
97
|
-
def split_wiki_word(ww)
|
98
|
-
ww.gsub(/([a-z0-9])([A-Z])/,'\1 \2');
|
99
|
-
end
|
100
|
-
def clean_wiki_word(ww)
|
101
|
-
ww.gsub(/[^A-Za-z0-9$-_.+!*'(),]/,'')
|
102
|
-
end
|
103
|
-
include ActionView::Helpers::TagHelper
|
104
|
-
include ActionView::Helpers::UrlHelper
|
105
|
-
def wiki_link(link_text,ww)
|
106
|
-
(@callback && @callback.call(:wiki_link,link_text,ww)) ||
|
107
|
-
(link_to link_text, "/<%= file_name %>/show/#{clean_wiki_word(ww)}")
|
108
|
-
end
|
109
|
-
def pre_wiki_words(text)
|
110
|
-
text.gsub!(NOT_WIKI_WORD) { |m| shelve $1 }
|
111
|
-
[WIKI_PHRASE,WIKI_WORD].each {|pattern|
|
112
|
-
text.gsub!(pattern) { |m|
|
113
|
-
has_link,pre,atts,link_text,title,ww = $~.captures
|
114
|
-
ww = split_wiki_word(ww) if pattern == WIKI_WORD
|
115
|
-
(pre||'') + shelve(wiki_link("<span #{pba(atts)}>#{link_text||ww}</span>",ww))
|
116
|
-
}
|
117
|
-
}
|
118
|
-
text
|
119
|
-
end
|
120
|
-
end
|
121
|
-
def textilize(body) #html
|
122
|
-
if body.blank?
|
123
|
-
""
|
124
|
-
else
|
17
|
+
include ActionView::Helpers::TagHelper
|
18
|
+
include ActionView::Helpers::UrlHelper
|
19
|
+
def html
|
20
|
+
@controller = []
|
21
|
+
#ObjectSpace.each_object(<%= class_name %>Controller) { |wc| @controller = wc }
|
22
|
+
ObjectSpace.each_object(ApplicationController) { |wc| @controller = wc }
|
23
|
+
sanitize_html(
|
125
24
|
RopaRojo.new(body, [:hard_breaks ]).to_html { |event,*details|
|
126
25
|
case event
|
127
26
|
when :wiki_link
|
128
|
-
link_text,ww = *details
|
129
|
-
|
27
|
+
pattern,attributes,link_text,ww = *details
|
28
|
+
ww = Page.key_from_CamelCase(ww) if pattern == RopaRojo::WIKI_WORD
|
29
|
+
page = (Page.find(ww) || Page.new_page(ww))
|
30
|
+
ww = page.title
|
130
31
|
links << page unless links.include? page
|
131
|
-
|
32
|
+
#link_to "<span #{attributes}>#{link_text||ww}</span>",:action => "show", :id => page.for_URL
|
33
|
+
link_to "<span #{attributes}>#{link_text||ww}</span>",:controller => "<%= file_name %>", :action => "show", :id => page.for_URL
|
132
34
|
else
|
133
35
|
nil
|
134
36
|
end
|
135
|
-
}
|
136
|
-
end
|
137
|
-
end
|
138
|
-
def html
|
139
|
-
sanitize_html(textilize(body))
|
37
|
+
})
|
140
38
|
end
|
141
39
|
end
|
40
|
+
|
data/templates/model_page.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
1
3
|
class Page < ActiveRecord::Base
|
2
4
|
belongs_to :current_draft, :class_name => 'Draft', :foreign_key => :current_draft_id
|
3
5
|
has_many :drafts, :foreign_key => :draft_of_page_id
|
@@ -7,7 +9,7 @@ class Page < ActiveRecord::Base
|
|
7
9
|
validates_length_of :title, :within => 1..80
|
8
10
|
validates_presence_of :title
|
9
11
|
def self.new_page(title)
|
10
|
-
p = Page.new :created_by => User.current_user, :title => title
|
12
|
+
p = Page.new :created_by => User.current_user.id, :title => title
|
11
13
|
p.raw = ''
|
12
14
|
p
|
13
15
|
end
|
@@ -18,7 +20,7 @@ class Page < ActiveRecord::Base
|
|
18
20
|
d = Draft.new(
|
19
21
|
:body => new_text || '',
|
20
22
|
:based_on_draft_id => self.current_draft && self.current_draft.id,
|
21
|
-
:created_by => User.current_user
|
23
|
+
:created_by => User.current_user.id
|
22
24
|
);
|
23
25
|
d.save;
|
24
26
|
self.current_draft = d
|
@@ -28,4 +30,33 @@ class Page < ActiveRecord::Base
|
|
28
30
|
def html
|
29
31
|
current_draft.html
|
30
32
|
end
|
33
|
+
#
|
34
|
+
# Key/URL/title/text canonicalization
|
35
|
+
#
|
36
|
+
def self.key_from_CamelCase(s)
|
37
|
+
s.gsub(/([a-z])([A-Z][a-z])/,'\1 \2')
|
38
|
+
end
|
39
|
+
def self.key_from_URL(s)
|
40
|
+
URI.unescape(s||'').gsub(/[+_]/,' ').gsub(/''/,'"')
|
41
|
+
end
|
42
|
+
def self.key_from_text(s)
|
43
|
+
s.gsub(/[+_]/,' ').gsub(/''/,'"')
|
44
|
+
end
|
45
|
+
def for_URL
|
46
|
+
URI.escape(title.gsub(/ /,'+').gsub(/"/,"''"),/[^-A-Za-z0-9$_.+!*'(),]/)
|
47
|
+
end
|
48
|
+
#def split_wiki_word(ww)
|
49
|
+
# ww.gsub(/([a-z0-9])([A-Z])/,'\1 \2');
|
50
|
+
# end
|
51
|
+
#def clean_wiki_word(ww)
|
52
|
+
# ww.gsub(/[^-A-Za-z0-9$_.+!*'(),]/,'')
|
53
|
+
# end
|
54
|
+
def self.find(*s)
|
55
|
+
return super(*s) unless s.length == 1 and s.first.is_a? String
|
56
|
+
s = key_from_text(s.first)
|
57
|
+
find_by_title(s) ||
|
58
|
+
((s =~ /[a-z][A-Z][a-z]/) && find_by_title(key_from_CamelCase(s))) ||
|
59
|
+
find_by_sql(["SELECT * FROM pages WHERE REPLACE(title,' ','')=?",s.gsub(/ /,'')]).first
|
60
|
+
end
|
31
61
|
end
|
62
|
+
|
data/templates/view__form.rhtml
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
<%%= error_messages_for 'page' %>
|
2
2
|
|
3
3
|
<!--[form:page]-->
|
4
|
-
|
4
|
+
<!-- wiki_processing[off] -->
|
5
5
|
<%% unless @page.title %>
|
6
6
|
<p><label for="page_title">Title</label><br/>
|
7
7
|
<%%= text_field 'page', 'title' %></p>
|
8
8
|
<%% end %>
|
9
9
|
<%%= text_area 'page', 'raw' %></p>
|
10
10
|
|
11
|
+
<!-- wiki_processing[on] -->
|
11
12
|
<!--[eoform:page]-->
|
12
13
|
|
@@ -1,2 +1,15 @@
|
|
1
|
-
<h1
|
2
|
-
|
1
|
+
<h1><%%= @page.title %></h1>
|
2
|
+
|
3
|
+
<%%= form_remote_tag(:html => {}, :url => { :action => 'inplace_edit', :id => @params[:id]}, :update => "web_#{@params[:id]}") %>
|
4
|
+
<%%= render_partial 'form' %>
|
5
|
+
<%%= submit_tag 'Save changes' %>
|
6
|
+
<%%= link_to_function(
|
7
|
+
'Cancel edit',
|
8
|
+
remote_function(
|
9
|
+
:url => { :controller => 'wiki', :action => 'html', :id => @params[:id]},
|
10
|
+
:update => "web_#{@params[:id]}"
|
11
|
+
)
|
12
|
+
) %>
|
13
|
+
<%%= end_form_tag %>
|
14
|
+
|
15
|
+
|
metadata
CHANGED
@@ -3,13 +3,13 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: sqliki_generator
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2005-
|
6
|
+
version: 0.0.4
|
7
|
+
date: 2005-09-03
|
8
8
|
summary: "[Rails] SQL-based wiki generator."
|
9
9
|
require_paths:
|
10
10
|
- "."
|
11
11
|
email: Markus@reality.com
|
12
|
-
homepage: http://
|
12
|
+
homepage: http://rubyforge.org/projects/sqliki/
|
13
13
|
rubyforge_project:
|
14
14
|
description: Generates code for (primative) a SQL-based wiki within your Rails app.
|
15
15
|
autorequire:
|
@@ -29,8 +29,8 @@ authors:
|
|
29
29
|
files:
|
30
30
|
- USAGE
|
31
31
|
- templates/lib_sanitize_html.rb
|
32
|
+
- templates/lib_roparojo.rb
|
32
33
|
- templates/README
|
33
|
-
- templates/model_draft.rb
|
34
34
|
- templates/view_edit.rhtml
|
35
35
|
- templates/view__form.rhtml
|
36
36
|
- templates/view_inplace_edit.rhtml
|
@@ -38,11 +38,12 @@ files:
|
|
38
38
|
- templates/view_create.rhtml
|
39
39
|
- templates/view_rollback.rhtml
|
40
40
|
- templates/view_show.rhtml
|
41
|
+
- templates/model_draft.rb
|
41
42
|
- templates/model_link.rb
|
42
43
|
- templates/model_page.rb
|
43
44
|
- templates/controller_sqliki_controller.rb
|
44
45
|
- sqliki_generator.rb
|
45
|
-
- sqliki_generator-0.0.
|
46
|
+
- sqliki_generator-0.0.4.gemspec
|
46
47
|
test_files: []
|
47
48
|
rdoc_options: []
|
48
49
|
extra_rdoc_files: []
|
@@ -61,7 +62,7 @@ dependencies:
|
|
61
62
|
version: 0.13.1
|
62
63
|
version:
|
63
64
|
- !ruby/object:Gem::Dependency
|
64
|
-
name:
|
65
|
+
name: RedCloth
|
65
66
|
version_requirement:
|
66
67
|
version_requirements: !ruby/object:Gem::Version::Requirement
|
67
68
|
requirements:
|