textile_editor_helper 0.0.14 → 0.0.30
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 +0 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +0 -0
- data/README.md +54 -95
- data/Rakefile +8 -3
- data/features/copy_assets.feature +5 -10
- data/features/step_definitions/common_steps.rb +0 -0
- data/features/step_definitions/rails_setup_steps.rb +0 -0
- data/features/support/env.rb +0 -0
- data/features/support/setup.rb +0 -0
- data/lib/generators/textile_editor_helper/install_generator.rb +4 -13
- data/lib/helpers/default.rb +138 -0
- data/lib/helpers/formtastic.rb +39 -0
- data/lib/helpers/simple_form.rb +27 -0
- data/lib/helpers/textile_editor_initialize.rb +19 -0
- data/lib/textile_editor_helper/version.rb +1 -1
- data/lib/textile_editor_helper.rb +15 -201
- data/test/abstract_unit.rb +11 -4
- data/test/formtastic_test.rb +21 -0
- data/test/simple_form_test.rb +21 -0
- data/test/support_methods.rb +54 -0
- data/test/test_helper.rb +7 -0
- data/test/textile_editor_helper_test.rb +30 -172
- data/textile_editor_helper.gemspec +14 -15
- data/travis.yml +0 -0
- data/vendor/README +26 -31
- 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 +0 -0
- data/vendor/assets/javascripts/textile-editor.js +0 -0
- data/vendor/assets/stylesheets/textile-editor.css +0 -0
- metadata +76 -36
- data/vendor/app/controllers/textile_preview_controller.rb +0 -14
- data/vendor/app/helpers/textile_preview_helper.rb +0 -13
- data/vendor/app/views/textile_preview/show.js.coffee +0 -2
| @@ -1,206 +1,20 @@ | |
| 1 1 | 
             
            require "textile_editor_helper/version"
         | 
| 2 | 
            +
            require 'action_view'
         | 
| 2 3 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            -
            end
         | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
            module ActionView
         | 
| 9 | 
            -
              module Helpers
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                class FormBuilder
         | 
| 12 | 
            -
                  def textile_editor(method, options = {})
         | 
| 13 | 
            -
                    @template.textile_editor(@object_name, method, options.merge(:object => @object))
         | 
| 14 | 
            -
                  end
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                
         | 
| 18 | 
            -
                module FormHelper
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                  # Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by +method+)
         | 
| 21 | 
            -
                  # on an object assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
         | 
| 22 | 
            -
                  # hash with +options+ and places the textile toolbar above it
         | 
| 23 | 
            -
                  #
         | 
| 24 | 
            -
                  # ==== Examples
         | 
| 25 | 
            -
                  #   textile_editor(:post, :body, :cols => 20, :rows => 40)
         | 
| 26 | 
            -
                  #   # => <textarea cols="20" rows="40" id="post_body" name="post[body]">
         | 
| 27 | 
            -
                  #   #      #{@post.body}
         | 
| 28 | 
            -
                  #   #    </textarea>
         | 
| 29 | 
            -
                  #
         | 
| 30 | 
            -
                  #   textile_editor(:comment, :text, :size => "20x30")
         | 
| 31 | 
            -
                  #   # => <textarea cols="20" rows="30" id="comment_text" name="comment[text]">
         | 
| 32 | 
            -
                  #   #      #{@comment.text}
         | 
| 33 | 
            -
                  #   #    </textarea>
         | 
| 34 | 
            -
                  #
         | 
| 35 | 
            -
                  #   textile_editor(:application, :notes, :cols => 40, :rows => 15, :class => 'app_input')
         | 
| 36 | 
            -
                  #   # => <textarea cols="40" rows="15" id="application_notes" name="application[notes]" class="app_input">
         | 
| 37 | 
            -
                  #   #      #{@application.notes}
         | 
| 38 | 
            -
                  #   #    </textarea>
         | 
| 39 | 
            -
                  #
         | 
| 40 | 
            -
                  #   textile_editor(:entry, :body, :size => "20x20", :disabled => 'disabled')
         | 
| 41 | 
            -
                  #   # => <textarea cols="20" rows="20" id="entry_body" name="entry[body]" disabled="disabled">
         | 
| 42 | 
            -
                  #   #      #{@entry.body}
         | 
| 43 | 
            -
                  #   #    </textarea>
         | 
| 44 | 
            -
                  def textile_editor(object_name, method, options = {})        
         | 
| 45 | 
            -
                    editor_id = options[:id] || '%s_%s' % [object_name, method]
         | 
| 46 | 
            -
                    mode      = options.delete(:simple) ? 'simple' : 'extended'
         | 
| 47 | 
            -
                    preview   = options.delete(:preview) ? true : false
         | 
| 48 | 
            -
                    (@textile_editor_ids ||= []) << [editor_id.to_s, mode.to_s]
         | 
| 49 | 
            -
             | 
| 50 | 
            -
            				output = []
         | 
| 51 | 
            -
            				output << InstanceTag.new(object_name, method, self, options.delete(:object)).to_text_area_tag(options)
         | 
| 52 | 
            -
            				output << %q{<div id="%s_destination" class="textile-preview"></div>} % [editor_id]	if preview
         | 
| 53 | 
            -
            				output.join("\n").html_safe
         | 
| 54 | 
            -
            				
         | 
| 55 | 
            -
                  end
         | 
| 56 | 
            -
                  
         | 
| 57 | 
            -
                  def textile_editor_options(options={})
         | 
| 58 | 
            -
                    (@textile_editor_options ||= { }).merge! options
         | 
| 59 | 
            -
                  end
         | 
| 60 | 
            -
                  
         | 
| 61 | 
            -
                  def textile_editor_support
         | 
| 62 | 
            -
                    output = []
         | 
| 63 | 
            -
                    output << stylesheet_link_tag('textile-editor') 
         | 
| 64 | 
            -
                    output << javascript_include_tag('textile-editor')
         | 
| 65 | 
            -
                    output.join("\n").html_safe
         | 
| 66 | 
            -
                  end
         | 
| 67 | 
            -
                  
         | 
| 68 | 
            -
                  # registers a new button for the Textile Editor toolbar
         | 
| 69 | 
            -
                  # Parameters:
         | 
| 70 | 
            -
                  #   * +text+: text to display (contents of button tag, so HTML is valid as well)
         | 
| 71 | 
            -
                  #   * +options+: options Hash as supported by +content_tag+ helper in Rails
         | 
| 72 | 
            -
                  # 
         | 
| 73 | 
            -
                  # Example:
         | 
| 74 | 
            -
                  #   The following example adds a button labeled 'Greeting' which triggers an
         | 
| 75 | 
            -
                  #   alert:
         | 
| 76 | 
            -
                  # 
         | 
| 77 | 
            -
                  #   <% textile_editor_button 'Greeting', :onclick => "alert('Hello!')" %> 
         | 
| 78 | 
            -
                  #
         | 
| 79 | 
            -
                  # *Note*: this method must be called before +textile_editor_initialize+
         | 
| 80 | 
            -
                  def textile_editor_button(text, options={})
         | 
| 81 | 
            -
                    return textile_editor_button_separator  if text == :separator
         | 
| 82 | 
            -
                    button = content_tag(:button, text, options)
         | 
| 83 | 
            -
                    button = "TextileEditor.buttons.push(\"%s\");" % escape_javascript(button)
         | 
| 84 | 
            -
                    (@textile_editor_buttons ||= []) << button
         | 
| 85 | 
            -
                  end
         | 
| 86 | 
            -
             | 
| 87 | 
            -
                  def textile_editor_button_separator(options={})
         | 
| 88 | 
            -
                    button = "TextileEditor.buttons.push(new TextileEditorButtonSeparator('%s'));" % (options[:simple] || '')
         | 
| 89 | 
            -
                    (@textile_editor_buttons ||= []) << button
         | 
| 90 | 
            -
                  end
         | 
| 4 | 
            +
            require_relative 'helpers/textile_editor_initialize'
         | 
| 5 | 
            +
            require_relative 'helpers/default'
         | 
| 91 6 |  | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
                  end
         | 
| 98 | 
            -
                  
         | 
| 99 | 
            -
                  # adds the necessary javascript include tags, stylesheet tags,
         | 
| 100 | 
            -
                  # and load event with necessary javascript to active textile editor(s)
         | 
| 101 | 
            -
                  # sample output:
         | 
| 102 | 
            -
                  #    <link href="/stylesheets/textile-editor.css" media="screen" rel="stylesheet" type="text/css" />
         | 
| 103 | 
            -
                  #    <script src="/javascripts/textile-editor.js" type="text/javascript"></script>
         | 
| 104 | 
            -
                  #    <script type="text/javascript">
         | 
| 105 | 
            -
                  #    document.observe('dom:loaded', function() {
         | 
| 106 | 
            -
                  #    TextileEditor.initialize('article_body', 'extended');
         | 
| 107 | 
            -
                  #    TextileEditor.initialize('article_body_excerpt', 'simple');
         | 
| 108 | 
            -
                  #    });
         | 
| 109 | 
            -
                  #    </script>  
         | 
| 110 | 
            -
                  # 
         | 
| 111 | 
            -
                  # Note: in the case of this helper being called via AJAX, the output will be reduced:
         | 
| 112 | 
            -
                  #    <script type="text/javascript">
         | 
| 113 | 
            -
                  #    TextileEditor.initialize('article_body', 'extended');
         | 
| 114 | 
            -
                  #    TextileEditor.initialize('article_body_excerpt', 'simple');
         | 
| 115 | 
            -
                  #    </script>  
         | 
| 116 | 
            -
                  # 
         | 
| 117 | 
            -
                  # This means that the support files must be loaded outside of the AJAX request, either
         | 
| 118 | 
            -
                  # via a call to this helper or the textile_editor_support() helper
         | 
| 119 | 
            -
                  def textile_editor_initialize(*dom_ids)
         | 
| 120 | 
            -
                    options = textile_editor_options.dup
         | 
| 121 | 
            -
             | 
| 122 | 
            -
                    # extract options from last argument if it's a hash
         | 
| 123 | 
            -
                    if dom_ids.last.is_a?(Hash)
         | 
| 124 | 
            -
                      hash = dom_ids.last.dup
         | 
| 125 | 
            -
                      options.merge! hash
         | 
| 126 | 
            -
                      dom_ids.last.delete :framework
         | 
| 127 | 
            -
                      dom_ids.last.delete :preview
         | 
| 128 | 
            -
                    end
         | 
| 129 | 
            -
             | 
| 130 | 
            -
                    editor_ids = (@textile_editor_ids || []) + textile_extract_dom_ids(*dom_ids)
         | 
| 131 | 
            -
                    editor_buttons = (@textile_editor_buttons || [])
         | 
| 132 | 
            -
                    output = []
         | 
| 133 | 
            -
                    output << textile_editor_support unless request.xhr?
         | 
| 134 | 
            -
                    output << '<script type="text/javascript">'
         | 
| 135 | 
            -
                    output << '/* <![CDATA[ */'
         | 
| 136 | 
            -
                    
         | 
| 137 | 
            -
                    if !request.xhr?
         | 
| 138 | 
            -
                       output << %{$(document).ready(function() \{}
         | 
| 139 | 
            -
                    end      
         | 
| 140 | 
            -
             | 
| 141 | 
            -
                    output << editor_buttons.join("\n") if editor_buttons.any?
         | 
| 142 | 
            -
                    editor_ids.each do |editor_id, mode|
         | 
| 143 | 
            -
                     
         | 
| 144 | 
            -
                    output << %q{TextileEditor.initialize('%s', '%s');} % [editor_id, mode || 'extended']					
         | 
| 145 | 
            -
             | 
| 146 | 
            -
            					
         | 
| 147 | 
            -
            					output << %q{ $("#%s").keyup(function() {
         | 
| 148 | 
            -
            						 var textile_string = $("#%s").val(); 
         | 
| 149 | 
            -
            						 if($("#%s_destination")[0]) { 
         | 
| 7 | 
            +
            begin
         | 
| 8 | 
            +
              require 'simple_form'
         | 
| 9 | 
            +
              require_relative 'helpers/simple_form'
         | 
| 10 | 
            +
            rescue LoadError
         | 
| 11 | 
            +
            end
         | 
| 150 12 |  | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 153 | 
            -
             | 
| 154 | 
            -
             | 
| 155 | 
            -
             | 
| 156 | 
            -
            		
         | 
| 157 | 
            -
            					
         | 
| 158 | 
            -
                    end
         | 
| 159 | 
            -
                    output << '});' unless request.xhr?
         | 
| 13 | 
            +
            begin
         | 
| 14 | 
            +
              require 'formtastic'
         | 
| 15 | 
            +
              require_relative 'helpers/formtastic'
         | 
| 16 | 
            +
            rescue LoadError
         | 
| 17 | 
            +
            end
         | 
| 160 18 |  | 
| 161 | 
            -
             | 
| 162 | 
            -
             | 
| 163 | 
            -
                    output.join("\n").html_safe
         | 
| 164 | 
            -
                  end
         | 
| 165 | 
            -
                end
         | 
| 166 | 
            -
                
         | 
| 167 | 
            -
                module FormTagHelper
         | 
| 168 | 
            -
                  # Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions 
         | 
| 169 | 
            -
                  # and includes the textile toolbar above it.
         | 
| 170 | 
            -
                  # 
         | 
| 171 | 
            -
                  # ==== Options
         | 
| 172 | 
            -
                  # * <tt>:size</tt> - A string specifying the dimensions (columns by rows) of the textarea (e.g., "25x10").
         | 
| 173 | 
            -
                  # * <tt>:rows</tt> - Specify the number of rows in the textarea
         | 
| 174 | 
            -
                  # * <tt>:cols</tt> - Specify the number of columns in the textarea
         | 
| 175 | 
            -
                  # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
         | 
| 176 | 
            -
                  # * Any other key creates standard HTML attributes for the tag.
         | 
| 177 | 
            -
                  #
         | 
| 178 | 
            -
                  # ==== Examples
         | 
| 179 | 
            -
                  #   textile_editor_tag 'post'
         | 
| 180 | 
            -
                  #   # => <textarea id="post" name="post"></textarea>
         | 
| 181 | 
            -
                  #
         | 
| 182 | 
            -
                  #   textile_editor_tag 'bio', @user.bio
         | 
| 183 | 
            -
                  #   # => <textarea id="bio" name="bio">This is my biography.</textarea>
         | 
| 184 | 
            -
                  #
         | 
| 185 | 
            -
                  #   textile_editor_tag 'body', nil, :rows => 10, :cols => 25
         | 
| 186 | 
            -
                  #   # => <textarea cols="25" id="body" name="body" rows="10"></textarea>
         | 
| 187 | 
            -
                  #
         | 
| 188 | 
            -
                  #   textile_editor_tag 'body', nil, :size => "25x10"
         | 
| 189 | 
            -
                  #   # => <textarea name="body" id="body" cols="25" rows="10"></textarea>
         | 
| 190 | 
            -
                  #
         | 
| 191 | 
            -
                  #   textile_editor_tag 'description', "Description goes here.", :disabled => true
         | 
| 192 | 
            -
                  #   # => <textarea disabled="disabled" id="description" name="description">Description goes here.</textarea>
         | 
| 193 | 
            -
                  #
         | 
| 194 | 
            -
                  #   textile_editor_tag 'comment', nil, :class => 'comment_input'
         | 
| 195 | 
            -
                  #   # => <textarea class="comment_input" id="comment" name="comment"></textarea>
         | 
| 196 | 
            -
                  def textile_editor_tag(name, content = nil, options = {})
         | 
| 197 | 
            -
                    editor_id = options[:id] || name
         | 
| 198 | 
            -
                    mode      = options.delete(:simple) ? 'simple' : 'extended'
         | 
| 199 | 
            -
                    (@textile_editor_ids ||= []) << [editor_id.to_s, mode.to_s]
         | 
| 200 | 
            -
                    
         | 
| 201 | 
            -
                    text_area_tag(name, content, options)
         | 
| 202 | 
            -
                  end
         | 
| 203 | 
            -
                end
         | 
| 204 | 
            -
                
         | 
| 205 | 
            -
              end
         | 
| 206 | 
            -
            end
         | 
| 19 | 
            +
            module TextileEditorHelper
         | 
| 20 | 
            +
            end
         | 
    
        data/test/abstract_unit.rb
    CHANGED
    
    | @@ -1,16 +1,23 @@ | |
| 1 1 | 
             
            $:.unshift(File.dirname(__FILE__) + '/../lib')
         | 
| 2 2 |  | 
| 3 3 | 
             
            require 'yaml'
         | 
| 4 | 
            -
            require 'test/unit'
         | 
| 5 4 | 
             
            require 'rubygems'
         | 
| 6 5 |  | 
| 7 6 | 
             
            require 'action_controller'
         | 
| 8 | 
            -
            require ' | 
| 9 | 
            -
            require ' | 
| 7 | 
            +
            require 'action_view/helpers'
         | 
| 8 | 
            +
            require 'action_view/asset_paths'
         | 
| 9 | 
            +
            require 'action_controller/test_case'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            require 'simple_form'
         | 
| 10 12 |  | 
| 11 13 | 
             
            # Show backtraces for deprecated behavior for quicker cleanup.
         | 
| 12 14 | 
             
            ActiveSupport::Deprecation.debug = true
         | 
| 13 15 |  | 
| 14 16 | 
             
            ActionController::Base.logger = nil
         | 
| 17 | 
            +
             | 
| 15 18 | 
             
            # ActionController::Base.ignore_missing_templates = false
         | 
| 16 | 
            -
            ActionController::Routing::Routes.reload rescue nil
         | 
| 19 | 
            +
            ActionController::Routing::Routes.reload rescue nil
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ActionController::Base.asset_host = "localhost"
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            require_relative 'support_methods'
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require_relative 'test_helper'
         | 
| 2 | 
            +
            require_relative '../lib/helpers/formtastic'
         | 
| 3 | 
            +
            require_relative '../lib/helpers/textile_editor_initialize'
         | 
| 4 | 
            +
            require_relative 'abstract_unit'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            class FormtasticTest  < MiniTest::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              include SimpleForm::ActionViewExtensions::FormHelper
         | 
| 9 | 
            +
              include SimpleForm::Inputs
         | 
| 10 | 
            +
              include SupportMethods
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def expected_initialize_output
         | 
| 13 | 
            +
                TextileEditorInitialize.textile_editor_initialize
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              def test_textile_editor_initialize_formtastic
         | 
| 17 | 
            +
                actual = textile_editor_initialize()
         | 
| 18 | 
            +
                assert_equal expected_initialize_output, actual
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require_relative 'test_helper'
         | 
| 2 | 
            +
            require_relative '../lib/helpers/simple_form'
         | 
| 3 | 
            +
            require_relative 'abstract_unit'
         | 
| 4 | 
            +
            require_relative '../lib/helpers/textile_editor_initialize'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            class SimpleFormTest  < MiniTest::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              include SimpleForm::ActionViewExtensions::FormHelper
         | 
| 9 | 
            +
              include SimpleForm::Inputs
         | 
| 10 | 
            +
              include SupportMethods
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def expected_initialize_output
         | 
| 13 | 
            +
                TextileEditorInitialize.textile_editor_initialize
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              def test_textile_editor_initialize_simple_form
         | 
| 17 | 
            +
                actual = textile_editor_initialize()
         | 
| 18 | 
            +
                assert_equal expected_initialize_output, actual
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,54 @@ | |
| 1 | 
            +
            module SupportMethods
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              def setup
         | 
| 4 | 
            +
                @controller = Class.new do
         | 
| 5 | 
            +
                  attr_reader :url_for_options
         | 
| 6 | 
            +
                  def url_for(options, *parameters_for_method_reference)
         | 
| 7 | 
            +
                    @url_for_options = options
         | 
| 8 | 
            +
                    "http://www.example.com"
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def request;  @request  ||= ActionController::TestRequest.new;  end
         | 
| 12 | 
            +
                  def response; @response ||= ActionController::TestResponse.new; end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
                @controller = @controller.new
         | 
| 15 | 
            +
                @article = OpenStruct.new(:body => nil)
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def request
         | 
| 19 | 
            +
                @controller.request
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              def controller
         | 
| 23 | 
            +
                setup
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              def config
         | 
| 27 | 
            +
                Class.new do
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  class << self
         | 
| 30 | 
            +
                    def perform_caching
         | 
| 31 | 
            +
                      true
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    def asset_path
         | 
| 35 | 
            +
                      @asset_path
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    def assets_dir
         | 
| 39 | 
            +
                      ""
         | 
| 40 | 
            +
                    end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                    def relative_url_root
         | 
| 43 | 
            +
                      nil
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    def asset_host
         | 
| 47 | 
            +
                      nil
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            end
         | 
    
        data/test/test_helper.rb
    ADDED
    
    
| @@ -1,195 +1,53 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 1 | 
            +
            require_relative 'test_helper'
         | 
| 2 | 
            +
            require_relative 'abstract_unit'
         | 
| 3 | 
            +
            require_relative '../lib/helpers/default'
         | 
| 4 | 
            +
            require_relative '../lib/helpers/textile_editor_initialize'
         | 
| 3 5 | 
             
            require 'ostruct'
         | 
| 4 6 |  | 
| 5 | 
            -
            class TextileEditorHelperTest | 
| 7 | 
            +
            class TextileEditorHelperTest  < MiniTest::Unit::TestCase
         | 
| 8 | 
            +
             | 
| 6 9 | 
             
              include ActionView::Helpers::TextHelper
         | 
| 7 10 | 
             
              include ActionView::Helpers::AssetTagHelper
         | 
| 8 11 | 
             
              include ActionView::Helpers::TagHelper
         | 
| 9 12 | 
             
              include ActionView::Helpers::FormHelper
         | 
| 10 13 | 
             
              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 14 |  | 
| 38 | 
            -
               | 
| 39 | 
            -
                output = textile_editor(object, field, options)
         | 
| 40 | 
            -
                assert_equal  text_area(object, field, options), output
         | 
| 41 | 
            -
              end  
         | 
| 15 | 
            +
              include SupportMethods
         | 
| 42 16 |  | 
| 43 | 
            -
              def  | 
| 44 | 
            -
                 | 
| 45 | 
            -
                 | 
| 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 | 
            -
                }
         | 
| 17 | 
            +
              def create_editor(object, field, options={})
         | 
| 18 | 
            +
                output = textile_editor(object, field, options)
         | 
| 19 | 
            +
                assert_equal  text_area(object, field, options.merge(:class => "textile_editor")), output
         | 
| 66 20 | 
             
              end
         | 
| 67 | 
            -
             | 
| 68 | 
            -
              def expected_initialize_output | 
| 69 | 
            -
                 | 
| 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
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              def expected_initialize_output
         | 
| 23 | 
            +
                TextileEditorInitialize.textile_editor_initialize
         | 
| 76 24 | 
             
              end
         | 
| 77 | 
            -
             | 
| 78 | 
            -
              #  | 
| 25 | 
            +
             | 
| 26 | 
            +
              # Tests
         | 
| 79 27 | 
             
              def test_textile_editor
         | 
| 80 | 
            -
                 | 
| 81 | 
            -
                 | 
| 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
         | 
| 28 | 
            +
                create_editor('article', 'body')
         | 
| 29 | 
            +
                assert_includes textile_editor('article', 'body'), "textile_editor"
         | 
| 89 30 | 
             
              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 31 |  | 
| 117 | 
            -
             | 
| 118 | 
            -
                 | 
| 119 | 
            -
                  ['article_body', 'extended'],
         | 
| 120 | 
            -
                  ['article_body_excerpt', 'simple']
         | 
| 121 | 
            -
                ]), output
         | 
| 122 | 
            -
                
         | 
| 123 | 
            -
                # test using custom default options
         | 
| 124 | 
            -
                textile_editor_options :framework => :jquery
         | 
| 32 | 
            +
              def test_textile_editor_initialize
         | 
| 33 | 
            +
                create_editor('article', 'body')
         | 
| 125 34 | 
             
                output = textile_editor_initialize()
         | 
| 126 | 
            -
                assert_equal expected_initialize_output | 
| 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
         | 
| 35 | 
            +
                assert_equal expected_initialize_output, output
         | 
| 138 36 | 
             
              end
         | 
| 139 37 |  | 
| 140 38 | 
             
              def test_textile_editor_initialize_with_custom_buttons
         | 
| 141 | 
            -
                b = '<button id="test_button"  | 
| 142 | 
            -
                button_data = ["TextileEditor.buttons.push( | 
| 39 | 
            +
                b = '<button id="test_button" title="Hello world">Hello</button>'
         | 
| 40 | 
            +
                button_data = ["TextileEditor.buttons.push(""#{b}"");" ]
         | 
| 143 41 | 
             
                actual = textile_editor_button('Hello',
         | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 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
         | 
| 42 | 
            +
                                               :id => 'test_button',
         | 
| 43 | 
            +
                                               :title => 'Hello world'
         | 
| 44 | 
            +
                                              )
         | 
| 157 45 |  | 
| 158 | 
            -
             | 
| 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
         | 
| 46 | 
            +
                assert_equal button_data, actual
         | 
| 167 47 |  | 
| 168 | 
            -
             | 
| 169 | 
            -
                 | 
| 170 | 
            -
                assert_equal  | 
| 48 | 
            +
                create_editor('article', 'body')
         | 
| 49 | 
            +
                output = textile_editor_initialize()
         | 
| 50 | 
            +
                assert_equal expected_initialize_output, output
         | 
| 171 51 | 
             
              end
         | 
| 172 52 |  | 
| 173 | 
            -
             | 
| 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
         | 
| 53 | 
            +
            end
         | 
| @@ -2,26 +2,25 @@ | |
| 2 2 | 
             
            require File.expand_path('../lib/textile_editor_helper/version', __FILE__)
         | 
| 3 3 |  | 
| 4 4 | 
             
            Gem::Specification.new do |gem|
         | 
| 5 | 
            -
              gem.authors       = [ | 
| 6 | 
            -
              gem.email         = [ | 
| 5 | 
            +
              gem.authors       = ['Katherine']
         | 
| 6 | 
            +
              gem.email         = ['info@bridgeutopiaweb.com']
         | 
| 7 7 | 
             
              gem.description   = %q{Textile Editor Helper is a gem for Ruby on Rails 3.2 > to add a Textile toolbar above textareas.}
         | 
| 8 8 | 
             
              gem.summary       = %q{Textile Editor Helper}
         | 
| 9 | 
            -
              gem.homepage      =  | 
| 9 | 
            +
              gem.homepage      = 'https://github.com/bridgeutopia/textile_editor_helper'
         | 
| 10 10 |  | 
| 11 | 
            -
              gem.executables   =  | 
| 12 | 
            -
              gem.files | 
| 11 | 
            +
              gem.executables   = Dir["bin/*"].map { |f| File.basename(f) }
         | 
| 12 | 
            +
              gem.files = `git ls-files`.strip.split("\n")
         | 
| 13 13 | 
             
              gem.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 14 | 
            -
              gem.name          =  | 
| 15 | 
            -
              gem.require_paths = [ | 
| 14 | 
            +
              gem.name          = 'textile_editor_helper'
         | 
| 15 | 
            +
              gem.require_paths = ['lib']
         | 
| 16 16 | 
             
              gem.version       = TextileEditorHelper::VERSION
         | 
| 17 | 
            -
             | 
| 17 | 
            +
             | 
| 18 18 | 
             
              #dependencies
         | 
| 19 19 | 
             
              gem.add_development_dependency 'rails', '>= 3.2.0'
         | 
| 20 | 
            -
              gem.add_development_dependency  | 
| 21 | 
            -
              gem. | 
| 22 | 
            -
              gem. | 
| 23 | 
            -
              gem.add_development_dependency  | 
| 24 | 
            -
              gem.add_development_dependency  | 
| 25 | 
            -
              gem.add_development_dependency  | 
| 26 | 
            -
              gem.add_development_dependency "rspec", ">= 2.0.0"
         | 
| 20 | 
            +
              gem.add_development_dependency 'simple_form'
         | 
| 21 | 
            +
              gem.add_development_dependency 'formtastic'
         | 
| 22 | 
            +
              gem.add_development_dependency 'thor'
         | 
| 23 | 
            +
              gem.add_development_dependency 'minitest'
         | 
| 24 | 
            +
              gem.add_development_dependency 'cucumber'
         | 
| 25 | 
            +
              gem.add_development_dependency 'rspec'
         | 
| 27 26 | 
             
            end
         | 
    
        data/travis.yml
    CHANGED
    
    | 
            File without changes
         |