access_kit 0.03 → 0.04
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.
| 
         @@ -1,13 +1,19 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module AccessKit
         
     | 
| 
       2 
2 
     | 
    
         
             
              module UrlHelperAdditions
         
     | 
| 
       3 
3 
     | 
    
         
             
                extend ActiveSupport::Concern 
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
                mattr_accessor :css_class
         
     | 
| 
      
 5 
     | 
    
         
            +
                
         
     | 
| 
       5 
6 
     | 
    
         
             
                class << self
         
     | 
| 
       6 
7 
     | 
    
         
             
                  DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT = :intro
         
     | 
| 
       7 
8 
     | 
    
         
             
                  DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT = :outro
         
     | 
| 
      
 9 
     | 
    
         
            +
                  DEFAULT_CSS_CLASS_FOR_SUPPLEMENT    = "access_kit"
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
11 
     | 
    
         
             
                  def add_supplement_to_text(text, opts={})        
         
     | 
| 
       10 
     | 
    
         
            -
                    default_opts = {DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT => nil,  
     | 
| 
      
 12 
     | 
    
         
            +
                    default_opts = {  DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT => nil, 
         
     | 
| 
      
 13 
     | 
    
         
            +
                                      DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT => nil, 
         
     | 
| 
      
 14 
     | 
    
         
            +
                                      :auto_pad => true, 
         
     | 
| 
      
 15 
     | 
    
         
            +
                                      :css_class_for_supplement => css_class_for_supplement
         
     | 
| 
      
 16 
     | 
    
         
            +
                    }
         
     | 
| 
       11 
17 
     | 
    
         
             
                    opts = default_opts.merge(opts)
         
     | 
| 
       12 
18 
     | 
    
         | 
| 
       13 
19 
     | 
    
         
             
                    padding = begin
         
     | 
| 
         @@ -19,15 +25,10 @@ module AccessKit 
     | 
|
| 
       19 
25 
     | 
    
         
             
                        opts[:auto_pad].to_s
         
     | 
| 
       20 
26 
     | 
    
         
             
                      end        
         
     | 
| 
       21 
27 
     | 
    
         
             
                    end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                    before_span = opts[DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT] 
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                      
         
     | 
| 
       27 
     | 
    
         
            -
                    after_span  = opts[DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT].blank?  ? 
         
     | 
| 
       28 
     | 
    
         
            -
                      "" : 
         
     | 
| 
       29 
     | 
    
         
            -
                      span_tag(padding + opts[DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT])
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
                    
         
     | 
| 
      
 29 
     | 
    
         
            +
                    before_span = span_tag opts[DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT], :padding_after => padding, :class => opts[:css_class_for_supplement]
         
     | 
| 
      
 30 
     | 
    
         
            +
                    after_span  = span_tag opts[DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT], :padding_before => padding, :class => opts[:css_class_for_supplement]
         
     | 
| 
      
 31 
     | 
    
         
            +
                    
         
     | 
| 
       31 
32 
     | 
    
         
             
                    "#{before_span}#{text}#{after_span}".html_safe
         
     | 
| 
       32 
33 
     | 
    
         
             
                  end
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
         @@ -42,7 +43,7 @@ module AccessKit 
     | 
|
| 
       42 
43 
     | 
    
         
             
                  def process_options_for_link_to_with_supplement(*args)
         
     | 
| 
       43 
44 
     | 
    
         
             
                    if args_for_link_to_with_supplement?(*args)
         
     | 
| 
       44 
45 
     | 
    
         
             
                      # TODO: move to separate method: 'extract_supplement_opts'
         
     | 
| 
       45 
     | 
    
         
            -
                      supplement_opts = [ DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT, DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT, :auto_pad ].inject({}) do |memo, k|
         
     | 
| 
      
 46 
     | 
    
         
            +
                      supplement_opts = [ DEFAULT_KEY_NAME_FOR_PRECEDING_TEXT, DEFAULT_KEY_NAME_FOR_FOLLOWING_TEXT, :auto_pad, :css_class_for_supplement ].inject({}) do |memo, k|
         
     | 
| 
       46 
47 
     | 
    
         
             
                        value = args[2].delete(k)
         
     | 
| 
       47 
48 
     | 
    
         
             
                        value.blank? ? memo : memo.merge( k => value )
         
     | 
| 
       48 
49 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -58,8 +59,22 @@ module AccessKit 
     | 
|
| 
       58 
59 
     | 
    
         | 
| 
       59 
60 
     | 
    
         
             
                  private 
         
     | 
| 
       60 
61 
     | 
    
         
             
                    # TODO: use Rails content_tag if available
         
     | 
| 
       61 
     | 
    
         
            -
                    def span_tag(content)
         
     | 
| 
       62 
     | 
    
         
            -
                      " 
     | 
| 
      
 62 
     | 
    
         
            +
                    def span_tag(content, opts={} )
         
     | 
| 
      
 63 
     | 
    
         
            +
                      default_opts = {:padding_before => '', :padding_after => '', :class => ""}
         
     | 
| 
      
 64 
     | 
    
         
            +
                      opts = default_opts.merge(opts)
         
     | 
| 
      
 65 
     | 
    
         
            +
                      
         
     | 
| 
      
 66 
     | 
    
         
            +
                      if content.blank?
         
     | 
| 
      
 67 
     | 
    
         
            +
                        ""
         
     | 
| 
      
 68 
     | 
    
         
            +
                      else
         
     | 
| 
      
 69 
     | 
    
         
            +
                        class_str = opts[:class].blank? ? 
         
     | 
| 
      
 70 
     | 
    
         
            +
                          "" :
         
     | 
| 
      
 71 
     | 
    
         
            +
                          ' class="' + opts[:class] + '"'
         
     | 
| 
      
 72 
     | 
    
         
            +
                        "<span#{class_str}>#{opts[:padding_before]}#{content}#{opts[:padding_after]}</span>"
         
     | 
| 
      
 73 
     | 
    
         
            +
                      end
         
     | 
| 
      
 74 
     | 
    
         
            +
                    end
         
     | 
| 
      
 75 
     | 
    
         
            +
                    
         
     | 
| 
      
 76 
     | 
    
         
            +
                    def css_class_for_supplement
         
     | 
| 
      
 77 
     | 
    
         
            +
                      self.css_class || DEFAULT_CSS_CLASS_FOR_SUPPLEMENT
         
     | 
| 
       63 
78 
     | 
    
         
             
                    end
         
     | 
| 
       64 
79 
     | 
    
         
             
                end
         
     | 
| 
       65 
80 
     | 
    
         
             
              end
         
     | 
    
        data/lib/access_kit/version.rb
    CHANGED
    
    
| 
         @@ -1,74 +1,99 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module AccessKit
         
     | 
| 
       4 
     | 
    
         
            -
              describe UrlHelperAdditions do 
     | 
| 
       5 
     | 
    
         
            -
                 
     | 
| 
      
 4 
     | 
    
         
            +
              describe UrlHelperAdditions do  
         
     | 
| 
      
 5 
     | 
    
         
            +
                describe "#link_to_with_supplement" do    
         
     | 
| 
      
 6 
     | 
    
         
            +
                  let(:args){  [ "unicorns", 
         
     | 
| 
      
 7 
     | 
    
         
            +
                                  '#unicorns', 
         
     | 
| 
      
 8 
     | 
    
         
            +
                                  { :intro => "Click to learn about" }
         
     | 
| 
      
 9 
     | 
    
         
            +
                                ]        
         
     | 
| 
      
 10 
     | 
    
         
            +
                  }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       6 
12 
     | 
    
         
             
                  include ActionView::Helpers::TagHelper
         
     | 
| 
       7 
13 
     | 
    
         
             
                  include ActionView::Helpers::UrlHelper
         
     | 
| 
       8 
14 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
                   
     | 
| 
       10 
     | 
    
         
            -
                     
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                       
     | 
| 
       13 
     | 
    
         
            -
                      :intro => "Click to learn about"
         
     | 
| 
       14 
     | 
    
         
            -
                    ).should == "<a href=\"#unicorns\"><span>Click to learn about </span>unicorns</a>"
         
     | 
| 
       15 
     | 
    
         
            -
                  end
         
     | 
| 
       16 
     | 
    
         
            -
                  
         
     | 
| 
       17 
     | 
    
         
            -
                  context "#args_for_link_to_with_supplement?" do
         
     | 
| 
       18 
     | 
    
         
            -
                    context "should return true if :intro or :outro options are passed" do
         
     | 
| 
       19 
     | 
    
         
            -
                      UrlHelperAdditions.args_for_link_to_with_supplement?(
         
     | 
| 
       20 
     | 
    
         
            -
                        "unicorns", 
         
     | 
| 
       21 
     | 
    
         
            -
                        '#unicorns', 
         
     | 
| 
       22 
     | 
    
         
            -
                        :intro => "Click to learn about"
         
     | 
| 
       23 
     | 
    
         
            -
                      ).should == true
         
     | 
| 
      
 15 
     | 
    
         
            +
                  context "without a css class for supplementary text" do
         
     | 
| 
      
 16 
     | 
    
         
            +
                    # this is to keep the expected output shorter and easier to read
         
     | 
| 
      
 17 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 18 
     | 
    
         
            +
                      ::AccessKit::UrlHelperAdditions.css_class = ""
         
     | 
| 
       24 
19 
     | 
    
         
             
                    end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                    it "should  
     | 
| 
       27 
     | 
    
         
            -
                       
     | 
| 
       28 
     | 
    
         
            -
                        "unicorns", 
         
     | 
| 
       29 
     | 
    
         
            -
                        '#unicorns'
         
     | 
| 
       30 
     | 
    
         
            -
                      ).should == false
         
     | 
| 
      
 20 
     | 
    
         
            +
                    
         
     | 
| 
      
 21 
     | 
    
         
            +
                    it "should extend link_to" do
         
     | 
| 
      
 22 
     | 
    
         
            +
                      link_to(*args).should == "<a href=\"#unicorns\"><span>Click to learn about </span>unicorns</a>"
         
     | 
| 
       31 
23 
     | 
    
         
             
                    end
         
     | 
| 
      
 24 
     | 
    
         
            +
                  
         
     | 
| 
      
 25 
     | 
    
         
            +
                    describe "#args_for_link_to_with_supplement?" do        
         
     | 
| 
      
 26 
     | 
    
         
            +
                      it "should return true if :intro or :outro options are passed" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                        UrlHelperAdditions.args_for_link_to_with_supplement?(*args).should == true
         
     | 
| 
      
 28 
     | 
    
         
            +
                      end
         
     | 
| 
      
 29 
     | 
    
         
            +
                          
         
     | 
| 
      
 30 
     | 
    
         
            +
                      it "should return false if neither :intro nor :outro options are passed" do  
         
     | 
| 
      
 31 
     | 
    
         
            +
                        UrlHelperAdditions.args_for_link_to_with_supplement?("unicorns", '#unicorns').should == false
         
     | 
| 
      
 32 
     | 
    
         
            +
                      end
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                       
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                        &some_block
         
     | 
| 
       39 
     | 
    
         
            -
                      ).should == false          
         
     | 
| 
      
 34 
     | 
    
         
            +
                      # TODO: why not allow blocks to be passed?
         
     | 
| 
      
 35 
     | 
    
         
            +
                      it "should return false if a block is given" do
         
     | 
| 
      
 36 
     | 
    
         
            +
                        some_block = lambda{ 'link_name' }
         
     | 
| 
      
 37 
     | 
    
         
            +
                        UrlHelperAdditions.args_for_link_to_with_supplement?(args, &some_block).should == false          
         
     | 
| 
      
 38 
     | 
    
         
            +
                      end
         
     | 
| 
       40 
39 
     | 
    
         
             
                    end
         
     | 
| 
       41 
     | 
    
         
            -
                  end
         
     | 
| 
       42 
40 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                           
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                                      '#unicorns', 
         
     | 
| 
       53 
     | 
    
         
            -
                                      { :class => 'mythical' }
         
     | 
| 
       54 
     | 
    
         
            -
                        ]
         
     | 
| 
      
 41 
     | 
    
         
            +
                    describe "#process_options_for_link_to_with_supplement" do
         
     | 
| 
      
 42 
     | 
    
         
            +
                      context "args_for_link_to_with_supplement? is true" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                        it "should return hash with new name" do
         
     | 
| 
      
 44 
     | 
    
         
            +
                          args.last[:class] = 'mythical'
         
     | 
| 
      
 45 
     | 
    
         
            +
                          UrlHelperAdditions.process_options_for_link_to_with_supplement(*args).should == 
         
     | 
| 
      
 46 
     | 
    
         
            +
                            [ "<span>Click to learn about </span>unicorns",
         
     | 
| 
      
 47 
     | 
    
         
            +
                              '#unicorns', 
         
     | 
| 
      
 48 
     | 
    
         
            +
                              { :class => 'mythical' }
         
     | 
| 
      
 49 
     | 
    
         
            +
                            ]
         
     | 
| 
       55 
50 
     | 
    
         | 
| 
      
 51 
     | 
    
         
            +
                        end
         
     | 
| 
       56 
52 
     | 
    
         
             
                      end
         
     | 
| 
       57 
     | 
    
         
            -
                    end
         
     | 
| 
       58 
53 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
      
 54 
     | 
    
         
            +
                      context "args_for_link_to_with_supplement? is false" do
         
     | 
| 
      
 55 
     | 
    
         
            +
                        it "should return nil" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                          UrlHelperAdditions.process_options_for_link_to_with_supplement(
         
     | 
| 
      
 57 
     | 
    
         
            +
                            "unicorns", 
         
     | 
| 
      
 58 
     | 
    
         
            +
                            '#unicorns'
         
     | 
| 
      
 59 
     | 
    
         
            +
                          ).should be_nil     
         
     | 
| 
      
 60 
     | 
    
         
            +
                        end
         
     | 
| 
       65 
61 
     | 
    
         
             
                      end
         
     | 
| 
      
 62 
     | 
    
         
            +
                    
         
     | 
| 
      
 63 
     | 
    
         
            +
                    end
         
     | 
| 
      
 64 
     | 
    
         
            +
                  end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                  context "with a css class for supplementary text" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 68 
     | 
    
         
            +
                      # wipe out any custom settings from previous examples
         
     | 
| 
      
 69 
     | 
    
         
            +
                      ::AccessKit::UrlHelperAdditions.css_class = nil
         
     | 
| 
      
 70 
     | 
    
         
            +
                    end        
         
     | 
| 
      
 71 
     | 
    
         
            +
                    it "should use 'access_kit' as the default css class" do
         
     | 
| 
      
 72 
     | 
    
         
            +
                      link_to(*args).should == "<a href=\"#unicorns\"><span class=\"access_kit\">Click to learn about </span>unicorns</a>"
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end      
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                    it "should allow a custom css class to be set" do
         
     | 
| 
      
 76 
     | 
    
         
            +
                      args.last[:css_class_for_supplement] = 'hidden_text for_accessibility'
         
     | 
| 
      
 77 
     | 
    
         
            +
                      link_to(*args).should == "<a href=\"#unicorns\"><span class=\"hidden_text for_accessibility\">Click to learn about </span>unicorns</a>"
         
     | 
| 
       66 
78 
     | 
    
         
             
                    end
         
     | 
| 
       67 
79 
     | 
    
         | 
| 
      
 80 
     | 
    
         
            +
                    it "should allow the default css class to be customized" do
         
     | 
| 
      
 81 
     | 
    
         
            +
                      AccessKit::UrlHelperAdditions.css_class = 'foo'
         
     | 
| 
      
 82 
     | 
    
         
            +
                      link_to(*args).should == "<a href=\"#unicorns\"><span class=\"foo\">Click to learn about </span>unicorns</a>"
         
     | 
| 
      
 83 
     | 
    
         
            +
                    end        
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
       68 
85 
     | 
    
         
             
                  end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
       69 
87 
     | 
    
         
             
                end
         
     | 
| 
       70 
88 
     | 
    
         | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                    
         
     | 
| 
      
 91 
     | 
    
         
            +
                describe "#add_supplement_to_text" do
         
     | 
| 
      
 92 
     | 
    
         
            +
                  # this is to keep the expected output shorter and easier to read
         
     | 
| 
      
 93 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 94 
     | 
    
         
            +
                    ::AccessKit::UrlHelperAdditions.css_class = ""
         
     | 
| 
      
 95 
     | 
    
         
            +
                  end      
         
     | 
| 
      
 96 
     | 
    
         
            +
                  
         
     | 
| 
       72 
97 
     | 
    
         
             
                  it "should add before" do
         
     | 
| 
       73 
98 
     | 
    
         
             
                    UrlHelperAdditions.add_supplement_to_text( 
         
     | 
| 
       74 
99 
     | 
    
         
             
                      "unicorns", 
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,15 +1,16 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: access_kit
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 3
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
     | 
    
         
            -
              -  
     | 
| 
       9 
     | 
    
         
            -
              version: "0. 
     | 
| 
      
 8 
     | 
    
         
            +
              - 4
         
     | 
| 
      
 9 
     | 
    
         
            +
              version: "0.04"
         
     | 
| 
       10 
10 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       11 
11 
     | 
    
         
             
            authors: 
         
     | 
| 
       12 
12 
     | 
    
         
             
            - Mani Tadayon
         
     | 
| 
      
 13 
     | 
    
         
            +
            - Brian Miller
         
     | 
| 
       13 
14 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       14 
15 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       15 
16 
     | 
    
         
             
            cert_chain: []
         
     |