Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fb21737
Showing
18 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
Copyright (c) 2010 [name of plugin creator] | |||
|
|||
Permission is hereby granted, free of charge, to any person obtaining | |||
a copy of this software and associated documentation files (the | |||
"Software"), to deal in the Software without restriction, including | |||
without limitation the rights to use, copy, modify, merge, publish, | |||
distribute, sublicense, and/or sell copies of the Software, and to | |||
permit persons to whom the Software is furnished to do so, subject to | |||
the following conditions: | |||
|
|||
The above copyright notice and this permission notice shall be | |||
included in all copies or substantial portions of the Software. | |||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
MagicWiki | |||
========= | |||
|
|||
Introduction goes here. | |||
|
|||
|
|||
Example | |||
======= | |||
|
|||
Example goes here. | |||
|
|||
|
|||
Copyright (c) 2010 [name of plugin creator], released under the MIT license |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
require 'rake' | |||
require 'rake/testtask' | |||
require 'rake/rdoctask' | |||
|
|||
desc 'Default: run unit tests.' | |||
task :default => :test | |||
|
|||
desc 'Test the magic_wiki plugin.' | |||
Rake::TestTask.new(:test) do |t| | |||
t.libs << 'lib' | |||
t.libs << 'test' | |||
t.pattern = 'test/**/*_test.rb' | |||
t.verbose = true | |||
end | |||
|
|||
desc 'Generate documentation for the magic_wiki plugin.' | |||
Rake::RDocTask.new(:rdoc) do |rdoc| | |||
rdoc.rdoc_dir = 'rdoc' | |||
rdoc.title = 'MagicWiki' | |||
rdoc.options << '--line-numbers' << '--inline-source' | |||
rdoc.rdoc_files.include('README') | |||
rdoc.rdoc_files.include('lib/**/*.rb') | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
# Filters added to this controller apply to all controllers in the application. | |||
# Likewise, all the methods added will be available for all controllers. | |||
|
|||
class ApplicationController < ActionController::Base | |||
helper :all # include all helpers, all the time | |||
protect_from_forgery # See ActionController::RequestForgeryProtection for details | |||
|
|||
# Scrub sensitive parameters from your log | |||
# filter_parameter_logging :password | |||
|
|||
|
|||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,44 @@ | |||
class WikiController < ApplicationController | |||
|
|||
private | |||
def wiki_sub(str) | |||
switches = WikiItem::get_switches | |||
switches.keys.each {|k| | |||
if switches[k].class == String | |||
str.gsub! k, switches[k] | |||
elsif switches[k].class == Hash && (scn = str.scan(k).flatten).size > 0 | |||
if switches[k][:inline] | |||
str.gsub! k, render_to_string(:inline => switches[k][:content].gsub('\1', scn[1]), :type => switches[k][:inline]) | |||
end | |||
end | |||
} | |||
return str | |||
end | |||
|
|||
public | |||
def view | |||
render :text => "" and return unless params[:name] && params[:name].size > 0 | |||
@page = WikiItem.find_by_name(params[:name]) || WikiItem.new(:name => params[:name], :content => "") | |||
if params[:commit] && params[:content] | |||
@page.content = params[:content] | |||
@page.save | |||
end | |||
@text = [] | |||
@text << render_to_string(:inline => "= link_to_remote :Edit, :url => {:controller => :wiki, :action => :edit, :id => '#{params[:name]}'}, :update =>:main_wiki_box", :type => :haml) | |||
@text << "<br /><br />" | |||
@text << "Empty page for #{params[:name]}" unless @page.content && @page.content.size > 0 | |||
@page.content.split("\n").each {|l| | |||
@text << wiki_sub(l.gsub("\r", "")) | |||
} | |||
@text = @text.join("\n") | |||
@text.html_safe! | |||
render :partial => "view", :layout => true, :locals => {:page => @page, :text => @text} | |||
end | |||
|
|||
def edit | |||
render :text => "" and return unless params[:name] && params[:name].size > 0 | |||
@page = WikiItem.find_by_name(params[:name]) || WikiItem.new(:name => params[:name], :content => "") | |||
render :partial => "edit", :locals => {:page => @page} | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,31 @@ | |||
class WikiItem < ActiveRecord::Base | |||
|
|||
@@wiki_switches = { | |||
/'''([^']*)'''/ => '<b>\1</b>', | |||
/''([^']*)''/ => '<i>\1</i>', | |||
/^\{$/ => '<ul>', | |||
/^\[$/ => '<ol>', | |||
/^\*(.*)$/ => '<li>\1</li>', | |||
/^\]$/ => '</ol>', | |||
/^\}$/ => '</ul>', | |||
/^h1\. (.*)$/ => '<a name="\1"></a>' + "\n" + '<h1>\1</h1>', | |||
/^h2\. (.*)$/ => '<a name="\1"></a>' + "\n" + '<h2>\1</h2>', | |||
/^h3\. (.*)$/ => '<h3>\1</h3>', | |||
/^h4\. (.*)$/ => '<h4>\1</h4>', | |||
/^h5\. (.*)$/ => '<h5>\1</h5>', | |||
/^h6\. (.*)$/ => '<h6>\1</h6>', | |||
/^centre\. (.*)$/ => '<center>\1</center>', | |||
/^center\. (.*)$/ => '<center>\1</center>', | |||
/^youtube\. (.*)$/ => '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/$1&hl=en_GB&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/\1&hl=en_GB&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>', | |||
/(\[\[([A-Za-z0-9_?: \/\-]+)\]\])/ => {:content => '= link_to "\1", :controller => :wiki, :action => "\1"', :inline => 'haml'}, | |||
/\[([A-Za-z0-9_?: \/\-.&]+[^|])\]/ => '<a href="\1">\1</a>', | |||
/\[([^|]+)\|([A-Za-z0-9_?: \/\-.&]+)\]/ => '<a href="\2">\1</a>', | |||
/-{4}/ => '<hr />', | |||
/^$/ => '<br />' | |||
} | |||
|
|||
def self.get_switches | |||
return @@wiki_switches | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
%html | |||
%head | |||
!= javascript_include_tag :defaults | |||
%body | |||
= yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
- form_tag "/wiki/#{page.name}" do | |||
= text_area_tag :content, page.content, :size => "80x30" | |||
%br | |||
= submit_tag :Update | |||
= link_to_remote :Cancel, :url => {:controller => :wiki, :action => page.name}, :update => :main_wiki_box | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
#main_wiki_box | |||
= text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
ActionController::Routing::Routes.draw do |map| | |||
map.connect 'wiki/edit/:name', :controller => :wiki, :action => :edit | |||
map.connect 'wiki/update/:name', :controller => :wiki, :action => :update | |||
map.connect 'wiki/:name', :controller => :wiki, :action => :view | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
# Include hook code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
# Install hook code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
# MagicWiki |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
class CreateWikiItems < ActiveRecord::Migration | |||
def self.up | |||
create_table :wiki_items do |t| | |||
t.string :name | |||
t.text :content | |||
|
|||
t.timestamps | |||
end | |||
end | |||
|
|||
def self.down | |||
drop_table :wiki_items | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
# desc "Explaining what the task does" | |||
# task :magic_wiki do | |||
# # Task goes here | |||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
require 'test_helper' | |||
|
|||
class MagicWikiTest < ActiveSupport::TestCase | |||
# Replace this with your real tests. | |||
test "the truth" do | |||
assert true | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
require 'rubygems' | |||
require 'active_support' | |||
require 'active_support/test_case' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
# Uninstall hook code here |