rtextile 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.project +26 -0
  2. data/Gemfile +7 -0
  3. data/LICENSE +20 -0
  4. data/README.textile +44 -0
  5. data/Rakefile +8 -0
  6. data/lib/rails/generators/rtextile/USAGE +18 -0
  7. data/lib/rails/generators/rtextile/rtextile_generator.rb +80 -0
  8. data/lib/rails/generators/rtextile/templates/_form.html.erb +12 -0
  9. data/lib/rails/generators/rtextile/templates/_show.html.erb +3 -0
  10. data/lib/rails/generators/rtextile/templates/controller.rb +64 -0
  11. data/lib/rails/generators/rtextile/templates/edit.html.erb +10 -0
  12. data/lib/rails/generators/rtextile/templates/index.html.erb +8 -0
  13. data/lib/rails/generators/rtextile/templates/migration.rb +9 -0
  14. data/lib/rails/generators/rtextile/templates/model.rb +4 -0
  15. data/lib/rails/generators/rtextile/templates/new.html.erb +3 -0
  16. data/lib/rails/generators/rtextile/templates/schema.rb +14 -0
  17. data/lib/rails/generators/rtextile/templates/show.html.erb +8 -0
  18. data/lib/rails/generators/textile_editor_helper/USAGE +23 -0
  19. data/lib/rails/generators/textile_editor_helper/templates/background.png +0 -0
  20. data/lib/rails/generators/textile_editor_helper/templates/blockquote.png +0 -0
  21. data/lib/rails/generators/textile_editor_helper/templates/bold.png +0 -0
  22. data/lib/rails/generators/textile_editor_helper/templates/center.png +0 -0
  23. data/lib/rails/generators/textile_editor_helper/templates/h1.png +0 -0
  24. data/lib/rails/generators/textile_editor_helper/templates/h2.png +0 -0
  25. data/lib/rails/generators/textile_editor_helper/templates/h3.png +0 -0
  26. data/lib/rails/generators/textile_editor_helper/templates/h4.png +0 -0
  27. data/lib/rails/generators/textile_editor_helper/templates/h5.png +0 -0
  28. data/lib/rails/generators/textile_editor_helper/templates/h6.png +0 -0
  29. data/lib/rails/generators/textile_editor_helper/templates/indent.png +0 -0
  30. data/lib/rails/generators/textile_editor_helper/templates/italic.png +0 -0
  31. data/lib/rails/generators/textile_editor_helper/templates/justify.png +0 -0
  32. data/lib/rails/generators/textile_editor_helper/templates/left.png +0 -0
  33. data/lib/rails/generators/textile_editor_helper/templates/list_bullets.png +0 -0
  34. data/lib/rails/generators/textile_editor_helper/templates/list_numbers.png +0 -0
  35. data/lib/rails/generators/textile_editor_helper/templates/omega.png +0 -0
  36. data/lib/rails/generators/textile_editor_helper/templates/outdent.png +0 -0
  37. data/lib/rails/generators/textile_editor_helper/templates/paragraph.png +0 -0
  38. data/lib/rails/generators/textile_editor_helper/templates/right.png +0 -0
  39. data/lib/rails/generators/textile_editor_helper/templates/strikethrough.png +0 -0
  40. data/lib/rails/generators/textile_editor_helper/templates/textile-editor-config.js +22 -0
  41. data/lib/rails/generators/textile_editor_helper/templates/textile-editor.css +53 -0
  42. data/lib/rails/generators/textile_editor_helper/templates/textile-editor.js +676 -0
  43. data/lib/rails/generators/textile_editor_helper/templates/underline.png +0 -0
  44. data/lib/rails/generators/textile_editor_helper/textile_editor_helper_generator.rb +39 -0
  45. data/lib/rtextile/version.rb +3 -0
  46. data/lib/rtextile.rb +3 -0
  47. data/lib/textile_editor_helper.rb +185 -0
  48. data/rtextile.gemspec +22 -0
  49. metadata +126 -0
@@ -0,0 +1,39 @@
1
+ class TextileEditorHelperGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+
5
+ def copy_teh_images
6
+ copy_file 'background.png', 'public/images/textile-editor/background.png'
7
+ copy_file 'blockquote.png', 'public/images/textile-editor/blockquote.png'
8
+ copy_file 'bold.png', 'public/images/textile-editor/bold.png'
9
+ copy_file 'center.png', 'public/images/textile-editor/center.png'
10
+ copy_file 'h1.png', 'public/images/textile-editor/h1.png'
11
+ copy_file 'h2.png', 'public/images/textile-editor/h2.png'
12
+ copy_file 'h3.png', 'public/images/textile-editor/h3.png'
13
+ copy_file 'h4.png', 'public/images/textile-editor/h4.png'
14
+ copy_file 'h5.png', 'public/images/textile-editor/h5.png'
15
+ copy_file 'h6.png', 'public/images/textile-editor/h6.png'
16
+ copy_file 'indent.png', 'public/images/textile-editor/indent.png'
17
+ copy_file 'italic.png', 'public/images/textile-editor/italic.png'
18
+ copy_file 'justify.png', 'public/images/textile-editor/justify.png'
19
+ copy_file 'left.png', 'public/images/textile-editor/left.png'
20
+ copy_file 'list_bullets.png', 'public/images/textile-editor/list_bullets.png'
21
+ copy_file 'list_numbers.png', 'public/images/textile-editor/list_numbers.png'
22
+ copy_file 'omega.png', 'public/images/textile-editor/omega.png'
23
+ copy_file 'outdent.png', 'public/images/textile-editor/outdent.png'
24
+ copy_file 'paragraph.png', 'public/images/textile-editor/paragraph.png'
25
+ copy_file 'right.png', 'public/images/textile-editor/right.png'
26
+ copy_file 'strikethrough.png', 'public/images/textile-editor/strikethrough.png'
27
+ copy_file 'underline.png', 'public/images/textile-editor/underline.png'
28
+ end
29
+
30
+ def copy_stylesheet
31
+ copy_file 'textile-editor.css', 'public/stylesheets/textile-editor.css'
32
+ end
33
+ def copy_javascript
34
+ copy_file 'textile-editor.js', 'public/javascripts/textile-editor.js'
35
+ copy_file 'textile-editor-config.js', 'public/javascripts/textile-editor-config.js'
36
+ end
37
+
38
+ end
39
+
@@ -0,0 +1,3 @@
1
+ module Rtextile
2
+ VERSION = "0.2.3"
3
+ end
data/lib/rtextile.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Rtextile
2
+ require 'textile_editor_helper.rb'
3
+ end
@@ -0,0 +1,185 @@
1
+ module ActionView
2
+ module Helpers
3
+ class FormBuilder
4
+ def textile_editor(method, options = {})
5
+ @template.textile_editor(@object_name, method, options.merge(:object => @object))
6
+ end
7
+ end
8
+
9
+ module PrototypeHelper
10
+ end
11
+
12
+ module FormHelper
13
+ # Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by +method+)
14
+ # on an object assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
15
+ # hash with +options+ and places the textile toolbar above it
16
+ #
17
+ # ==== Examples
18
+ # textile_editor(:post, :body, :cols => 20, :rows => 40)
19
+ # # => <textarea cols="20" rows="40" id="post_body" name="post[body]">
20
+ # # #{@post.body}
21
+ # # </textarea>
22
+ #
23
+ # textile_editor(:comment, :text, :size => "20x30")
24
+ # # => <textarea cols="20" rows="30" id="comment_text" name="comment[text]">
25
+ # # #{@comment.text}
26
+ # # </textarea>
27
+ #
28
+ # textile_editor(:application, :notes, :cols => 40, :rows => 15, :class => 'app_input')
29
+ # # => <textarea cols="40" rows="15" id="application_notes" name="application[notes]" class="app_input">
30
+ # # #{@application.notes}
31
+ # # </textarea>
32
+ #
33
+ # textile_editor(:entry, :body, :size => "20x20", :disabled => 'disabled')
34
+ # # => <textarea cols="20" rows="20" id="entry_body" name="entry[body]" disabled="disabled">
35
+ # # #{@entry.body}
36
+ # # </textarea>
37
+ def textile_editor(object_name, method, options = {})
38
+ editor_id = options[:id] || '%s_%s' % [object_name, method]
39
+ mode = options.delete(:simple) ? 'simple' : 'extended'
40
+ (@textile_editor_ids ||= []) << [editor_id.to_s, mode.to_s]
41
+
42
+ InstanceTag.new(object_name, method, self, options.delete(:object)).to_text_area_tag(options)
43
+ end
44
+
45
+ def textile_editor_options(options={})
46
+ (@textile_editor_options ||= { :framework => :prototype }).merge! options
47
+ end
48
+
49
+ def textile_editor_support
50
+ output = []
51
+ output << stylesheet_link_tag('textile-editor')
52
+ output << javascript_include_tag('textile-editor')
53
+ output.join("\n").html_safe
54
+ end
55
+
56
+ # registers a new button for the Textile Editor toolbar
57
+ # Parameters:
58
+ # * +text+: text to display (contents of button tag, so HTML is valid as well)
59
+ # * +options+: options Hash as supported by +content_tag+ helper in Rails
60
+ #
61
+ # Example:
62
+ # The following example adds a button labeled 'Greeting' which triggers an
63
+ # alert:
64
+ #
65
+ # <% textile_editor_button 'Greeting', :onclick => "alert('Hello!')" %>
66
+ #
67
+ # *Note*: this method must be called before +textile_editor_initialize+
68
+ def textile_editor_button(text, options={})
69
+ return textile_editor_button_separator if text == :separator
70
+ button = content_tag(:button, text, options)
71
+ button = "TextileEditor.buttons.push(\"%s\");" % escape_javascript(button)
72
+ (@textile_editor_buttons ||= []) << button
73
+ end
74
+
75
+ def textile_editor_button_separator(options={})
76
+ button = "TextileEditor.buttons.push(new TextileEditorButtonSeparator('%s'));" % (options[:simple] || '')
77
+ (@textile_editor_buttons ||= []) << button
78
+ end
79
+
80
+ def textile_extract_dom_ids(*dom_ids)
81
+ hash = dom_ids.last.is_a?(Hash) ? dom_ids.pop : {}
82
+ hash.inject(dom_ids) do |ids, (object, fields)|
83
+ ids + Array(fields).map { |field| "%s_%s" % [object, field] }
84
+ end
85
+ end
86
+
87
+ # adds the necessary javascript include tags, stylesheet tags,
88
+ # and load event with necessary javascript to active textile editor(s)
89
+ # sample output:
90
+ # <link href="/stylesheets/textile-editor.css" media="screen" rel="Stylesheet" type="text/css" />
91
+ # <script src="/javascripts/textile-editor.js" type="text/javascript"></script>
92
+ # <script type="text/javascript">
93
+ # document.observe('dom:loaded', function() {
94
+ # TextileEditor.initialize('article_body', 'extended');
95
+ # TextileEditor.initialize('article_body_excerpt', 'simple');
96
+ # });
97
+ # </script>
98
+ #
99
+ # Note: in the case of this helper being called via AJAX, the output will be reduced:
100
+ # <script type="text/javascript">
101
+ # TextileEditor.initialize('article_body', 'extended');
102
+ # TextileEditor.initialize('article_body_excerpt', 'simple');
103
+ # </script>
104
+ #
105
+ # This means that the support files must be loaded outside of the AJAX request, either
106
+ # via a call to this helper or the textile_editor_support() helper
107
+ def textile_editor_initialize(*dom_ids)
108
+ options = textile_editor_options.dup
109
+
110
+ # extract options from last argument if it's a hash
111
+ if dom_ids.last.is_a?(Hash)
112
+ hash = dom_ids.last.dup
113
+ options.merge! hash
114
+ dom_ids.last.delete :framework
115
+ end
116
+
117
+ editor_ids = (@textile_editor_ids || []) + textile_extract_dom_ids(*dom_ids)
118
+ editor_buttons = (@textile_editor_buttons || [])
119
+ output = []
120
+ output << textile_editor_support unless request.xhr?
121
+ output << '<script type="text/javascript">'
122
+ output << '/* <![CDATA[ */'
123
+
124
+ if !request.xhr?
125
+ case options[:framework]
126
+ when :prototype
127
+ output << %{document.observe('dom:loaded', function() \{}
128
+ when :jquery
129
+ output << %{jQuery(document).ready(function($) \{}
130
+ end
131
+ end
132
+
133
+ # output << %q{TextileEditor.framework = '%s';} % options[:framework].to_s
134
+ output << editor_buttons.join("\n") if editor_buttons.any?
135
+ editor_ids.each do |editor_id, mode|
136
+ output << %q{TextileEditor.initialize('%s', '%s');} % [editor_id, mode || 'extended']
137
+ end
138
+ output << '});' unless request.xhr?
139
+
140
+ output << '/* ]]> */'
141
+ output << '</script>'
142
+ output.join("\n").html_safe
143
+ end
144
+ end
145
+
146
+ module FormTagHelper
147
+ # Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions
148
+ # and includes the textile toolbar above it.
149
+ #
150
+ # ==== Options
151
+ # * <tt>:size</tt> - A string specifying the dimensions (columns by rows) of the textarea (e.g., "25x10").
152
+ # * <tt>:rows</tt> - Specify the number of rows in the textarea
153
+ # * <tt>:cols</tt> - Specify the number of columns in the textarea
154
+ # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
155
+ # * Any other key creates standard HTML attributes for the tag.
156
+ #
157
+ # ==== Examples
158
+ # textile_editor_tag 'post'
159
+ # # => <textarea id="post" name="post"></textarea>
160
+ #
161
+ # textile_editor_tag 'bio', @user.bio
162
+ # # => <textarea id="bio" name="bio">This is my biography.</textarea>
163
+ #
164
+ # textile_editor_tag 'body', nil, :rows => 10, :cols => 25
165
+ # # => <textarea cols="25" id="body" name="body" rows="10"></textarea>
166
+ #
167
+ # textile_editor_tag 'body', nil, :size => "25x10"
168
+ # # => <textarea name="body" id="body" cols="25" rows="10"></textarea>
169
+ #
170
+ # textile_editor_tag 'description', "Description goes here.", :disabled => true
171
+ # # => <textarea disabled="disabled" id="description" name="description">Description goes here.</textarea>
172
+ #
173
+ # textile_editor_tag 'comment', nil, :class => 'comment_input'
174
+ # # => <textarea class="comment_input" id="comment" name="comment"></textarea>
175
+ def textile_editor_tag(name, content = nil, options = {})
176
+ editor_id = options[:id] || name
177
+ mode = options.delete(:simple) ? 'simple' : 'extended'
178
+ (@textile_editor_ids ||= []) << [editor_id.to_s, mode.to_s]
179
+
180
+ text_area_tag(name, content, options)
181
+ end
182
+ end
183
+
184
+ end
185
+ end
data/rtextile.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rtextile/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rtextile"
7
+ s.version = Rtextile::VERSION
8
+ s.authors = ["Xfinger"]
9
+ s.email = ["xfinger@gmail.com"]
10
+ s.homepage = "https://github.com/XFinger/rtextile"
11
+ s.summary = %q{Rails 3 Textile Editor}
12
+ s.description = %q{ Rails Textile Editor, includes Textile_Editor_Helper plugin files that
13
+ have been upgraded for rails 3 }
14
+
15
+ s.rubyforge_project = "rtextile"
16
+ s.add_dependency('RedCloth')
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtextile
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 3
10
+ version: 0.2.3
11
+ platform: ruby
12
+ authors:
13
+ - Xfinger
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-01 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: RedCloth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: " Rails Textile Editor, includes Textile_Editor_Helper plugin files that\n have been upgraded for rails 3 "
35
+ email:
36
+ - xfinger@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .project
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.textile
48
+ - Rakefile
49
+ - lib/rails/generators/rtextile/USAGE
50
+ - lib/rails/generators/rtextile/rtextile_generator.rb
51
+ - lib/rails/generators/rtextile/templates/_form.html.erb
52
+ - lib/rails/generators/rtextile/templates/_show.html.erb
53
+ - lib/rails/generators/rtextile/templates/controller.rb
54
+ - lib/rails/generators/rtextile/templates/edit.html.erb
55
+ - lib/rails/generators/rtextile/templates/index.html.erb
56
+ - lib/rails/generators/rtextile/templates/migration.rb
57
+ - lib/rails/generators/rtextile/templates/model.rb
58
+ - lib/rails/generators/rtextile/templates/new.html.erb
59
+ - lib/rails/generators/rtextile/templates/schema.rb
60
+ - lib/rails/generators/rtextile/templates/show.html.erb
61
+ - lib/rails/generators/textile_editor_helper/USAGE
62
+ - lib/rails/generators/textile_editor_helper/templates/background.png
63
+ - lib/rails/generators/textile_editor_helper/templates/blockquote.png
64
+ - lib/rails/generators/textile_editor_helper/templates/bold.png
65
+ - lib/rails/generators/textile_editor_helper/templates/center.png
66
+ - lib/rails/generators/textile_editor_helper/templates/h1.png
67
+ - lib/rails/generators/textile_editor_helper/templates/h2.png
68
+ - lib/rails/generators/textile_editor_helper/templates/h3.png
69
+ - lib/rails/generators/textile_editor_helper/templates/h4.png
70
+ - lib/rails/generators/textile_editor_helper/templates/h5.png
71
+ - lib/rails/generators/textile_editor_helper/templates/h6.png
72
+ - lib/rails/generators/textile_editor_helper/templates/indent.png
73
+ - lib/rails/generators/textile_editor_helper/templates/italic.png
74
+ - lib/rails/generators/textile_editor_helper/templates/justify.png
75
+ - lib/rails/generators/textile_editor_helper/templates/left.png
76
+ - lib/rails/generators/textile_editor_helper/templates/list_bullets.png
77
+ - lib/rails/generators/textile_editor_helper/templates/list_numbers.png
78
+ - lib/rails/generators/textile_editor_helper/templates/omega.png
79
+ - lib/rails/generators/textile_editor_helper/templates/outdent.png
80
+ - lib/rails/generators/textile_editor_helper/templates/paragraph.png
81
+ - lib/rails/generators/textile_editor_helper/templates/right.png
82
+ - lib/rails/generators/textile_editor_helper/templates/strikethrough.png
83
+ - lib/rails/generators/textile_editor_helper/templates/textile-editor-config.js
84
+ - lib/rails/generators/textile_editor_helper/templates/textile-editor.css
85
+ - lib/rails/generators/textile_editor_helper/templates/textile-editor.js
86
+ - lib/rails/generators/textile_editor_helper/templates/underline.png
87
+ - lib/rails/generators/textile_editor_helper/textile_editor_helper_generator.rb
88
+ - lib/rtextile.rb
89
+ - lib/rtextile/version.rb
90
+ - lib/textile_editor_helper.rb
91
+ - rtextile.gemspec
92
+ homepage: https://github.com/XFinger/rtextile
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project: rtextile
121
+ rubygems_version: 1.7.2
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Rails 3 Textile Editor
125
+ test_files: []
126
+