sqliki 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/USAGE +1 -0
- data/{sqliki_generator-0.0.3.gemspec → sqliki_generator-0.0.4.gemspec} +5 -4
- data/sqliki_generator.rb +1 -1
- data/templates/README +6 -0
- data/templates/controller_sqliki_controller.rb +1 -1
- data/templates/lib_roparojo.rb +95 -0
- data/templates/model_draft.rb +24 -124
- data/templates/model_page.rb +22 -2
- metadata +5 -4
data/USAGE
CHANGED
@@ -2,17 +2,18 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
SPEC = Gem::Specification.new do |s|
|
4
4
|
s.name = %q{sqliki}
|
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
18
|
templates/model_draft.rb
|
18
19
|
templates/view_edit.rhtml
|
@@ -26,7 +27,7 @@ SPEC = Gem::Specification.new do |s|
|
|
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
33
|
s.add_dependency('RedCloth')
|
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
@@ -92,4 +92,10 @@ CREATE TABLE links (
|
|
92
92
|
Implemented Orphaned/Wanted/Recently_revised
|
93
93
|
Cleaned up the controller interface (w. the the
|
94
94
|
trick from Tobias Luetke's Postback Generator)
|
95
|
+
0.0.3
|
96
|
+
Fixed two typos in the gemspec that were making
|
97
|
+
it hard for some people to install
|
98
|
+
0.0.4
|
99
|
+
Added ".id" to the Uses of "User.current_user" to
|
100
|
+
fix a bug which misattributed pages
|
95
101
|
|
@@ -0,0 +1,95 @@
|
|
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_wiki_words,:pre_make_divs,:post_add_toggle]+rules))
|
14
|
+
end
|
15
|
+
def htmlesc(str,mode)
|
16
|
+
super
|
17
|
+
str
|
18
|
+
end
|
19
|
+
# Bracket free text consists of either
|
20
|
+
# characters that are not "{" or "}",
|
21
|
+
# one or two "{"s, not followed by a third "{",
|
22
|
+
# one or two "}"s, not followed by a third "}",
|
23
|
+
#
|
24
|
+
BRACKET_FREE_TEXT = "((:?[^{}]|[{]{1,2}(?![{])|[}]{1,2}(?![}]))*?)"
|
25
|
+
DIV_BRACKETS = /\{\{\{#{BRACKET_FREE_TEXT}\}\}\}/m
|
26
|
+
ALT_TEXT = /
|
27
|
+
(
|
28
|
+
([\s\[{(]|[#{PUNCT}])? # $pre
|
29
|
+
" # start
|
30
|
+
(#{C}) # $atts
|
31
|
+
([^"]+?) # $text
|
32
|
+
\s?
|
33
|
+
(?:\(([^)]+?)\)(?="))? # $title
|
34
|
+
":
|
35
|
+
)?
|
36
|
+
/mx
|
37
|
+
XDIV_RE = /
|
38
|
+
(
|
39
|
+
([\s\[{(]|[#{PUNCT}])? # $pre
|
40
|
+
" # start
|
41
|
+
(#{C}) # $atts
|
42
|
+
([^"]+?) # $text
|
43
|
+
\s?
|
44
|
+
(?:\(([^)]+?)\)(?="))? # $title
|
45
|
+
":
|
46
|
+
)?
|
47
|
+
#{DIV_BRACKETS} # $div_block
|
48
|
+
/mx
|
49
|
+
DIV_RE = /#{ALT_TEXT}#{DIV_BRACKETS}/m
|
50
|
+
|
51
|
+
def pre_make_divs( text )
|
52
|
+
## break the text into <div> blocks based on {{{ ... }}}
|
53
|
+
while text.gsub!( DIV_RE ) { |m|
|
54
|
+
has_link,pre,atts,link_text,title,div_block = $~.captures
|
55
|
+
if has_link
|
56
|
+
@need_toggle_function = true
|
57
|
+
id = "div_#{rand(100000)}"
|
58
|
+
atts = shelve(" onclick=\"toggle('#{id}'); return false;\" #{ pba(atts) } title=\"#{ title||'more...' }\"")
|
59
|
+
"#{ pre }<a#{ atts }>#{ link_text }</a><div id=\"#{id}\" style=\"display:none\">#{div_block}</div>"
|
60
|
+
else
|
61
|
+
"<div #{shelve(attrs) }>#{div_block}</div>"
|
62
|
+
end
|
63
|
+
}; end
|
64
|
+
text
|
65
|
+
end
|
66
|
+
def post_add_toggle(text)
|
67
|
+
text << %q{
|
68
|
+
<script type="text/javascript" language="JavaScript">
|
69
|
+
<!--
|
70
|
+
function toggle(name) {
|
71
|
+
q=document.getElementById(name);
|
72
|
+
if (q.style.display == 'none')
|
73
|
+
{q.style.display = 'block';}
|
74
|
+
else
|
75
|
+
{q.style.display = 'none';};
|
76
|
+
}
|
77
|
+
//-->
|
78
|
+
</script>
|
79
|
+
} if @need_toggle_function
|
80
|
+
end
|
81
|
+
NOT_WIKI_WORD = /\\(([A-Z]+[a-z0-9]+){2,})/
|
82
|
+
WIKI_WORD = /#{ALT_TEXT}(([A-Z]+['a-z1-9]+){2,})/
|
83
|
+
WIKI_PHRASE = /#{ALT_TEXT}\[\[(.*?)\]\]/m
|
84
|
+
def pre_wiki_words(text)
|
85
|
+
text.gsub!(NOT_WIKI_WORD) { |m| shelve $1 }
|
86
|
+
[WIKI_PHRASE,WIKI_WORD].each {|pattern|
|
87
|
+
text.gsub!(pattern) { |m|
|
88
|
+
has_link,pre,atts,link_text,title,ww = $~.captures
|
89
|
+
(pre||'') + shelve(@callback.call(:wiki_link,pattern,atts,link_text,ww))
|
90
|
+
}
|
91
|
+
}
|
92
|
+
text
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
data/templates/model_draft.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'sanitize_html'
|
2
|
-
require '
|
2
|
+
require 'roparojo'
|
3
3
|
|
4
4
|
class Draft < ActiveRecord::Base
|
5
5
|
acts_as_tree :foreign_key => 'based_on_draft_id'
|
@@ -13,129 +13,29 @@ class Draft < ActiveRecord::Base
|
|
13
13
|
def raw
|
14
14
|
body
|
15
15
|
end
|
16
|
-
|
17
|
-
|
18
|
-
@rules.each do |rule_name|
|
19
|
-
method( rule_name ).call( text ) if rule_name.to_s.match /^pre_/
|
20
|
-
end
|
21
|
-
super
|
22
|
-
end
|
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
|
125
|
-
RopaRojo.new(body, [:hard_breaks ]).to_html { |event,*details|
|
126
|
-
case event
|
127
|
-
when :wiki_link
|
128
|
-
link_text,ww = *details
|
129
|
-
page = (Page.find_by_title(ww) || Page.new_page(ww))
|
130
|
-
links << page unless links.include? page
|
131
|
-
nil
|
132
|
-
else
|
133
|
-
nil
|
134
|
-
end
|
135
|
-
}
|
136
|
-
end
|
137
|
-
end
|
16
|
+
include ActionView::Helpers::TagHelper
|
17
|
+
include ActionView::Helpers::UrlHelper
|
138
18
|
def html
|
139
|
-
sanitize_html(
|
19
|
+
sanitize_html(
|
20
|
+
#if body.blank?
|
21
|
+
# ""
|
22
|
+
# else
|
23
|
+
RopaRojo.new(body, [:hard_breaks ]).to_html { |event,*details|
|
24
|
+
case event
|
25
|
+
when :wiki_link
|
26
|
+
pattern,atts,link_text,ww = *details
|
27
|
+
ww = Page.key_from_CamelCase(ww) if pattern == RopaRojo::WIKI_WORD
|
28
|
+
page = (Page.find(ww) || Page.new_page(ww))
|
29
|
+
ww = page.title
|
30
|
+
links << page unless links.include? page
|
31
|
+
link_text = "<span #{pba(atts)}>#{link_text||ww}</span>"
|
32
|
+
link_to link_text, "/<%= file_name %>/show/#{Page.find_or_make(ww).for_URL}"
|
33
|
+
else
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
}
|
37
|
+
# end
|
38
|
+
)
|
140
39
|
end
|
141
40
|
end
|
41
|
+
|
data/templates/model_page.rb
CHANGED
@@ -7,7 +7,7 @@ class Page < ActiveRecord::Base
|
|
7
7
|
validates_length_of :title, :within => 1..80
|
8
8
|
validates_presence_of :title
|
9
9
|
def self.new_page(title)
|
10
|
-
p = Page.new :created_by => User.current_user, :title => title
|
10
|
+
p = Page.new :created_by => User.current_user.id, :title => title
|
11
11
|
p.raw = ''
|
12
12
|
p
|
13
13
|
end
|
@@ -18,7 +18,7 @@ class Page < ActiveRecord::Base
|
|
18
18
|
d = Draft.new(
|
19
19
|
:body => new_text || '',
|
20
20
|
:based_on_draft_id => self.current_draft && self.current_draft.id,
|
21
|
-
:created_by => User.current_user
|
21
|
+
:created_by => User.current_user.id
|
22
22
|
);
|
23
23
|
d.save;
|
24
24
|
self.current_draft = d
|
@@ -28,4 +28,24 @@ class Page < ActiveRecord::Base
|
|
28
28
|
def html
|
29
29
|
current_draft.html
|
30
30
|
end
|
31
|
+
def self.key_from_CamelCase(s)
|
32
|
+
s.gsub(/([a-z])([A-Z][a-z])/,'\1 \2')
|
33
|
+
end
|
34
|
+
def self.key_from_URL(s)
|
35
|
+
s.html_decode.gsub(/\+/,' ').gsub(/''/,'"')
|
36
|
+
end
|
37
|
+
def self.find(s*)
|
38
|
+
return super(s*) unless s.length == 1 and s.first.is_a? String
|
39
|
+
s = s.first
|
40
|
+
find_by_title(s) || ((s =~ /[a-z][A-Z][a-z]) && find_by_title(key_from_CamelCase(s)))
|
41
|
+
end
|
42
|
+
def for_URL
|
43
|
+
title.gsub(/ /,'+').gsub(/"/,"''").html_encode
|
44
|
+
end
|
45
|
+
def split_wiki_word(ww)
|
46
|
+
ww.gsub(/([a-z0-9])([A-Z])/,'\1 \2');
|
47
|
+
end
|
48
|
+
def clean_wiki_word(ww)
|
49
|
+
ww.gsub(/[^-A-Za-z0-9$_.+!*'(),]/,'')
|
50
|
+
end
|
31
51
|
end
|
metadata
CHANGED
@@ -3,13 +3,13 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: sqliki
|
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,6 +29,7 @@ authors:
|
|
29
29
|
files:
|
30
30
|
- USAGE
|
31
31
|
- templates/lib_sanitize_html.rb
|
32
|
+
- templates/lib_roparojo.rb
|
32
33
|
- templates/README
|
33
34
|
- templates/model_draft.rb
|
34
35
|
- templates/view_edit.rhtml
|
@@ -42,7 +43,7 @@ files:
|
|
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: []
|