WatersOfOblivion-wikipodia 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +83 -0
- data/Rakefile +23 -0
- data/init.rb +2 -0
- data/install.rb +1 -0
- data/lib/wikipodia.rb +56 -0
- data/rails/init.rb +4 -0
- data/test/test_helper.rb +5 -0
- data/test/wikipodia_test.rb +121 -0
- data/uninstall.rb +1 -0
- metadata +66 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
=Wikipodia
|
2
|
+
|
3
|
+
Wikipodia is a DSL for defining wikis within a Controller. It contains a small
|
4
|
+
preprocessor which recognizes links within text and converts them to user
|
5
|
+
defined formats. It allows a way to define these formats and a way in which to
|
6
|
+
display content being linked to.
|
7
|
+
|
8
|
+
==A Simple Example
|
9
|
+
|
10
|
+
For example, a simple wiki which just has pages processed with RedCloth:
|
11
|
+
|
12
|
+
class FooController < ActionController::Base
|
13
|
+
wikipodia do
|
14
|
+
# Define a link to another page
|
15
|
+
section :page do
|
16
|
+
# Define what to do when one of the links is clicked
|
17
|
+
action do
|
18
|
+
@page = Page.find(params[:id])
|
19
|
+
render :text => RedCloth.new(handle_wiki_links(@page.content)).to_html
|
20
|
+
end
|
21
|
+
|
22
|
+
# Define how to transform the link
|
23
|
+
url do |id, text|
|
24
|
+
"\"#{text}\":#{page_path(id)}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Anywhere in <tt>@page.content</tt>, links of the format
|
31
|
+
<tt>[[page:some-id Some Text]]</tt> will be converted into RedCloth links of the
|
32
|
+
format <tt>"Some Text":/page/some-id</tt>.
|
33
|
+
|
34
|
+
==A More Complex Example
|
35
|
+
|
36
|
+
A more complete wiki might support not only pages, but images and file
|
37
|
+
downloads:
|
38
|
+
|
39
|
+
class MiniWikiController < ActionController::Base
|
40
|
+
wikipodia do
|
41
|
+
section :page do
|
42
|
+
action do
|
43
|
+
@page = Page.find(params[:id])
|
44
|
+
render :text => RedCloth.new(handle_wiki_links(@page.content)).to_html
|
45
|
+
end
|
46
|
+
|
47
|
+
url do |id, text|
|
48
|
+
"\"#{text}\":#{page_path(id)}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
section :image do
|
53
|
+
action do
|
54
|
+
@image = Image.find(params[:id])
|
55
|
+
send_data @image.content
|
56
|
+
end
|
57
|
+
|
58
|
+
url do |id, text|
|
59
|
+
"!#{image_path(id)}!"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
section :document do
|
64
|
+
action do
|
65
|
+
@document = Documents.find(params[:id])
|
66
|
+
send_data @document.content, :filename => @document.original_filename, :type => @document.content_type
|
67
|
+
end
|
68
|
+
|
69
|
+
url do |id, text|
|
70
|
+
"\"#{text}\":#{document_path(id)}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
==Gem
|
77
|
+
|
78
|
+
This plugin is available as a Gem. To use it, simply add the following line to
|
79
|
+
your <tt>config/environment.rb</tt> and run <tt>rake gems:install</tt>:
|
80
|
+
|
81
|
+
config.gem "WatersOfOblivion-wikipodia", :lib => "wikipodia", :source => "http://gems.github.com/"
|
82
|
+
|
83
|
+
Copyright (c) 2009 Jonathan Bryant, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the wikipodia plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the wikipodia plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'Wikipodia'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/wikipodia.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Wikipodia
|
2
|
+
|
3
|
+
module Wikipodia
|
4
|
+
def self.included(base)
|
5
|
+
base.send :extend, ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def wikipodia options = {}, &definition
|
10
|
+
instance_eval do
|
11
|
+
define_method :handle_wiki_links do |text|
|
12
|
+
text.gsub /\[\[([-\w\d]+):([-\w\d]+)\s+(.*)\]\]/ do |link|
|
13
|
+
send "handle_#{$1}_link".to_sym, $2, $3
|
14
|
+
end
|
15
|
+
end
|
16
|
+
protected :handle_wiki_links
|
17
|
+
end
|
18
|
+
|
19
|
+
@wikipodia = Wikipodia.new(self)
|
20
|
+
@wikipodia.instance_eval &definition if definition
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Wikipodia
|
25
|
+
def initialize(controller)
|
26
|
+
@controller = controller
|
27
|
+
@sections ||= {}
|
28
|
+
end
|
29
|
+
|
30
|
+
def section name, options = {}, &definition
|
31
|
+
@sections[name] = Section.new(@controller, name)
|
32
|
+
@sections[name].instance_eval &definition if definition
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Section
|
37
|
+
def initialize(controller, name)
|
38
|
+
@controller = controller
|
39
|
+
@name = name
|
40
|
+
end
|
41
|
+
|
42
|
+
def action options = {}, &body
|
43
|
+
name = @name
|
44
|
+
@controller.instance_eval do
|
45
|
+
define_method name, &body if body
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def url options = {}, &handler
|
50
|
+
name = "handle_#{@name}_link".to_sym
|
51
|
+
@controller.instance_eval do
|
52
|
+
define_method name, &handler if handler
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/rails/init.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
ActionController::Base.send :include, Wikipodia
|
4
|
+
|
5
|
+
class WikipodiaTest < Test::Unit::TestCase
|
6
|
+
def test_action_controller_contains_wikipodia_method
|
7
|
+
assert_respond_to ActionController::Base, :wikipodia
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_wikipodia_method_creates_a_protected_wiki_link_handler_method
|
11
|
+
ActionController::Base.wikipodia
|
12
|
+
assert ActionController::Base.new.protected_methods.include? "handle_wiki_links"
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_wikipodia_wiki_link_handler_method_follows_defined_sections
|
16
|
+
ActionController::Base.wikipodia do
|
17
|
+
section "test-section" do
|
18
|
+
url do |id, text|
|
19
|
+
"\"#{text}\":#{id}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
assert_equal "\"Some Text\":12345", ActionController::Base.new.send(:handle_wiki_links, "[[test-section:12345 Some Text]]")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_wikipodia_takes_and_executes_block
|
27
|
+
assert_raises RuntimeError do
|
28
|
+
ActionController::Base.wikipodia do
|
29
|
+
raise "I take and execute a block"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_wikipodia_block_has_section_method
|
35
|
+
assert_nothing_raised NoMethodError do
|
36
|
+
ActionController::Base.wikipodia do
|
37
|
+
section :section_name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_wikipodia_section_block_takes_and_executes_block
|
43
|
+
assert_raises RuntimeError do
|
44
|
+
ActionController::Base.wikipodia do
|
45
|
+
section :section_name do
|
46
|
+
raise "I take and execute a block"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_wikipodia_section_block_has_url_method
|
53
|
+
assert_nothing_raised NoMethodError do
|
54
|
+
ActionController::Base.wikipodia do
|
55
|
+
section :section_name do
|
56
|
+
url
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_wikipodia_section_url_method_takes_a_block
|
63
|
+
assert_nothing_raised ArgumentError do
|
64
|
+
ActionController::Base.wikipodia do
|
65
|
+
section :section_name do
|
66
|
+
url do
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_wikipodia_section_url_method_defines_a_protected_handler_method_with_the_block
|
74
|
+
ActionController::Base.wikipodia do
|
75
|
+
section :section_name do
|
76
|
+
url do |id, text|
|
77
|
+
"\"#{text}\":#{id}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
assert_respond_to ActionController::Base.new, :handle_section_name_link
|
83
|
+
assert_equal "\"bar\":foo", ActionController::Base.new.handle_section_name_link("foo", "bar")
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_wikipodia_section_block_has_action_method
|
87
|
+
assert_nothing_raised NoMethodError do
|
88
|
+
ActionController::Base.wikipodia do
|
89
|
+
section :section_name do
|
90
|
+
action
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_wikipodia_section_action_method_takes_a_block
|
97
|
+
assert_nothing_raised ArgumentError do
|
98
|
+
ActionController::Base.wikipodia do
|
99
|
+
section :section_name do
|
100
|
+
action do
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_wikipodia_section_action_method_defines_a_public_action_with_the_block
|
108
|
+
ActionController::Base.wikipodia do
|
109
|
+
section :section_name do
|
110
|
+
action do
|
111
|
+
raise "I'm the public action"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
assert_respond_to ActionController::Base.new, :section_name
|
117
|
+
assert_raises RuntimeError do
|
118
|
+
ActionController::Base.new.section_name
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: WatersOfOblivion-wikipodia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Bryant
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-05 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: ""
|
17
|
+
email: watersofmemory@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- init.rb
|
26
|
+
- install.rb
|
27
|
+
- MIT-LICENSE
|
28
|
+
- Rakefile
|
29
|
+
- README
|
30
|
+
- uninstall.rb
|
31
|
+
- rails/init.rb
|
32
|
+
- test/wikipodia_test.rb
|
33
|
+
- test/test_helper.rb
|
34
|
+
- lib/wikipodia.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://watersofoblivion.github.com/wikipodia/
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --title
|
40
|
+
- Wikipodia
|
41
|
+
- --line-numbers
|
42
|
+
- --inline-source
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.2.0
|
61
|
+
signing_key:
|
62
|
+
specification_version: 2
|
63
|
+
summary: A Rails plugin for easy links in RedCloth
|
64
|
+
test_files:
|
65
|
+
- test/wikipodia_test.rb
|
66
|
+
- test/test_helper.rb
|