textile_editor_helper 0.0.12
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/.gitignore +20 -0
- data/Gemfile +5 -0
- data/README.md +130 -0
- data/Rakefile +7 -0
- data/features/copy_assets.feature +17 -0
- data/features/step_definitions/common_steps.rb +66 -0
- data/features/step_definitions/rails_setup_steps.rb +9 -0
- data/features/support/env.rb +0 -0
- data/features/support/setup.rb +0 -0
- data/lib/generators/textile_editor_helper/install_generator.rb +54 -0
- data/lib/textile_editor_helper.rb +204 -0
- data/lib/textile_editor_helper/version.rb +3 -0
- data/test/abstract_unit.rb +16 -0
- data/test/textile_editor_helper_test.rb +195 -0
- data/textile_editor_helper.gemspec +27 -0
- data/travis.yml +5 -0
- data/vendor/README +95 -0
- data/vendor/app/controllers/textile_preview_controller.rb +14 -0
- data/vendor/app/helpers/textile_preview_helper.rb +14 -0
- data/vendor/app/views/textile_preview/show.js.coffee +2 -0
- data/vendor/assets/images/textile-editor/background.png +0 -0
- data/vendor/assets/images/textile-editor/blockquote.png +0 -0
- data/vendor/assets/images/textile-editor/bold.png +0 -0
- data/vendor/assets/images/textile-editor/center.png +0 -0
- data/vendor/assets/images/textile-editor/h1.png +0 -0
- data/vendor/assets/images/textile-editor/h2.png +0 -0
- data/vendor/assets/images/textile-editor/h3.png +0 -0
- data/vendor/assets/images/textile-editor/h4.png +0 -0
- data/vendor/assets/images/textile-editor/h5.png +0 -0
- data/vendor/assets/images/textile-editor/h6.png +0 -0
- data/vendor/assets/images/textile-editor/indent.png +0 -0
- data/vendor/assets/images/textile-editor/italic.png +0 -0
- data/vendor/assets/images/textile-editor/justify.png +0 -0
- data/vendor/assets/images/textile-editor/left.png +0 -0
- data/vendor/assets/images/textile-editor/list_bullets.png +0 -0
- data/vendor/assets/images/textile-editor/list_numbers.png +0 -0
- data/vendor/assets/images/textile-editor/omega.png +0 -0
- data/vendor/assets/images/textile-editor/outdent.png +0 -0
- data/vendor/assets/images/textile-editor/paragraph.png +0 -0
- data/vendor/assets/images/textile-editor/right.png +0 -0
- data/vendor/assets/images/textile-editor/strikethrough.png +0 -0
- data/vendor/assets/images/textile-editor/underline.png +0 -0
- data/vendor/assets/javascripts/textile-editor-config.js +22 -0
- data/vendor/assets/javascripts/textile-editor.js +687 -0
- data/vendor/assets/stylesheets/textile-editor.css +53 -0
- metadata +186 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'rubygems'
|
6
|
+
|
7
|
+
require 'action_controller'
|
8
|
+
require 'action_controller/cgi_ext'
|
9
|
+
require 'action_controller/test_process'
|
10
|
+
|
11
|
+
# Show backtraces for deprecated behavior for quicker cleanup.
|
12
|
+
ActiveSupport::Deprecation.debug = true
|
13
|
+
|
14
|
+
ActionController::Base.logger = nil
|
15
|
+
# ActionController::Base.ignore_missing_templates = false
|
16
|
+
ActionController::Routing::Routes.reload rescue nil
|
@@ -0,0 +1,195 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/abstract_unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/textile_editor_helper'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
class TextileEditorHelperTest < Test::Unit::TestCase
|
6
|
+
include ActionView::Helpers::TextHelper
|
7
|
+
include ActionView::Helpers::AssetTagHelper
|
8
|
+
include ActionView::Helpers::TagHelper
|
9
|
+
include ActionView::Helpers::FormHelper
|
10
|
+
include ActionView::Helpers::JavaScriptHelper
|
11
|
+
# include TextileEditorHelper
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@controller = Class.new do
|
15
|
+
attr_reader :url_for_options
|
16
|
+
def url_for(options, *parameters_for_method_reference)
|
17
|
+
@url_for_options = options
|
18
|
+
"http://www.example.com"
|
19
|
+
end
|
20
|
+
|
21
|
+
def request; @request ||= ActionController::TestRequest.new; end
|
22
|
+
def response; @response ||= ActionController::TestResponse.new; end
|
23
|
+
end
|
24
|
+
@controller = @controller.new
|
25
|
+
@article = OpenStruct.new(:body => nil)
|
26
|
+
end
|
27
|
+
|
28
|
+
# support methods
|
29
|
+
def request
|
30
|
+
@controller.request
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_simple_editor(object, field, options={})
|
34
|
+
output = textile_editor(object, field, options.merge(:simple => true))
|
35
|
+
assert_equal text_area(object, field, options), output
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_extended_editor(object, field, options={})
|
39
|
+
output = textile_editor(object, field, options)
|
40
|
+
assert_equal text_area(object, field, options), output
|
41
|
+
end
|
42
|
+
|
43
|
+
def framework_initialize_output(framework)
|
44
|
+
case framework
|
45
|
+
when :prototype
|
46
|
+
%{document.observe('dom:loaded', function() \{}
|
47
|
+
when :jquery
|
48
|
+
%{$(document).ready(function() \{}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def pre_initialize_output(framework)
|
53
|
+
%{<link href="/stylesheets/textile-editor.css" media="screen" rel="stylesheet" type="text/css" />
|
54
|
+
<script src="/javascripts/textile-editor.js" type="text/javascript"></script>
|
55
|
+
<script type="text/javascript">
|
56
|
+
/* <![CDATA[ */
|
57
|
+
} +
|
58
|
+
framework_initialize_output(framework)
|
59
|
+
end
|
60
|
+
|
61
|
+
def post_initialize_output
|
62
|
+
%{\});
|
63
|
+
/* ]]> */
|
64
|
+
</script>
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def expected_initialize_output(framework, editors, button_data=nil)
|
69
|
+
expected = [pre_initialize_output(framework)]
|
70
|
+
expected << button_data unless button_data.nil?
|
71
|
+
expected << editors.map do |editor|
|
72
|
+
"TextileEditor.initialize('%s', '%s');" % editor
|
73
|
+
end
|
74
|
+
expected << post_initialize_output
|
75
|
+
expected.join("\n").split("\n").map { |e| e.lstrip }.join("\n").chomp
|
76
|
+
end
|
77
|
+
|
78
|
+
# tests
|
79
|
+
def test_textile_editor
|
80
|
+
assert_nil @textile_editor_ids
|
81
|
+
create_extended_editor('article', 'body')
|
82
|
+
assert_equal [['article_body', 'extended']], @textile_editor_ids
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_textile_editor_simple_mode
|
86
|
+
assert_nil @textile_editor_ids
|
87
|
+
create_simple_editor('article', 'body')
|
88
|
+
assert_equal [['article_body', 'simple']], @textile_editor_ids
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_textile_editor_with_custom_id
|
92
|
+
assert_nil @textile_editor_ids
|
93
|
+
create_extended_editor('article', 'body', :id => 'my_custom_id')
|
94
|
+
assert_equal [['my_custom_id', 'extended']], @textile_editor_ids
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_textile_editor_simple_mode_with_custom_id
|
98
|
+
assert_nil @textile_editor_ids
|
99
|
+
create_simple_editor('article', 'body', :id => 'my_custom_id')
|
100
|
+
assert_equal [['my_custom_id', 'simple']], @textile_editor_ids
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_textile_editor_initialize
|
104
|
+
create_extended_editor('article', 'body')
|
105
|
+
output = textile_editor_initialize()
|
106
|
+
assert_equal expected_initialize_output(:prototype, [
|
107
|
+
['article_body', 'extended']
|
108
|
+
]), output
|
109
|
+
|
110
|
+
create_simple_editor('article', 'body_excerpt')
|
111
|
+
output = textile_editor_initialize()
|
112
|
+
assert_equal expected_initialize_output(:prototype, [
|
113
|
+
['article_body', 'extended'],
|
114
|
+
['article_body_excerpt', 'simple']
|
115
|
+
]), output
|
116
|
+
|
117
|
+
output = textile_editor_initialize(:framework => :jquery)
|
118
|
+
assert_equal expected_initialize_output(:jquery, [
|
119
|
+
['article_body', 'extended'],
|
120
|
+
['article_body_excerpt', 'simple']
|
121
|
+
]), output
|
122
|
+
|
123
|
+
# test using custom default options
|
124
|
+
textile_editor_options :framework => :jquery
|
125
|
+
output = textile_editor_initialize()
|
126
|
+
assert_equal expected_initialize_output(:jquery, [
|
127
|
+
['article_body', 'extended'],
|
128
|
+
['article_body_excerpt', 'simple']
|
129
|
+
]), output
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_textile_editor_inititalize_with_arbitrary_ids
|
133
|
+
output = textile_editor_initialize(:story_comment, :story_body)
|
134
|
+
assert_equal expected_initialize_output(:prototype, [
|
135
|
+
['story_comment', 'extended'],
|
136
|
+
['story_body', 'extended']
|
137
|
+
]), output
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_textile_editor_initialize_with_custom_buttons
|
141
|
+
b = '<button id="test_button" onclick="alert(\'Hello!\')" title="Hello world">Hello</button>'
|
142
|
+
button_data = ["TextileEditor.buttons.push(\"%s\");" % escape_javascript(b)]
|
143
|
+
actual = textile_editor_button('Hello',
|
144
|
+
:id => 'test_button',
|
145
|
+
:onclick => "alert('Hello!')",
|
146
|
+
:title => 'Hello world'
|
147
|
+
)
|
148
|
+
|
149
|
+
assert_equal button_data, actual
|
150
|
+
|
151
|
+
create_extended_editor('article', 'body')
|
152
|
+
output = textile_editor_initialize()
|
153
|
+
assert_equal expected_initialize_output(:prototype, [
|
154
|
+
['article_body', 'extended']
|
155
|
+
], button_data), output
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_textile_extract_dom_ids_works_with_arrayed_hash
|
159
|
+
hash_with_array = { :recipe => [ :instructions, :introduction ] }
|
160
|
+
assert_equal [ 'recipe_instructions', 'recipe_introduction' ], textile_extract_dom_ids(hash_with_array)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_textile_extract_dom_ids_works_with_hash
|
164
|
+
hash_with_symbol = { :story => :title }
|
165
|
+
assert_equal [ 'story_title' ], textile_extract_dom_ids(hash_with_symbol)
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_textile_extract_dom_ids_works_with_ids
|
169
|
+
straight_id = 'article_page'
|
170
|
+
assert_equal [ 'article_page' ], textile_extract_dom_ids(straight_id)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_textile_extract_dom_ids_works_with_mixed_params
|
174
|
+
paramd = %w(article_page)
|
175
|
+
paramd += [{
|
176
|
+
:recipe => [ :instructions, :introduction ],
|
177
|
+
:story => :title
|
178
|
+
}]
|
179
|
+
assert_equal %w(article_page recipe_instructions recipe_introduction story_title).sort,
|
180
|
+
textile_extract_dom_ids(*paramd).sort { |a,b| a.to_s <=> b.to_s }
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_textile_editor_button
|
184
|
+
b = '<button id="test_button" onclick="alert(\'Hello!\')" title="Hello world">Hello</button>'
|
185
|
+
expected = ['TextileEditor.buttons.push("%s");' % escape_javascript(b)]
|
186
|
+
|
187
|
+
actual = textile_editor_button('Hello',
|
188
|
+
:id => 'test_button',
|
189
|
+
:onclick => "alert('Hello!')",
|
190
|
+
:title => 'Hello world'
|
191
|
+
)
|
192
|
+
|
193
|
+
assert_equal expected, actual
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/textile_editor_helper/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Katherine"]
|
6
|
+
gem.email = ["info@bridgeutopiaweb.com"]
|
7
|
+
gem.description = %q{Textile Editor Helper is a gem for Ruby on Rails 3.1 > to add a Textile toolbar above textareas.}
|
8
|
+
gem.summary = %q{Textile Editor Helper}
|
9
|
+
gem.homepage = "https://github.com/bridgeutopia/textile_editor_helper"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "textile_editor_helper"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = TextileEditorHelper::VERSION
|
17
|
+
|
18
|
+
#dependencies
|
19
|
+
gem.add_development_dependency 'rails', '>= 3.2.0'
|
20
|
+
gem.add_development_dependency "coffee-rails", '>=3.2.1'
|
21
|
+
gem.add_dependency "thor"
|
22
|
+
gem.add_dependency "test-unit"
|
23
|
+
gem.add_development_dependency "RedCloth", ">=4.2.9"
|
24
|
+
gem.add_development_dependency "htmlentities", '>=4.3.1'
|
25
|
+
gem.add_development_dependency "cucumber", '>=1.1.4'
|
26
|
+
gem.add_development_dependency "rspec", ">= 2.0.0"
|
27
|
+
end
|
data/travis.yml
ADDED
data/vendor/README
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
*********************
|
2
|
+
Textile Editor Helper
|
3
|
+
*********************
|
4
|
+
|
5
|
+
The assets have been copied.
|
6
|
+
|
7
|
+
|
8
|
+
*********************
|
9
|
+
Example App
|
10
|
+
*********************
|
11
|
+
|
12
|
+
rails g something -d mysql
|
13
|
+
rake db:create RAILS_ENV=development
|
14
|
+
rails g scaffold Post body:text
|
15
|
+
rake db:migrate
|
16
|
+
|
17
|
+
*********************
|
18
|
+
Example layout
|
19
|
+
*********************
|
20
|
+
|
21
|
+
<!DOCTYPE html>
|
22
|
+
<html>
|
23
|
+
<head>
|
24
|
+
<title>Peace</title>
|
25
|
+
<%= stylesheet_link_tag "application", :media => "all" %>
|
26
|
+
|
27
|
+
<%= csrf_meta_tags %>
|
28
|
+
<%= yield :head %>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
|
32
|
+
<%= yield %>
|
33
|
+
<%= javascript_include_tag "application" %>
|
34
|
+
<%= yield :javascript %>
|
35
|
+
</body>
|
36
|
+
</html>
|
37
|
+
|
38
|
+
|
39
|
+
****************************
|
40
|
+
Example form without preview
|
41
|
+
****************************
|
42
|
+
|
43
|
+
<%= form_for(@post) do |f| %>
|
44
|
+
<% if @post.errors.any? %>
|
45
|
+
<div id="error_explanation">
|
46
|
+
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
|
47
|
+
|
48
|
+
<ul>
|
49
|
+
<% @post.errors.full_messages.each do |msg| %>
|
50
|
+
<li><%= msg %></li>
|
51
|
+
<% end %>
|
52
|
+
</ul>
|
53
|
+
</div>
|
54
|
+
<% end %>
|
55
|
+
|
56
|
+
<div class="field">
|
57
|
+
<%= f.label :body %><br />
|
58
|
+
<%= f.textile_editor :body %>
|
59
|
+
</div>
|
60
|
+
<div class="actions">
|
61
|
+
<%= f.submit %>
|
62
|
+
<% content_for :javascript do %>
|
63
|
+
<%= textile_editor_initialize %>
|
64
|
+
<% end %>
|
65
|
+
</div>
|
66
|
+
<% end %>
|
67
|
+
|
68
|
+
****************************
|
69
|
+
Example form with preview
|
70
|
+
****************************
|
71
|
+
|
72
|
+
<%= form_for(@post) do |f| %>
|
73
|
+
<% if @post.errors.any? %>
|
74
|
+
<div id="error_explanation">
|
75
|
+
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
|
76
|
+
|
77
|
+
<ul>
|
78
|
+
<% @post.errors.full_messages.each do |msg| %>
|
79
|
+
<li><%= msg %></li>
|
80
|
+
<% end %>
|
81
|
+
</ul>
|
82
|
+
</div>
|
83
|
+
<% end %>
|
84
|
+
|
85
|
+
<div class="field">
|
86
|
+
<%= f.label :body %><br />
|
87
|
+
<%= f.textile_editor :body, :preview=>true %>
|
88
|
+
</div>
|
89
|
+
<div class="actions">
|
90
|
+
<%= f.submit %>
|
91
|
+
<% content_for :javascript do %>
|
92
|
+
<%= textile_editor_initialize :preview=>true %>
|
93
|
+
<% end %>
|
94
|
+
</div>
|
95
|
+
<% end %>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
var teButtons = TextileEditor.buttons;
|
2
|
+
|
3
|
+
teButtons.push(new TextileEditorButton('ed_strong', 'bold.png', '*', '*', 'b', 'Bold','s'));
|
4
|
+
teButtons.push(new TextileEditorButton('ed_emphasis', 'italic.png', '_', '_', 'i', 'Italicize','s'));
|
5
|
+
teButtons.push(new TextileEditorButton('ed_underline', 'underline.png', '+', '+', 'u', 'Underline','s'));
|
6
|
+
teButtons.push(new TextileEditorButton('ed_strike', 'strikethrough.png', '-', '-', 's', 'Strikethrough','s'));
|
7
|
+
teButtons.push(new TextileEditorButton('ed_ol', 'list_numbers.png', ' # ', '\n', ',', 'Numbered List'));
|
8
|
+
teButtons.push(new TextileEditorButton('ed_ul', 'list_bullets.png', ' * ', '\n', '.', 'Bulleted List'));
|
9
|
+
teButtons.push(new TextileEditorButton('ed_p', 'paragraph.png', 'p', '\n', 'p', 'Paragraph'));
|
10
|
+
teButtons.push(new TextileEditorButton('ed_h1', 'h1.png', 'h1', '\n', '1', 'Header 1'));
|
11
|
+
teButtons.push(new TextileEditorButton('ed_h2', 'h2.png', 'h2', '\n', '2', 'Header 2'));
|
12
|
+
teButtons.push(new TextileEditorButton('ed_h3', 'h3.png', 'h3', '\n', '3', 'Header 3'));
|
13
|
+
teButtons.push(new TextileEditorButton('ed_h4', 'h4.png', 'h4', '\n', '4', 'Header 4'));
|
14
|
+
teButtons.push(new TextileEditorButton('ed_block', 'blockquote.png', 'bq', '\n', 'q', 'Blockquote'));
|
15
|
+
teButtons.push(new TextileEditorButton('ed_outdent', 'outdent.png', ')', '\n', ']', 'Outdent'));
|
16
|
+
teButtons.push(new TextileEditorButton('ed_indent', 'indent.png', '(', '\n', '[', 'Indent'));
|
17
|
+
teButtons.push(new TextileEditorButton('ed_justifyl', 'left.png', '<', '\n', 'l', 'Left Justify'));
|
18
|
+
teButtons.push(new TextileEditorButton('ed_justifyc', 'center.png', '=', '\n', 'e', 'Center Text'));
|
19
|
+
teButtons.push(new TextileEditorButton('ed_justifyr', 'right.png', '>', '\n', 'r', 'Right Justify'));
|
20
|
+
teButtons.push(new TextileEditorButton('ed_justify', 'justify.png', '<>', '\n', 'j', 'Justify'));
|
21
|
+
|
22
|
+
// teButtons.push(new TextileEditorButton('ed_code','code','@','@','c','Code'));
|