pelargir-textile_toolbar 0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +4 -0
- data/MIT-LICENSE +16 -0
- data/README +61 -0
- data/Rakefile +22 -0
- data/TODO +2 -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 +1 -0
- data/install.rb +17 -0
- data/lib/textile_toolbar.rb +23 -0
- data/tasks/textile_toolbar.rake +39 -0
- data/test/test_helper.rb +0 -0
- data/test/textile_toolbar_test.rb +0 -0
- data/textile_toolbar.gemspec +32 -0
- metadata +70 -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,61 @@
|
|
|
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
|
+
|
|
14
|
+
== Installation
|
|
15
|
+
|
|
16
|
+
Install the gem directly:
|
|
17
|
+
|
|
18
|
+
gem sources -a http://gems.github.com (you only have to do this once)
|
|
19
|
+
sudo gem install pelargir-textile_toolbar
|
|
20
|
+
|
|
21
|
+
Or install the gem in your Rails project as a plugin:
|
|
22
|
+
|
|
23
|
+
script/plugin install git://github.com/pelargir/textile_toolbar.git
|
|
24
|
+
|
|
25
|
+
Or clone the project:
|
|
26
|
+
|
|
27
|
+
git clone git://github.com/pelargir/textile_toolbar.git
|
|
28
|
+
|
|
29
|
+
Then copy the required image and JS files into your Rails project
|
|
30
|
+
|
|
31
|
+
rake textile_toolbar:install_files
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
== Usage
|
|
35
|
+
|
|
36
|
+
Use the textile_area helper where you would normally use the text_area
|
|
37
|
+
helper. Yep, it's that simple!
|
|
38
|
+
|
|
39
|
+
<%= text_area :article, :body %> # plain old text area
|
|
40
|
+
<%= textile_area :article, :body %> # text area with Textile toolbar
|
|
41
|
+
|
|
42
|
+
Form blocks are not yet supported, so you can't do this:
|
|
43
|
+
|
|
44
|
+
<% form_for :article do |f| -%>
|
|
45
|
+
<%= f.textile_area :body %>
|
|
46
|
+
<% end -%>
|
|
47
|
+
|
|
48
|
+
Instead, you'll need to do this:
|
|
49
|
+
|
|
50
|
+
<% form_for :article do |f| -%>
|
|
51
|
+
<%= textile_area :article, :body %>
|
|
52
|
+
<% end -%>
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
== Resources
|
|
56
|
+
|
|
57
|
+
Repository: http://github.com/pelargir/textile_toolbar/
|
|
58
|
+
Blog: http://matthewbass.com
|
|
59
|
+
Author: Matthew Bass
|
|
60
|
+
|
|
61
|
+
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
|
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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'textile_toolbar'
|
data/install.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
puts "=========================================================="
|
|
5
|
+
puts "Attempting to copy required files into your application..."
|
|
6
|
+
puts "=========================================================="
|
|
7
|
+
RAKE_FILE = File.join(File.dirname(__FILE__), '/tasks/textile_toolbar.rake')
|
|
8
|
+
load RAKE_FILE
|
|
9
|
+
|
|
10
|
+
Rake::Task['textile_toolbar:install_files'].invoke
|
|
11
|
+
puts "=========================================================="
|
|
12
|
+
puts "Success!"
|
|
13
|
+
puts "=========================================================="
|
|
14
|
+
rescue Exception => ex
|
|
15
|
+
puts "FAILED TO COPY FILES DURING INSTALL. PLEASE RUN rake textile_toolbar:install_files."
|
|
16
|
+
puts "EXCEPTION: #{ex}"
|
|
17
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
toolbar + text_area(object_name, method, options)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def textile_toolbar(id, disable)
|
|
9
|
+
html = link_to_function(image_tag("textile_toolbar/bold.png", :size => "23x22", :alt => "Make selection bold"), "surround_selection('#{id}', '*', '*')")
|
|
10
|
+
html << " "
|
|
11
|
+
html << link_to_function(image_tag("textile_toolbar/italic.png", :size => "23x22", :alt => "Make selection italic"), "surround_selection('#{id}', '_', '_')")
|
|
12
|
+
html << " "
|
|
13
|
+
html << link_to_function(image_tag("textile_toolbar/hyperlink.png", :size => "23x22", :alt => "Make hyperlink"), "insert_hyperlink('#{id}')")
|
|
14
|
+
html << " "
|
|
15
|
+
unless disable == :image
|
|
16
|
+
html << link_to_function(image_tag("textile_toolbar/image.png", :size => "23x22", :alt => "Insert image"), "insert_image('#{id}')")
|
|
17
|
+
html << " "
|
|
18
|
+
end
|
|
19
|
+
html << "<small>" << link_to("Textile", "http://hobix.com/textile/", :target => "_blank") << " enabled</small>"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
ActionView::Base.send :include, TextileToolbar
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'find'
|
|
2
|
+
|
|
3
|
+
module TextileToolbar
|
|
4
|
+
class Assets
|
|
5
|
+
@source = File.expand_path(File.join(File.dirname(__FILE__), '..', 'files'))
|
|
6
|
+
@destination = RAILS_ROOT
|
|
7
|
+
class << self
|
|
8
|
+
attr_accessor :source, :destination
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.install
|
|
12
|
+
paths = []
|
|
13
|
+
Find.find(source) do |path|
|
|
14
|
+
Find.prune if path =~ /\/\..+/
|
|
15
|
+
Find.prune if path =~ /CVS/
|
|
16
|
+
paths << path
|
|
17
|
+
end
|
|
18
|
+
paths.each do |path|
|
|
19
|
+
dest_path = path.gsub(source, destination)
|
|
20
|
+
if File.directory?(path)
|
|
21
|
+
FileUtils.mkdir_p(dest_path) unless File.exists?(dest_path)
|
|
22
|
+
else
|
|
23
|
+
FileUtils.cp(path, dest_path)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
rescue Exception => e
|
|
27
|
+
puts "Error trying to copy files: #{e.inspect}"
|
|
28
|
+
raise e
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
namespace :textile_toolbar do
|
|
35
|
+
desc "Install files required by textile_toolbar"
|
|
36
|
+
task :install_files do
|
|
37
|
+
TextileToolbar::Assets.install
|
|
38
|
+
end
|
|
39
|
+
end
|
data/test/test_helper.rb
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
"files/public/images/textile_toolbar/bold.png",
|
|
14
|
+
"files/public/images/textile_toolbar/hyperlink.png",
|
|
15
|
+
"files/public/images/textile_toolbar/image.png",
|
|
16
|
+
"files/public/images/textile_toolbar/italic.png",
|
|
17
|
+
"files/public/javascripts/textile_toolbar.js",
|
|
18
|
+
"init.rb",
|
|
19
|
+
"install.rb",
|
|
20
|
+
"lib/textile_toolbar.rb",
|
|
21
|
+
"MIT-LICENSE",
|
|
22
|
+
"Rakefile",
|
|
23
|
+
"README",
|
|
24
|
+
"tasks/textile_toolbar.rake",
|
|
25
|
+
"test/test_helper.rb",
|
|
26
|
+
"test/textile_toolbar_test.rb",
|
|
27
|
+
"textile_toolbar.gemspec",
|
|
28
|
+
"TODO"
|
|
29
|
+
]
|
|
30
|
+
s.rdoc_options = ["--main", "README"]
|
|
31
|
+
s.extra_rdoc_files = ["README"]
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pelargir-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 -07: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
|
+
- files/public/images/textile_toolbar/bold.png
|
|
27
|
+
- files/public/images/textile_toolbar/hyperlink.png
|
|
28
|
+
- files/public/images/textile_toolbar/image.png
|
|
29
|
+
- files/public/images/textile_toolbar/italic.png
|
|
30
|
+
- files/public/javascripts/textile_toolbar.js
|
|
31
|
+
- init.rb
|
|
32
|
+
- install.rb
|
|
33
|
+
- lib/textile_toolbar.rb
|
|
34
|
+
- MIT-LICENSE
|
|
35
|
+
- Rakefile
|
|
36
|
+
- README
|
|
37
|
+
- tasks/textile_toolbar.rake
|
|
38
|
+
- test/test_helper.rb
|
|
39
|
+
- test/textile_toolbar_test.rb
|
|
40
|
+
- textile_toolbar.gemspec
|
|
41
|
+
- TODO
|
|
42
|
+
has_rdoc: true
|
|
43
|
+
homepage: http://github.com/pelargir/textile_toolbar
|
|
44
|
+
post_install_message:
|
|
45
|
+
rdoc_options:
|
|
46
|
+
- --main
|
|
47
|
+
- README
|
|
48
|
+
require_paths:
|
|
49
|
+
- lib
|
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: "0"
|
|
55
|
+
version:
|
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: "0"
|
|
61
|
+
version:
|
|
62
|
+
requirements: []
|
|
63
|
+
|
|
64
|
+
rubyforge_project:
|
|
65
|
+
rubygems_version: 1.2.0
|
|
66
|
+
signing_key:
|
|
67
|
+
specification_version: 2
|
|
68
|
+
summary: Adds a handy Textile toolbar to any text area.
|
|
69
|
+
test_files: []
|
|
70
|
+
|