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.
Files changed (46) hide show
  1. data/.gitignore +20 -0
  2. data/Gemfile +5 -0
  3. data/README.md +130 -0
  4. data/Rakefile +7 -0
  5. data/features/copy_assets.feature +17 -0
  6. data/features/step_definitions/common_steps.rb +66 -0
  7. data/features/step_definitions/rails_setup_steps.rb +9 -0
  8. data/features/support/env.rb +0 -0
  9. data/features/support/setup.rb +0 -0
  10. data/lib/generators/textile_editor_helper/install_generator.rb +54 -0
  11. data/lib/textile_editor_helper.rb +204 -0
  12. data/lib/textile_editor_helper/version.rb +3 -0
  13. data/test/abstract_unit.rb +16 -0
  14. data/test/textile_editor_helper_test.rb +195 -0
  15. data/textile_editor_helper.gemspec +27 -0
  16. data/travis.yml +5 -0
  17. data/vendor/README +95 -0
  18. data/vendor/app/controllers/textile_preview_controller.rb +14 -0
  19. data/vendor/app/helpers/textile_preview_helper.rb +14 -0
  20. data/vendor/app/views/textile_preview/show.js.coffee +2 -0
  21. data/vendor/assets/images/textile-editor/background.png +0 -0
  22. data/vendor/assets/images/textile-editor/blockquote.png +0 -0
  23. data/vendor/assets/images/textile-editor/bold.png +0 -0
  24. data/vendor/assets/images/textile-editor/center.png +0 -0
  25. data/vendor/assets/images/textile-editor/h1.png +0 -0
  26. data/vendor/assets/images/textile-editor/h2.png +0 -0
  27. data/vendor/assets/images/textile-editor/h3.png +0 -0
  28. data/vendor/assets/images/textile-editor/h4.png +0 -0
  29. data/vendor/assets/images/textile-editor/h5.png +0 -0
  30. data/vendor/assets/images/textile-editor/h6.png +0 -0
  31. data/vendor/assets/images/textile-editor/indent.png +0 -0
  32. data/vendor/assets/images/textile-editor/italic.png +0 -0
  33. data/vendor/assets/images/textile-editor/justify.png +0 -0
  34. data/vendor/assets/images/textile-editor/left.png +0 -0
  35. data/vendor/assets/images/textile-editor/list_bullets.png +0 -0
  36. data/vendor/assets/images/textile-editor/list_numbers.png +0 -0
  37. data/vendor/assets/images/textile-editor/omega.png +0 -0
  38. data/vendor/assets/images/textile-editor/outdent.png +0 -0
  39. data/vendor/assets/images/textile-editor/paragraph.png +0 -0
  40. data/vendor/assets/images/textile-editor/right.png +0 -0
  41. data/vendor/assets/images/textile-editor/strikethrough.png +0 -0
  42. data/vendor/assets/images/textile-editor/underline.png +0 -0
  43. data/vendor/assets/javascripts/textile-editor-config.js +22 -0
  44. data/vendor/assets/javascripts/textile-editor.js +687 -0
  45. data/vendor/assets/stylesheets/textile-editor.css +53 -0
  46. metadata +186 -0
@@ -0,0 +1,3 @@
1
+ module TextileEditorHelper
2
+ VERSION = "0.0.12"
3
+ end
@@ -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
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-19mode
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 %>
@@ -0,0 +1,14 @@
1
+ class TextilePreviewController < ApplicationController
2
+
3
+ respond_to :js
4
+
5
+ include TextilePreviewHelper
6
+
7
+ def show
8
+ @text = params[:text_data]
9
+ @editor_id = params[:id]
10
+ @preview = to_html(@text)
11
+ end
12
+
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ module TextilePreviewHelper
2
+
3
+ def to_html(m)
4
+ require 'redcloth'
5
+ require 'htmlentities'
6
+
7
+ coder = HTMLEntities.new
8
+ m = coder.decode(m)
9
+ m = RedCloth.new(m).to_html
10
+ m = view_context.raw m.gsub('<p>&nbsp;</p>', "")
11
+ m
12
+ end
13
+
14
+ end
@@ -0,0 +1,2 @@
1
+ $("#<%= @editor_id%>").keyup ->
2
+ $("#<%= @editor_id%>_destination").html('<%= @preview %>')
@@ -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'));