Skip to content

Commit

Permalink
v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterLawrence committed Oct 7, 2010
0 parents commit 851f81a
Show file tree
Hide file tree
Showing 287 changed files with 45,095 additions and 0 deletions.
58 changes: 58 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Redmine Wysiwyg Textile Editor is copyrighted free software by -----
You can redistribute it and/or modify it under either the terms of the GPL
(see COPYING.txt file), or the conditions below:

1. You may make and give away verbatim copies of the source form of the
software without restriction, provided that you duplicate all of the
original copyright notices and associated disclaimers.

2. You may modify your copy of the software in any way, provided that
you do at least ONE of the following:

a) place your modifications in the Public Domain or otherwise
make them Freely Available, such as by posting said
modifications to Usenet or an equivalent medium, or by allowing
the author to include your modifications in the software.

b) use the modified software only within your corporation or
organization.

c) rename any non-standard executables so the names do not conflict
with standard executables, which must also be provided.

d) make other distribution arrangements with the author.

3. You may distribute the software in object code or executable
form, provided that you do at least ONE of the following:

a) distribute the executables and library files of the software,
together with instructions (in the manual page or equivalent)
on where to get the original distribution.

b) accompany the distribution with the machine-readable source of
the software.

c) give non-standard executables non-standard names, with
instructions on where to get the original software distribution.

d) make other distribution arrangements with the author.

4. You may modify and include the part of the software into any other
software (possibly commercial). But some files in the distribution
are not written by the author, so that they are not under this terms.

They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
files under the ./missing directory. See each file for the copying
condition.

5. The scripts and library files supplied as input to or produced as
output from the software do not automatically fall under the
copyright of the software, but belong to whomever generated them,
and may be sold commercially, and may be aggregated with this
software.

6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.

23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Redmine Wysiwyg Textile Editor
=================

A TinyMCE test application for Textile wiki pages.

Currently this is a test version for in-house use only since there is a few issues that need to be sorted out regarding the conversion to and from textile and other security issues. If you stick to simple textile formatting it's not a problem, but when it comes to images and macros that's another issue.

A better option would be to write a javascript wysiwyg editor for redmine like the one used in Trac.

Installation
------------

1. Copy the plugin directory into the vendor/plugins directory (make sure the name is redmine_wysiwyg_textile)
2. Start Redmine
3. Change text formatting (Administration > Settings > General > Text formatting) to "textile wysiwyg"

Usage
-----

When editing a wiki page a radio button will be displayed below the Save button. This radio button allows the user to switch between the standard redmine textile editor and the tinymce wysiwyg editor.



76 changes: 76 additions & 0 deletions app/controllers/convert_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require 'html2textile'
require 'sgml-parser'
require 'redcloth3'

# P.J.Lawrence October 2010

class HTMLFormatter< RedCloth3
include ActionView::Helpers::TagHelper

RULES = [:textile, :block_markdown_rule]

def initialize(*args)
super
self.hard_breaks=true
self.no_span_caps=true
self.filter_styles=true
end

def to_html(*rules)
super(*RULES).to_s
end

private

# Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet.
# <a href="http://code.whytheluckystiff.net/redcloth/changeset/128">http://code.whytheluckystiff.net/redcloth/changeset/128</a>
def hard_break( text )
text.gsub!( /(.)\n(?!\n|\Z|>| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks
end

AUTO_LINK_RE = %r{
( # leading text
<\w+.*?>| # leading HTML tag, or
[^=<>!:'"/]| # leading punctuation, or
^ # beginning of line
)
(
(?:https?://)| # protocol spec, or
(?:s?ftps?://)|
(?:www\.) # www.*
)
(
(\S+?) # url
(\/)? # slash
)
([^\w\=\/;\(\)]*?) # post
(?=<|\s|$)
}x unless const_defined?(:AUTO_LINK_RE)

end

class ConvertController < ApplicationController
unloadable

def wysiwygtohtmltotextile
@text = params[:content][:text]
# name="content[text]" --- wiki page
# name="issue[description]" -- issue
# name="notes" -- note
# name="settings[mail_handler_body_delimiters]" - settings
# name="project[description]"
# name="message[content]" -- forum
htmlparser = HTMLToTextileParser.new
htmlparser.feed(@text)
@text=htmlparser.to_textile
render :partial => 'convert'
end

def wysiwygtotextiletohtml
@text=params[:content][:text]
#@text=RedCloth3.new(params[:content][:text]).to_html
#@text = @text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
@text=HTMLFormatter.new(@text).to_html
render :partial => 'convert'
end
end
2 changes: 2 additions & 0 deletions app/helpers/convert_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ConvertHelper
end
119 changes: 119 additions & 0 deletions app/helpers/redmine_wysiwyg_textile/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@

require "i18n.rb"

module RedmineWysiwygTextile
module Helper
unloadable

def wikitoolbar_for(field_id)
if (field_id=='content_text')
# only for wiki pages for now
wikitoolbar_for_wysiwyg(field_id)
else
wikitoolbar_for_non_wysiwyg(field_id)
end
end

def wikitoolbar_for_non_wysiwyg(field_id)
# Is there a simple way to link to a public resource?
url = "#{Redmine::Utils.relative_url_root}/help/wiki_syntax.html"

help_link = l(:setting_text_formatting) + ': ' +
link_to(l(:label_help), url,
:onclick => "window.open(\"#{ url }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;")

javascript_include_tag('jstoolbar/jstoolbar') +
javascript_include_tag('jstoolbar/textile') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
javascript_tag("var wikiToolbar = new jsToolBar($('#{field_id}')); wikiToolbar.setHelpLink('#{help_link}'); wikiToolbar.draw();")
end

def wikitoolbar_for_wysiwyg(field_id)
file = "#{Redmine::Utils.relative_url_root}/help/wiki_syntax.html"
help_link = l(:setting_text_formatting) + ': ' +
link_to(l(:label_help), file,
:onclick => "window.open(\"#{file}\", \"\", \"resizable=yes, location=no, width=800, height=640, menubar=no, status=no, scrollbars=yes\"); return false;")
# tinymce and jstoolbar
javascript_include_tag('jstoolbar/jstoolbar') +
javascript_include_tag('jstoolbar/textile') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
javascript_include_tag('/tinymce/jscripts/tiny_mce/tiny_mce.js', :plugin => 'redmine_wysiwyg_textile') +
javascript_tag("
var tinyenabled=false;
function setuptinymce() {
tinyMCE.init({
mode : 'specific_textareas',
editor_selector : 'wiki-edit',
formats : {strikethrough : {inline : 'del'},
underline : {inline : 'ins'} },
theme : 'advanced',
plugins : 'table',
theme_advanced_buttons1: 'bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect',
theme_advanced_buttons3_add : 'tablecontrols',
table_styles : 'Header 1=header1;Header 2=header2;Header 3=header3',
table_cell_styles : 'Header 1=header1;Header 2=header2;Header 3=header3;Table Cell=tableCel1',
table_row_styles : 'Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1',
table_cell_limit : 100,
table_row_limit : 5,
table_col_limit : 5,
theme_advanced_toolbar_location : 'top',
theme_advanced_toolbar_align : 'left',
theme_advanced_resizing : true
});
}
function toggleEditor(id,DisplayTiny) {
if (DisplayTiny==1 && tinyenabled==false) {
new Ajax.Request('/convert/wysiwygtotextiletohtml', {asynchronous:false, evalScripts:false, method:'post', onSuccess:function(request){UpdateFile(request)}, parameters:$('#{field_id}').serialize()});
setuptinymce();
tinyenabled=true;
the_jstoolbar.toolbar.style.display = 'none';
return;
}
if (!tinyMCE.get(id)) {
if (DisplayTiny==1) {
new Ajax.Request('/convert/wysiwygtotextiletohtml', {asynchronous:false, evalScripts:false, method:'post', onSuccess:function(request){UpdateFile(request)}, parameters:$('#{field_id}').serialize()});
the_jstoolbar.toolbar.style.display = 'none';
tinyMCE.execCommand('mceAddControl', false, id);
}
}
else {
if (DisplayTiny==0) {
tinyMCE.execCommand('mceRemoveControl', false, id);
new Ajax.Request('/convert/wysiwygtohtmltotextile', {asynchronous:false, evalScripts:false, method:'post', onSuccess:function(request){UpdateFile(request)}, parameters:$('#{field_id}').serialize()});
the_jstoolbar.toolbar.style.display = 'block';
}
}
}
function UpdateFile(TheText) {
var text1 = document.getElementById('#{field_id}');
text1.value = TheText.responseText;
if (tinyenabled==true) {
tinyMCE.get('#{field_id}').setContent(TheText.responseText);
}
return true;
}
function UpdatePreviewText(TheText) {
var text2 = document.getElementById('#{:preview}');
text2.innerHTML = TheText.responseText;
}
") +
"<form>
<Input type = radio Name = \"textilewysiwyg\" CHECKED onClick=\"javascript:toggleEditor('#{field_id}',0)\">textile
<Input type = radio Name = \"textilewysiwyg\" onClick=\"javascript:toggleEditor('#{field_id}',1)\">wysiwyg
</form>
<div id='workarea' class='wiki'></div>" +
javascript_tag("var the_jstoolbar = new jsToolBar($('#{field_id}')); the_jstoolbar.setHelpLink('#{help_link}'); the_jstoolbar.draw();")
end

def initial_page_content(page)
"h1. #{ERB::Util.html_escape page.pretty_title}"
end

def heads_for_wiki_formatter
#stylesheet_link_tag('/tiny_mce/themes/advanced/skins/default/wysiwygtextile/content.css', :plugin => 'redmine_wysiwyg_textile' ) +
#stylesheet_link_tag('/tiny_mce/themes/advanced/skins/default/wysiwygtextile/ui.css', :plugin => 'redmine_wysiwyg_textile' ) +
#stylesheet_link_tag('/tiny_mce/themes/advanced/skins/default/wysiwygtextile/dialog.css', :plugin => 'redmine_wysiwyg_textile' ) +
stylesheet_link_tag('jstoolbar')
end
end
end
2 changes: 2 additions & 0 deletions app/views/convert/_convert.rhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= @text %>

Loading

0 comments on commit 851f81a

Please sign in to comment.