textile_rails 0.0.2

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 (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/lib/generators/textile_rails/install_generator.rb +45 -0
  8. data/lib/helpers/default.rb +192 -0
  9. data/lib/textile_rails.rb +10 -0
  10. data/lib/textile_rails/version.rb +3 -0
  11. data/textile_rails.gemspec +23 -0
  12. data/vendor/README +90 -0
  13. data/vendor/assets/images/textile-editor/.DS_Store +0 -0
  14. data/vendor/assets/images/textile-editor/background.png +0 -0
  15. data/vendor/assets/images/textile-editor/blockquote.png +0 -0
  16. data/vendor/assets/images/textile-editor/bold.png +0 -0
  17. data/vendor/assets/images/textile-editor/center.png +0 -0
  18. data/vendor/assets/images/textile-editor/h1.png +0 -0
  19. data/vendor/assets/images/textile-editor/h2.png +0 -0
  20. data/vendor/assets/images/textile-editor/h3.png +0 -0
  21. data/vendor/assets/images/textile-editor/h4.png +0 -0
  22. data/vendor/assets/images/textile-editor/h5.png +0 -0
  23. data/vendor/assets/images/textile-editor/h6.png +0 -0
  24. data/vendor/assets/images/textile-editor/icon_biggrin.gif +0 -0
  25. data/vendor/assets/images/textile-editor/icon_confused.gif +0 -0
  26. data/vendor/assets/images/textile-editor/icon_cool.gif +0 -0
  27. data/vendor/assets/images/textile-editor/icon_cry.gif +0 -0
  28. data/vendor/assets/images/textile-editor/icon_eek.gif +0 -0
  29. data/vendor/assets/images/textile-editor/icon_evil.gif +0 -0
  30. data/vendor/assets/images/textile-editor/icon_lol.gif +0 -0
  31. data/vendor/assets/images/textile-editor/icon_redface.gif +0 -0
  32. data/vendor/assets/images/textile-editor/icon_rolleyes.gif +0 -0
  33. data/vendor/assets/images/textile-editor/icon_sad.gif +0 -0
  34. data/vendor/assets/images/textile-editor/icon_smile.gif +0 -0
  35. data/vendor/assets/images/textile-editor/icon_surprised.gif +0 -0
  36. data/vendor/assets/images/textile-editor/icon_toungueout.gif +0 -0
  37. data/vendor/assets/images/textile-editor/icon_twisted.gif +0 -0
  38. data/vendor/assets/images/textile-editor/icon_wink.gif +0 -0
  39. data/vendor/assets/images/textile-editor/indent.png +0 -0
  40. data/vendor/assets/images/textile-editor/italic.png +0 -0
  41. data/vendor/assets/images/textile-editor/justify.png +0 -0
  42. data/vendor/assets/images/textile-editor/left.png +0 -0
  43. data/vendor/assets/images/textile-editor/list_bullets.png +0 -0
  44. data/vendor/assets/images/textile-editor/list_numbers.png +0 -0
  45. data/vendor/assets/images/textile-editor/omega.png +0 -0
  46. data/vendor/assets/images/textile-editor/outdent.png +0 -0
  47. data/vendor/assets/images/textile-editor/paragraph.png +0 -0
  48. data/vendor/assets/images/textile-editor/right.png +0 -0
  49. data/vendor/assets/images/textile-editor/strikethrough.png +0 -0
  50. data/vendor/assets/images/textile-editor/underline.png +0 -0
  51. data/vendor/assets/javascripts/textile-editor-config.js +38 -0
  52. data/vendor/assets/javascripts/textile-editor.js +683 -0
  53. data/vendor/assets/stylesheets/textile-editor.css +53 -0
  54. metadata +139 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea40a8dd8118d1274b0ffbedf6e5bc06a9434e1d
4
+ data.tar.gz: 87eec5a2742ec60ad6800785994d87f7905c447e
5
+ SHA512:
6
+ metadata.gz: 25752dbf383309510a13c935ef0db9903bde572099a80baf4458cfc17c5694e11ce6c88c7d910da6320c246b707205189ddab0823fe776f7ac18fb030964e44c
7
+ data.tar.gz: b47dd258eb2cfe9a4496d730ae5bb3f20c0f5163193b0c54e60e7178891053776c5c283f2d12929217fefd8444c16b9832b19cfef93f1525ccf5339abeef4d96
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in textile_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Anidhya-desidime
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # TextileRails
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'textile_rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install textile_rails
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/textile_rails/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,45 @@
1
+ module TextileRails
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../../../../vendor', __FILE__)
5
+
6
+ private
7
+
8
+ def self.asset_pipeline_enabled?
9
+ (Rails.configuration.respond_to?(:assets) ? (Rails.configuration.assets || {}) : {})[:enabled]
10
+ end
11
+
12
+ def asset_pipeline_enabled?
13
+ self.class.asset_pipeline_enabled?
14
+ end
15
+
16
+ public
17
+
18
+ if asset_pipeline_enabled?
19
+ desc 'Creates a TextileEditorHelper initializer and copies assets to app/assets and public/images.'
20
+ else
21
+ desc 'Creates a TextileEditorHelper initializer and copies assets to public directories.'
22
+ end
23
+
24
+ def copy_assets
25
+ if asset_pipeline_enabled?
26
+ js_destination = 'app/assets/javascripts'
27
+ css_destination = 'app/assets/stylesheets'
28
+ else
29
+ js_destination = 'public/javascripts'
30
+ css_destination = 'public/stylesheets'
31
+ end
32
+
33
+ copy_file 'assets/javascripts/textile-editor.js', "#{js_destination}/textile-editor.js"
34
+ copy_file 'assets/javascripts/textile-editor-config.js', "#{js_destination}/textile-editor-config.js"
35
+ copy_file 'assets/stylesheets/textile-editor.css', "#{css_destination}/textile-editor.css"
36
+
37
+ directory 'assets/images/textile-editor', 'public/images/textile-editor'
38
+
39
+ readme 'README' if behavior == :invoke
40
+
41
+ end
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,192 @@
1
+ #require_relative 'textile_editor_initialize'
2
+
3
+ module ActionView
4
+ module Helpers
5
+ include FormTagHelper
6
+
7
+ class FormBuilder
8
+ def textile_editor(method, options = {})
9
+ @template.textile_editor(@object_name, method, options.merge(:object => @object))
10
+ end
11
+ end
12
+
13
+ module PrototypeHelper
14
+ end
15
+
16
+ module FormHelper
17
+ # Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by +method+)
18
+ # on an object assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
19
+ # hash with +options+ and places the textile toolbar above it
20
+ #
21
+ # ==== Examples
22
+ # textile_editor(:post, :body, :cols => 20, :rows => 40)
23
+ # # => <textarea cols="20" rows="40" id="post_body" name="post[body]">
24
+ # # #{@post.body}
25
+ # # </textarea>
26
+ #
27
+ # textile_editor(:comment, :text, :size => "20x30")
28
+ # # => <textarea cols="20" rows="30" id="comment_text" name="comment[text]">
29
+ # # #{@comment.text}
30
+ # # </textarea>
31
+ #
32
+ # textile_editor(:application, :notes, :cols => 40, :rows => 15, :class => 'app_input')
33
+ # # => <textarea cols="40" rows="15" id="application_notes" name="application[notes]" class="app_input">
34
+ # # #{@application.notes}
35
+ # # </textarea>
36
+ #
37
+ # textile_editor(:entry, :body, :size => "20x20", :disabled => 'disabled')
38
+ # # => <textarea cols="20" rows="20" id="entry_body" name="entry[body]" disabled="disabled">
39
+ # # #{@entry.body}
40
+ # # </textarea>
41
+ def textile_editor(object_name, method, options = {})
42
+ editor_id = options[:id] || '%s_%s' % [object_name, method]
43
+ mode = options.delete(:simple) ? 'simple' : 'extended'
44
+ (@textile_editor_ids ||= []) << [editor_id.to_s, mode.to_s]
45
+
46
+ #ActiveModelInstanceTag.new(object_name, method, self, options.delete(:object)).to_text_area_tag(options)
47
+ Tags::TextArea.new(object_name, method, self, options).render
48
+ end
49
+
50
+ def textile_editor_options(options={})
51
+ (@textile_editor_options ||= { :framework => :prototype }).merge! options
52
+ end
53
+
54
+ def textile_editor_support
55
+ output = []
56
+ output << stylesheet_link_tag('textile-editor')
57
+ output << javascript_include_tag('textile-editor')
58
+ output << javascript_include_tag('textile-editor-config')
59
+ output.join("\n").html_safe
60
+ end
61
+
62
+ # registers a new button for the Textile Editor toolbar
63
+ # Parameters:
64
+ # * +text+: text to display (contents of button tag, so HTML is valid as well)
65
+ # * +options+: options Hash as supported by +content_tag+ helper in Rails
66
+ #
67
+ # Example:
68
+ # The following example adds a button labeled 'Greeting' which triggers an
69
+ # alert:
70
+ #
71
+ # <% textile_editor_button 'Greeting', :onclick => "alert('Hello!')" %>
72
+ #
73
+ # *Note*: this method must be called before +textile_editor_initialize+
74
+ def textile_editor_button(text, options={})
75
+ return textile_editor_button_separator if text == :separator
76
+ button = content_tag(:button, text, options)
77
+ button = "TextileEditor.buttons.push(\"%s\");" % escape_javascript(button)
78
+ (@textile_editor_buttons ||= []) << button
79
+ end
80
+
81
+ def textile_editor_button_separator(options={})
82
+ button = "TextileEditor.buttons.push(new TextileEditorButtonSeparator('%s'));" % (options[:simple] || '')
83
+ (@textile_editor_buttons ||= []) << button
84
+ end
85
+
86
+ def textile_extract_dom_ids(*dom_ids)
87
+ hash = dom_ids.last.is_a?(Hash) ? dom_ids.pop : {}
88
+ hash.inject(dom_ids) do |ids, (object, fields)|
89
+ ids + Array(fields).map { |field| "%s_%s" % [object, field] }
90
+ end
91
+ end
92
+
93
+ # adds the necessary javascript include tags, stylesheet tags,
94
+ # and load event with necessary javascript to active textile editor(s)
95
+ # sample output:
96
+ # <link href="/stylesheets/textile-editor.css" media="screen" rel="Stylesheet" type="text/css" />
97
+ # <script src="/javascripts/textile-editor.js" type="text/javascript"></script>
98
+ # <script type="text/javascript">
99
+ # document.observe('dom:loaded', function() {
100
+ # TextileEditor.initialize('article_body', 'extended');
101
+ # TextileEditor.initialize('article_body_excerpt', 'simple');
102
+ # });
103
+ # </script>
104
+ #
105
+ # Note: in the case of this helper being called via AJAX, the output will be reduced:
106
+ # <script type="text/javascript">
107
+ # TextileEditor.initialize('article_body', 'extended');
108
+ # TextileEditor.initialize('article_body_excerpt', 'simple');
109
+ # </script>
110
+ #
111
+ # This means that the support files must be loaded outside of the AJAX request, either
112
+ # via a call to this helper or the textile_editor_support() helper
113
+ def textile_editor_initialize(*dom_ids)
114
+ options = textile_editor_options.dup
115
+
116
+ # extract options from last argument if it's a hash
117
+ if dom_ids.last.is_a?(Hash)
118
+ hash = dom_ids.last.dup
119
+ options.merge! hash
120
+ dom_ids.last.delete :framework
121
+ end
122
+
123
+ editor_ids = (@textile_editor_ids || []) + textile_extract_dom_ids(*dom_ids)
124
+ editor_buttons = (@textile_editor_buttons || [])
125
+ output = []
126
+ output << textile_editor_support unless request.xhr?
127
+ output << '<script type="text/javascript">'
128
+ output << '/* <![CDATA[ */'
129
+
130
+ if !request.xhr?
131
+ case options[:framework]
132
+ when :prototype
133
+ output << %{document.observe('dom:loaded', function() \{}
134
+ when :jquery
135
+ output << %{jQuery(document).ready(function($) \{}
136
+ end
137
+ end
138
+
139
+ # output << %q{TextileEditor.framework = '%s';} % options[:framework].to_s
140
+ output << editor_buttons.join("\n") if editor_buttons.any?
141
+ editor_ids.each do |editor_id, mode|
142
+ output << %q{TextileEditor.initialize('%s', '%s');} % [editor_id, mode || 'extended']
143
+ end
144
+ output << '});' unless request.xhr?
145
+
146
+ output << '/* ]]> */'
147
+ output << '</script>'
148
+ output.join("\n").html_safe
149
+ end
150
+ end
151
+
152
+ module FormTagHelper
153
+ # Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions
154
+ # and includes the textile toolbar above it.
155
+ #
156
+ # ==== Options
157
+ # * <tt>:size</tt> - A string specifying the dimensions (columns by rows) of the textarea (e.g., "25x10").
158
+ # * <tt>:rows</tt> - Specify the number of rows in the textarea
159
+ # * <tt>:cols</tt> - Specify the number of columns in the textarea
160
+ # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
161
+ # * Any other key creates standard HTML attributes for the tag.
162
+ #
163
+ # ==== Examples
164
+ # textile_editor_tag 'post'
165
+ # # => <textarea id="post" name="post"></textarea>
166
+ #
167
+ # textile_editor_tag 'bio', @user.bio
168
+ # # => <textarea id="bio" name="bio">This is my biography.</textarea>
169
+ #
170
+ # textile_editor_tag 'body', nil, :rows => 10, :cols => 25
171
+ # # => <textarea cols="25" id="body" name="body" rows="10"></textarea>
172
+ #
173
+ # textile_editor_tag 'body', nil, :size => "25x10"
174
+ # # => <textarea name="body" id="body" cols="25" rows="10"></textarea>
175
+ #
176
+ # textile_editor_tag 'description', "Description goes here.", :disabled => true
177
+ # # => <textarea disabled="disabled" id="description" name="description">Description goes here.</textarea>
178
+ #
179
+ # textile_editor_tag 'comment', nil, :class => 'comment_input'
180
+ # # => <textarea class="comment_input" id="comment" name="comment"></textarea>
181
+ def textile_editor_tag(name, content = nil, options = {})
182
+ editor_id = options[:id] || name
183
+ mode = options.delete(:simple) ? 'simple' : 'extended'
184
+ (@textile_editor_ids ||= []) << [editor_id.to_s, mode.to_s]
185
+
186
+ text_area_tag(name, content, options)
187
+ end
188
+ end
189
+
190
+ end
191
+ end
192
+
@@ -0,0 +1,10 @@
1
+ require "textile_rails/version"
2
+
3
+ require 'action_view'
4
+
5
+ require_relative 'helpers/default'
6
+
7
+ module TextileRails
8
+ # Your code goes here...
9
+ end
10
+
@@ -0,0 +1,3 @@
1
+ module TextileRails
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'textile_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "textile_rails"
8
+ spec.version = TextileRails::VERSION
9
+ spec.authors = ["Anidhya","Beena"]
10
+ spec.email = ["anidhyaahuja@gmail.com","binu.shetty@gmail.com"]
11
+ spec.summary = %q{Textile editor for rails 4}
12
+ spec.description = %q{Textile editor plugin bundled into gem for rails 4}
13
+ spec.homepage = ""
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency 'rails', '>= 4.0.0'
23
+ end
data/vendor/README ADDED
@@ -0,0 +1,90 @@
1
+ *********************
2
+ Textile Editor Helper
3
+ *********************
4
+
5
+ The assets have been copied.
6
+
7
+
8
+ *********************
9
+ Example App
10
+ *********************
11
+
12
+ rails new 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 application.js
41
+ ***************************
42
+
43
+ //= require jquery
44
+ //= require jquery_ujs
45
+ //= require textile-editor
46
+ //= require textile-editor-config
47
+
48
+ ****************************
49
+ Example form
50
+ ****************************
51
+
52
+ <%= form_for(@post) do |f| %>
53
+ <% if @post.errors.any? %>
54
+ <div id="error_explanation">
55
+ <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
56
+
57
+ <ul>
58
+ <% @post.errors.full_messages.each do |msg| %>
59
+ <li><%= msg %></li>
60
+ <% end %>
61
+ </ul>
62
+ </div>
63
+ <% end %>
64
+
65
+ <div class="field">
66
+ <%= f.label :body %><br />
67
+ <%= f.textile_editor :body %>
68
+ </div>
69
+ <div class="actions">
70
+ <%= f.submit %>
71
+ <% content_for :javascript do %>
72
+ <%= textile_editor_initialize %>
73
+ <% end %>
74
+ </div>
75
+ <% end %>
76
+
77
+
78
+
79
+ ********************************
80
+ Example: If you use simple_form
81
+ ********************************
82
+
83
+ <%= simple_form_for @post do |f| %>
84
+ <%= f.input :body, :as=>:textile_editor %>
85
+ <%= f.button :submit %>
86
+
87
+ <% content_for :javascript do %>
88
+ <%= textile_editor_initialize %>
89
+ <% end %>
90
+ <% end %>