textile_toolbar 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/MIT-LICENSE +16 -0
- data/README +56 -0
- data/Rakefile +22 -0
- data/TODO +4 -0
- data/deleted_files +14 -0
- data/files/public/images/textile_toolbar/bold.png +0 -0
- data/files/public/images/textile_toolbar/hyperlink.png +0 -0
- data/files/public/images/textile_toolbar/image.png +0 -0
- data/files/public/images/textile_toolbar/italic.png +0 -0
- data/files/public/javascripts/textile_toolbar.js +39 -0
- data/init.rb +8 -0
- data/install.rb +20 -0
- data/lib/textile_toolbar.rb +34 -0
- data/tasks/asset_copier.rake +11 -0
- data/test/test_helper.rb +7 -0
- data/test/textile_toolbar_test.rb +18 -0
- data/textile_toolbar.gemspec +33 -0
- metadata +73 -0
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Copyright (c) 2007-2008 Matthew Bass (http://matthewbass.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
4
|
+
and associated documentation files (the "Software"), to deal in the Software without
|
5
|
+
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
6
|
+
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
Software is furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or
|
10
|
+
substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
13
|
+
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
14
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
15
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= textile_toolbar
|
2
|
+
|
3
|
+
Adds a handy Textile toolbar to any text area. The toolbar currently offers
|
4
|
+
the following functions:
|
5
|
+
|
6
|
+
- Bold: select some text and click this button to make it bold.
|
7
|
+
- Italic: select some text and click this button to make it italic.
|
8
|
+
- Insert Hyperlink: select some text, click, enter URL, and link is inserted.
|
9
|
+
- Insert Image: click, enter image URL, and image is inserted at cursor.
|
10
|
+
|
11
|
+
A link to a Textile reference page is also shown beside the toolbar.
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
|
15
|
+
Install the gem directly:
|
16
|
+
|
17
|
+
sudo gem install pelargir-textile_toolbar --source=http://gems.github.com
|
18
|
+
|
19
|
+
Or install the gem in your Rails project as a plugin:
|
20
|
+
|
21
|
+
script/plugin install git://github.com/pelargir/textile_toolbar.git
|
22
|
+
|
23
|
+
Or clone the project:
|
24
|
+
|
25
|
+
git clone git://github.com/pelargir/textile_toolbar.git
|
26
|
+
|
27
|
+
Then copy the required image and JS files into your Rails project
|
28
|
+
|
29
|
+
rake textile_toolbar:install
|
30
|
+
|
31
|
+
== Usage
|
32
|
+
|
33
|
+
Use the textile_area helper where you would normally use the text_area
|
34
|
+
helper. Yep, it's that simple!
|
35
|
+
|
36
|
+
<%= text_area :article, :body %> # plain old text area
|
37
|
+
<%= textile_area :article, :body %> # text area with Textile toolbar
|
38
|
+
|
39
|
+
Form blocks are supported, letting you do this also:
|
40
|
+
|
41
|
+
<% form_for :article do |f| -%>
|
42
|
+
<%= f.textile_area :body %>
|
43
|
+
<% end -%>
|
44
|
+
|
45
|
+
Any options that can be passed to text_area can also be passed to textile_area.
|
46
|
+
For example, to set the width and height:
|
47
|
+
|
48
|
+
<%= textile_area :article, :body, :rows => 5, :cols => 10 %>
|
49
|
+
|
50
|
+
== Resources
|
51
|
+
|
52
|
+
Repository: http://github.com/pelargir/textile_toolbar/
|
53
|
+
Blog: http://matthewbass.com
|
54
|
+
Author: Matthew Bass
|
55
|
+
|
56
|
+
Extraction work sponsored by Terralien
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
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 textile_toolbar plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Generate documentation for the textile_toolbar plugin.'
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
18
|
+
rdoc.title = 'textile_toolbar'
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
+
rdoc.rdoc_files.include('README')
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
end
|
data/TODO
ADDED
data/deleted_files
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
#
|
4
|
+
# Files that have been removed from the plugin and should also be removed from
|
5
|
+
# any Rails projects that use the plugin should be listed here, one entry
|
6
|
+
# per line. For example:
|
7
|
+
#
|
8
|
+
# public/javascripts/foo.js
|
9
|
+
# app/views/foo/bar.erb.html
|
10
|
+
#
|
11
|
+
# Adding the paths above to this file would ensure that foo.js and bar.erb.html
|
12
|
+
# both get removed from the target Rails project the next time the plugin's
|
13
|
+
# files are copied over.
|
14
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,39 @@
|
|
1
|
+
function surround_selection(text_area, prefix, suffix) {
|
2
|
+
text_area = $(text_area);
|
3
|
+
if (document.selection) { //IE support
|
4
|
+
text_area.focus();
|
5
|
+
sel = document.selection.createRange();
|
6
|
+
if (sel.text != "")
|
7
|
+
sel.text = prefix + sel.text + suffix;
|
8
|
+
} else if (text_area.selectionStart || text_area.selectionStart == '0') { //Mozilla/Firefox/Netscape 7+ support
|
9
|
+
var startPos = text_area.selectionStart;
|
10
|
+
var endPos = text_area.selectionEnd;
|
11
|
+
selected_text = text_area.value.substring(startPos, endPos);
|
12
|
+
if (selected_text != "")
|
13
|
+
text_area.value = text_area.value.substring(0, startPos) + prefix + selected_text + suffix +
|
14
|
+
text_area.value.substring(endPos, text_area.value.length);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
function insert_at_selection(text_area, value) {
|
19
|
+
text_area = $(text_area);
|
20
|
+
if (document.selection) { //IE support
|
21
|
+
text_area.focus();
|
22
|
+
document.selection.createRange().text = value;
|
23
|
+
} else if (text_area.selectionStart || text_area.selectionStart == '0') { //Mozilla/Firefox/Netscape 7+ support
|
24
|
+
var startPos = text_area.selectionStart;
|
25
|
+
var endPos = text_area.selectionEnd;
|
26
|
+
text_area.value = text_area.value.substring(0, startPos) + value +
|
27
|
+
text_area.value.substring(endPos, text_area.value.length);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
function insert_hyperlink(text_area) {
|
32
|
+
url = prompt("Enter URL for hyperlink:", "http://");
|
33
|
+
surround_selection(text_area, '"', '":' + url);
|
34
|
+
}
|
35
|
+
|
36
|
+
function insert_image(text_area) {
|
37
|
+
url = prompt("Enter URL for image:", "http://");
|
38
|
+
insert_at_selection(text_area, '!' + url + '!');
|
39
|
+
}
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
begin
|
7
|
+
puts "============================================================="
|
8
|
+
puts "Attempting to install required files into your application..."
|
9
|
+
puts "============================================================="
|
10
|
+
RAKE_FILE = File.expand_path(File.join(File.dirname(__FILE__), 'tasks', 'asset_copier.rake'))
|
11
|
+
load RAKE_FILE
|
12
|
+
|
13
|
+
Rake::Task['textile_toolbar:install'].invoke
|
14
|
+
puts "=========================================================="
|
15
|
+
puts "Success!"
|
16
|
+
puts "=========================================================="
|
17
|
+
rescue Exception => ex
|
18
|
+
puts "FAILED TO INSTALL REQUIRED FILES. PLEASE RUN rake textile_toolbar:install."
|
19
|
+
puts "EXCEPTION: #{ex}"
|
20
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module TextileToolbar
|
2
|
+
def textile_area(object_name, method, options={})
|
3
|
+
disable = options.delete(:disable) || {}
|
4
|
+
toolbar = textile_toolbar(options[:id] || "#{object_name}_#{method}", disable)
|
5
|
+
"<div class=\"textile_toolbar\">#{toolbar}</div>" <<
|
6
|
+
"<div class=\"textile_area\">#{text_area(object_name, method, options)}</div>"
|
7
|
+
end
|
8
|
+
|
9
|
+
def textile_toolbar(id, disable)
|
10
|
+
html = javascript_include_tag("textile_toolbar")
|
11
|
+
html << link_to_function(image_tag("textile_toolbar/bold.png", :size => "23x22", :alt => "Make selection bold"), "surround_selection('#{id}', '*', '*')")
|
12
|
+
html << " "
|
13
|
+
html << link_to_function(image_tag("textile_toolbar/italic.png", :size => "23x22", :alt => "Make selection italic"), "surround_selection('#{id}', '_', '_')")
|
14
|
+
html << " "
|
15
|
+
html << link_to_function(image_tag("textile_toolbar/underline.png", :size => "23x22", :alt => "Make selection underlined"), "surround_selection('#{id}', '+', '+')")
|
16
|
+
html << " "
|
17
|
+
html << link_to_function(image_tag("textile_toolbar/hyperlink.png", :size => "23x22", :alt => "Make hyperlink"), "insert_hyperlink('#{id}')")
|
18
|
+
html << " "
|
19
|
+
unless disable == :image
|
20
|
+
html << link_to_function(image_tag("textile_toolbar/image.png", :size => "23x22", :alt => "Insert image"), "insert_image('#{id}')")
|
21
|
+
html << " "
|
22
|
+
end
|
23
|
+
html << "<small>" << link_to("Textile", "http://hobix.com/textile/", :target => "_blank") << " enabled</small>"
|
24
|
+
end
|
25
|
+
|
26
|
+
module FormBuilder
|
27
|
+
def textile_area(method, options={})
|
28
|
+
@template.textile_area(@object_name, method, options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
ActionView::Base.send :include, TextileToolbar
|
34
|
+
ActionView::Helpers::FormBuilder.send :include, TextileToolbar::FormBuilder
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Generated by the asset_copier plugin
|
2
|
+
# http://github.com/pelargir/asset_copier
|
3
|
+
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/textile_toolbar/asset_copier')
|
5
|
+
|
6
|
+
namespace :textile_toolbar do
|
7
|
+
desc "Install files required by textile_toolbar"
|
8
|
+
task :install do
|
9
|
+
TextileToolbar::AssetCopier.copy "textile_toolbar"
|
10
|
+
end
|
11
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class TextileToolbarTest < Test::Unit::TestCase
|
4
|
+
include TextileToolbar
|
5
|
+
include ActionView::Helpers::TagHelper
|
6
|
+
include ActionView::Helpers::AssetTagHelper
|
7
|
+
include ActionView::Helpers::JavaScriptHelper
|
8
|
+
include ActionView::Helpers::UrlHelper
|
9
|
+
include ActionView::Helpers::FormHelper
|
10
|
+
|
11
|
+
context "textile_area" do
|
12
|
+
should "render text area" do
|
13
|
+
assert textile_area(:article, :body).include?("<textarea")
|
14
|
+
assert textile_area(:article, :body).include?("</textarea>")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "textile_toolbar"
|
3
|
+
s.version = "0.5"
|
4
|
+
s.date = "2008-08-21"
|
5
|
+
s.summary = "Adds a handy Textile toolbar to any text area."
|
6
|
+
s.email = "pelargir@gmail.com"
|
7
|
+
s.homepage = "http://github.com/pelargir/textile_toolbar"
|
8
|
+
s.description = "Adds a handy Textile toolbar to any text area."
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.authors = ["Matthew Bass"]
|
11
|
+
s.files = [
|
12
|
+
"CHANGELOG",
|
13
|
+
"deleted_files",
|
14
|
+
"files/public/images/textile_toolbar/bold.png",
|
15
|
+
"files/public/images/textile_toolbar/hyperlink.png",
|
16
|
+
"files/public/images/textile_toolbar/image.png",
|
17
|
+
"files/public/images/textile_toolbar/italic.png",
|
18
|
+
"files/public/javascripts/textile_toolbar.js",
|
19
|
+
"init.rb",
|
20
|
+
"install.rb",
|
21
|
+
"lib/textile_toolbar.rb",
|
22
|
+
"MIT-LICENSE",
|
23
|
+
"Rakefile",
|
24
|
+
"README",
|
25
|
+
"tasks/asset_copier.rake",
|
26
|
+
"test/test_helper.rb",
|
27
|
+
"test/textile_toolbar_test.rb",
|
28
|
+
"textile_toolbar.gemspec",
|
29
|
+
"TODO"
|
30
|
+
]
|
31
|
+
s.rdoc_options = ["--main", "README"]
|
32
|
+
s.extra_rdoc_files = ["README"]
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: textile_toolbar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.5"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Bass
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-21 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Adds a handy Textile toolbar to any text area.
|
17
|
+
email: pelargir@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- CHANGELOG
|
26
|
+
- deleted_files
|
27
|
+
- files/public/images/textile_toolbar/bold.png
|
28
|
+
- files/public/images/textile_toolbar/hyperlink.png
|
29
|
+
- files/public/images/textile_toolbar/image.png
|
30
|
+
- files/public/images/textile_toolbar/italic.png
|
31
|
+
- files/public/javascripts/textile_toolbar.js
|
32
|
+
- init.rb
|
33
|
+
- install.rb
|
34
|
+
- lib/textile_toolbar.rb
|
35
|
+
- MIT-LICENSE
|
36
|
+
- Rakefile
|
37
|
+
- README
|
38
|
+
- tasks/asset_copier.rake
|
39
|
+
- test/test_helper.rb
|
40
|
+
- test/textile_toolbar_test.rb
|
41
|
+
- textile_toolbar.gemspec
|
42
|
+
- TODO
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/pelargir/textile_toolbar
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --main
|
50
|
+
- README
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.4
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Adds a handy Textile toolbar to any text area.
|
72
|
+
test_files: []
|
73
|
+
|