smiley 0.0.1 → 0.1.0
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.
- checksums.yaml +7 -0
- data/Gemfile +2 -5
- data/Gemfile.lock +20 -13
- data/README.md +91 -0
- data/lib/smiley.rb +83 -18
- data/spec/smiley_spec.rb +121 -30
- data/spec/spec_helper.rb +6 -0
- metadata +44 -68
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 2e53eb3600742e6708e0987d6954b862148881b3
         | 
| 4 | 
            +
              data.tar.gz: b8d7c96b8f6f06bd42e27fc2da96fd7f436e2a59
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 54597c0a81fc9a507d34c775e95a794915599a6b7c32d0423ed98dd4331809220670a8e60866b72abc28608f02135e358ed29b2696bb6a63d5044111a9193e75
         | 
| 7 | 
            +
              data.tar.gz: 7cb39ed9a5dddb841ec5ed71ee6aaf14feca8ab9036dec878cd6ed9c3a5a4496dfa4a3dd7c7e899a839761cc90261717bca3cb96e0323aa4961be98e85690143
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,20 +1,27 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: .
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                smiley (0.1.0)
         | 
| 5 | 
            +
             | 
| 1 6 | 
             
            GEM
         | 
| 2 | 
            -
              remote:  | 
| 7 | 
            +
              remote: https://rubygems.org/
         | 
| 3 8 | 
             
              specs:
         | 
| 4 | 
            -
                diff-lcs (1.1 | 
| 5 | 
            -
                rake (0. | 
| 6 | 
            -
                rspec (2. | 
| 7 | 
            -
                  rspec-core (~> 2. | 
| 8 | 
            -
                  rspec-expectations (~> 2. | 
| 9 | 
            -
                  rspec-mocks (~> 2. | 
| 10 | 
            -
                rspec-core (2. | 
| 11 | 
            -
                rspec-expectations (2. | 
| 12 | 
            -
                  diff-lcs ( | 
| 13 | 
            -
                rspec-mocks (2. | 
| 9 | 
            +
                diff-lcs (1.2.1)
         | 
| 10 | 
            +
                rake (10.0.4)
         | 
| 11 | 
            +
                rspec (2.13.0)
         | 
| 12 | 
            +
                  rspec-core (~> 2.13.0)
         | 
| 13 | 
            +
                  rspec-expectations (~> 2.13.0)
         | 
| 14 | 
            +
                  rspec-mocks (~> 2.13.0)
         | 
| 15 | 
            +
                rspec-core (2.13.1)
         | 
| 16 | 
            +
                rspec-expectations (2.13.0)
         | 
| 17 | 
            +
                  diff-lcs (>= 1.1.3, < 2.0)
         | 
| 18 | 
            +
                rspec-mocks (2.13.0)
         | 
| 14 19 |  | 
| 15 20 | 
             
            PLATFORMS
         | 
| 21 | 
            +
              java
         | 
| 16 22 | 
             
              ruby
         | 
| 17 23 |  | 
| 18 24 | 
             
            DEPENDENCIES
         | 
| 19 | 
            -
              rake
         | 
| 20 | 
            -
              rspec
         | 
| 25 | 
            +
              rake (~> 10.0)
         | 
| 26 | 
            +
              rspec (~> 2.13.0)
         | 
| 27 | 
            +
              smiley!
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,91 @@ | |
| 1 | 
            +
            [](https://codeclimate.com/github/iGEL/smiley) 
         | 
| 2 | 
            +
            [](https://travis-ci.org/iGEL/smiley) 
         | 
| 3 | 
            +
            (Tested: Ruby 2.0.0, 1.9.3, 1.9.2, 1.8.7, Rubinius, Jruby)
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Smiley
         | 
| 6 | 
            +
            ======
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            This is a small library to pass text emoticons like into cute smiley images your users will like. To be more accurate,
         | 
| 9 | 
            +
            this lib will parse them into `<em class="smiley smiley-grin></em>`, which you can style with css to show the smiley
         | 
| 10 | 
            +
            image. This way, you can use [CSS sprites](http://css-tricks.com/css-sprites/) to make them load faster.
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            Usage
         | 
| 13 | 
            +
            =====
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            First, configure the smileys you want to have converted in a yml file. If you use this lib with Ruby on Rails, the 
         | 
| 16 | 
            +
            default position for this file is in `config/smileys.yml`.
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            ```yml
         | 
| 19 | 
            +
            cool:
         | 
| 20 | 
            +
              tokens: ':cool: 8-) 8)'
         | 
| 21 | 
            +
            cry:
         | 
| 22 | 
            +
              tokens: ":'( ;( :'-(" # HTML escaped, since we work in the escaped form
         | 
| 23 | 
            +
            grin:
         | 
| 24 | 
            +
              tokens: ':-D :D'
         | 
| 25 | 
            +
            ```
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            You can configure multiple forms for the same smiley. In this example, `:cool:`, `8-)` and `8)` will all produce
         | 
| 28 | 
            +
            the same smiley.
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            Next, pass your string through `smiley`. If you're inside of Rails, `smiley` will escape html unsafe Strings and
         | 
| 31 | 
            +
            mark the result as html safe. Remember to do it yourself if you use the lib outside of Rails.
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            Helper:
         | 
| 34 | 
            +
            ```ruby
         | 
| 35 | 
            +
            def smileys(str)
         | 
| 36 | 
            +
              Smiley.new.parse(str)
         | 
| 37 | 
            +
            end
         | 
| 38 | 
            +
            ```
         | 
| 39 | 
            +
            Haml:
         | 
| 40 | 
            +
            ```haml
         | 
| 41 | 
            +
            .post
         | 
| 42 | 
            +
              = smileys("Wow, they're alive :cool: :D")
         | 
| 43 | 
            +
            ```
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            The last step is to setup the CSS, so the images will be displayed.
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            SCSS:
         | 
| 48 | 
            +
            ```scss
         | 
| 49 | 
            +
            .smiley { // All smileys have this class
         | 
| 50 | 
            +
              display: inline-block;
         | 
| 51 | 
            +
              width: 15px;
         | 
| 52 | 
            +
              height: 15px;
         | 
| 53 | 
            +
              background: image-url('smileys/sprite.png');
         | 
| 54 | 
            +
            }
         | 
| 55 | 
            +
            .smiley-cool {
         | 
| 56 | 
            +
              background: image-url('smileys/cool.gif'); // animated
         | 
| 57 | 
            +
            }
         | 
| 58 | 
            +
            .smiley-cry {
         | 
| 59 | 
            +
              background-position: 0 0;
         | 
| 60 | 
            +
            }
         | 
| 61 | 
            +
            .smiley-grin {
         | 
| 62 | 
            +
              width: 20px;
         | 
| 63 | 
            +
              background-position: 0 -15px;
         | 
| 64 | 
            +
            }
         | 
| 65 | 
            +
            ```
         | 
| 66 | 
            +
             | 
| 67 | 
            +
            Configuration
         | 
| 68 | 
            +
            =============
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            So far, `smiley` has these configuration options:
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            ```ruby
         | 
| 73 | 
            +
            # The prefix for the CSS class, e.g. smiley in smiley-grin, defaults to smiley
         | 
| 74 | 
            +
            Smiley.each_class_prefix = 'icons'
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            # The CSS class that is added to all smileys, defaults to smiley
         | 
| 77 | 
            +
            Smiley.all_class = 'emoji'
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            # defaults to :dashed, meaning class names like smiley-big-grin
         | 
| 80 | 
            +
            # :camel-case will generate class names like smileyBigGrin, :snake_case like smiley_big_grin
         | 
| 81 | 
            +
            Smiley.css_class_style = :camel_case
         | 
| 82 | 
            +
             | 
| 83 | 
            +
            # YAML file with the smiley definition. Default in Rails is config/smileys.yml
         | 
| 84 | 
            +
            # No default if not used with Rails
         | 
| 85 | 
            +
            Smiley.smiley_file = 'data/smileys.yml'
         | 
| 86 | 
            +
            ```
         | 
| 87 | 
            +
             | 
| 88 | 
            +
            License
         | 
| 89 | 
            +
            =======
         | 
| 90 | 
            +
             | 
| 91 | 
            +
            MIT (see `MIT-LICENSE`)
         | 
    
        data/lib/smiley.rb
    CHANGED
    
    | @@ -1,37 +1,102 @@ | |
| 1 1 | 
             
            require 'yaml'
         | 
| 2 2 |  | 
| 3 3 | 
             
            class Smiley
         | 
| 4 | 
            +
              VALID_CSS_CLASS_STYLES = [:dashed, :snake_case, :camel_case]
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def self.all_class
         | 
| 7 | 
            +
                defined?(@@all_class) ? @@all_class : 'smiley'
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              def self.all_class=(klass)
         | 
| 11 | 
            +
                @@all_class = klass
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def self.each_class_prefix
         | 
| 15 | 
            +
                defined?(@@each_class_prefix) ? @@each_class_prefix : 'smiley'
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def self.each_class_prefix=(klass)
         | 
| 19 | 
            +
                @@each_class_prefix = klass
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 4 22 | 
             
              def self.smiley_file=(file)
         | 
| 5 23 | 
             
                @@smiley_file = file
         | 
| 6 24 | 
             
              end
         | 
| 7 25 |  | 
| 26 | 
            +
              def self.css_class_style
         | 
| 27 | 
            +
                defined?(@@css_class_style) ? @@css_class_style : :dashed
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              def self.css_class_style=(style)
         | 
| 31 | 
            +
                unless VALID_CSS_CLASS_STYLES.include?(style.to_sym)
         | 
| 32 | 
            +
                  raise "Invalid css class style #{style}. You can choose between :dashed, :snake_case and :camel_case"
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
                @@css_class_style = style.to_sym
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 8 37 | 
             
              def self.smiley_file
         | 
| 9 | 
            -
                 | 
| 10 | 
            -
             | 
| 11 | 
            -
                 | 
| 38 | 
            +
                if defined?(@@smiley_file)
         | 
| 39 | 
            +
                  return @@smiley_file
         | 
| 40 | 
            +
                elsif defined?(Rails) && Rails.respond_to?(:root)
         | 
| 41 | 
            +
                  return File.join(Rails.root, 'config', 'smileys.yml')
         | 
| 42 | 
            +
                end
         | 
| 12 43 | 
             
              end
         | 
| 13 44 |  | 
| 14 45 | 
             
              def parse(text)
         | 
| 15 | 
            -
                 | 
| 16 | 
            -
             | 
| 17 | 
            -
                text.gsub(@@regex) do
         | 
| 18 | 
            -
                  %(#{$1}<em class="smiley smiley-#{@@smileys[$2].downcase}"></em>#{$3})
         | 
| 46 | 
            +
                text = h(text).gsub(self.class.regex) do
         | 
| 47 | 
            +
                  %(#{$1}<em class="#{css_class(self.class.smileys[$2])}"></em>#{$3})
         | 
| 19 48 | 
             
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                text.respond_to?(:html_safe) ? text.html_safe : text
         | 
| 20 51 | 
             
              end
         | 
| 21 52 |  | 
| 22 53 | 
             
              private
         | 
| 23 | 
            -
              def  | 
| 24 | 
            -
                 | 
| 25 | 
            -
                   | 
| 26 | 
            -
             | 
| 27 | 
            -
                   | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 54 | 
            +
              def h(str)
         | 
| 55 | 
            +
                if defined?(ERB::Utils) && ERB::Utils.respond_to?(:html_escape)
         | 
| 56 | 
            +
                  ERB::Utils.html_escape(str).to_str
         | 
| 57 | 
            +
                else
         | 
| 58 | 
            +
                  str.to_str
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              def css_class(smiley)
         | 
| 63 | 
            +
                out = "#{self.class.all_class} #{self.class.each_class_prefix}-#{smiley}"
         | 
| 64 | 
            +
                case self.class.css_class_style
         | 
| 65 | 
            +
                when :camel_case
         | 
| 66 | 
            +
                  camelize(out)
         | 
| 67 | 
            +
                when :snake_case
         | 
| 68 | 
            +
                  underscore(out)
         | 
| 69 | 
            +
                else
         | 
| 70 | 
            +
                  out
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
              def camelize(str)
         | 
| 75 | 
            +
                str.gsub(/-([a-z])/) { $1.upcase }
         | 
| 76 | 
            +
              end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
              def underscore(str)
         | 
| 79 | 
            +
                str.gsub('-', '_')
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              def self.smileys
         | 
| 83 | 
            +
                return @@smileys if  defined?(@@smileys)
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                @@smileys = {}
         | 
| 86 | 
            +
                YAML.load(File.read(Smiley.smiley_file)).each do |smiley, options|
         | 
| 87 | 
            +
                  options['tokens'].split(/\s+/).each do |token|
         | 
| 88 | 
            +
                    @@smileys[token] = smiley
         | 
| 32 89 | 
             
                  end
         | 
| 33 | 
            -
                  before_and_after = "[.,;:!\\?\\(\\[\\{\\)\\]\\}\\-]|\\s"
         | 
| 34 | 
            -
                  @@regex = Regexp.compile "(^|#{before_and_after})(" + @@regex.join("|") + ")(#{before_and_after}|$)"
         | 
| 35 90 | 
             
                end
         | 
| 91 | 
            +
                @@smileys
         | 
| 92 | 
            +
              end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
              def self.regex
         | 
| 95 | 
            +
                return @@regex if defined?(@@regex)
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                before_and_after = "[.,;:!\\?\\(\\[\\{\\)\\]\\}\\-]|\\s"
         | 
| 98 | 
            +
                @@regex = Regexp.compile("(^|#{before_and_after})(" +
         | 
| 99 | 
            +
                        smileys.keys.map { |token| Regexp.escape(token) }.join("|") +
         | 
| 100 | 
            +
                        ")($|#{before_and_after})", Regexp::MULTILINE)
         | 
| 36 101 | 
             
              end
         | 
| 37 102 | 
             
            end
         | 
    
        data/spec/smiley_spec.rb
    CHANGED
    
    | @@ -2,66 +2,157 @@ require 'spec_helper' | |
| 2 2 | 
             
            require 'smiley'
         | 
| 3 3 |  | 
| 4 4 | 
             
            describe Smiley do
         | 
| 5 | 
            -
               | 
| 5 | 
            +
              subject(:smiley) { described_class.new }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
             | 
| 8 | 
            +
              after do
         | 
| 9 | 
            +
                described_class.class_eval do
         | 
| 10 | 
            +
                  remove_class_variable :@@all_class if class_variable_defined?(:@@all_class)
         | 
| 11 | 
            +
                  remove_class_variable :@@each_class_prefix if class_variable_defined?(:@@each_class_prefix)
         | 
| 12 | 
            +
                  remove_class_variable :@@css_class_style if class_variable_defined?(:@@css_class_style)
         | 
| 13 | 
            +
                  remove_class_variable :@@smiley_file if class_variable_defined?(:@@smiley_file)
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              describe '.all_class' do
         | 
| 6 18 | 
             
                before do
         | 
| 7 | 
            -
                   | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 19 | 
            +
                  described_class.smiley_file = File.join(File.dirname(__FILE__), "smileys.yml")
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                it 'defaults to smiley' do
         | 
| 23 | 
            +
                  expect(described_class.all_class).to eq('smiley')
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                it 'returns the configured value' do
         | 
| 27 | 
            +
                  described_class.all_class = 'funnyIcon'
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  expect(described_class.all_class).to eq('funnyIcon')
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              describe '.each_class_prefix' do
         | 
| 34 | 
            +
                it 'defaults to smiley' do
         | 
| 35 | 
            +
                  expect(described_class.each_class_prefix).to eq('smiley')
         | 
| 10 36 | 
             
                end
         | 
| 11 37 |  | 
| 12 | 
            -
                 | 
| 13 | 
            -
                   | 
| 38 | 
            +
                it 'returns the configured value' do
         | 
| 39 | 
            +
                  described_class.each_class_prefix = 'funnyIcon'
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  expect(described_class.each_class_prefix).to eq('funnyIcon')
         | 
| 14 42 | 
             
                end
         | 
| 43 | 
            +
              end
         | 
| 15 44 |  | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 45 | 
            +
              describe '.smiley_file' do
         | 
| 46 | 
            +
                it 'returns the configured value' do
         | 
| 47 | 
            +
                  described_class.smiley_file = '/etc/smileys.yml'
         | 
| 18 48 |  | 
| 19 | 
            -
                   | 
| 49 | 
            +
                  expect(described_class.smiley_file).to eq('/etc/smileys.yml')
         | 
| 20 50 | 
             
                end
         | 
| 21 51 |  | 
| 22 | 
            -
                it  | 
| 23 | 
            -
                   | 
| 52 | 
            +
                it 'returns nil, if not configured' do
         | 
| 53 | 
            +
                  expect(described_class.smiley_file).to be_nil
         | 
| 24 54 | 
             
                end
         | 
| 25 55 |  | 
| 26 | 
            -
                it  | 
| 27 | 
            -
                   | 
| 28 | 
            -
                  Rails | 
| 56 | 
            +
                it 'return \#{Rails.root}/config/smileys.yml, if Rails.root is defined"' do
         | 
| 57 | 
            +
                  rails = double('Rails')
         | 
| 58 | 
            +
                  stub_const('Rails', rails)
         | 
| 59 | 
            +
                  rails.stub(:root) { '/home/igel/dev/example.com/' }
         | 
| 29 60 |  | 
| 30 | 
            -
                   | 
| 61 | 
            +
                  expect(described_class.smiley_file).to eq('/home/igel/dev/example.com/config/smileys.yml')
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              describe '.css_class_style' do
         | 
| 66 | 
            +
                it 'defaults to dashed' do
         | 
| 67 | 
            +
                  expect(described_class.css_class_style).to eq(:dashed)
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                it 'returns :snake_case if configured' do
         | 
| 71 | 
            +
                  described_class.css_class_style = :snake_case
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  expect(described_class.css_class_style).to eq(:snake_case)
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                it 'returns :camel_case if configured' do
         | 
| 77 | 
            +
                  described_class.css_class_style = :camel_case
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  expect(described_class.css_class_style).to eq(:camel_case)
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                it 'raises an error if an invalid value is given' do
         | 
| 83 | 
            +
                  expect { described_class.css_class_style = :strike_through }.to raise_error
         | 
| 31 84 | 
             
                end
         | 
| 32 85 | 
             
              end
         | 
| 33 86 |  | 
| 34 87 | 
             
              describe '#parse' do
         | 
| 35 88 | 
             
                before do
         | 
| 36 | 
            -
                   | 
| 89 | 
            +
                  described_class.smiley_file = File.join(File.dirname(__FILE__), 'smileys.yml')
         | 
| 37 90 | 
             
                end
         | 
| 38 91 |  | 
| 39 | 
            -
                it  | 
| 40 | 
            -
                   | 
| 92 | 
            +
                it 'parses a smiley' do
         | 
| 93 | 
            +
                  expect(smiley.parse('That is so funny! :-) Will tell my grandma about that!')).to eq('That is so funny! <em class="smiley smiley-smile"></em> Will tell my grandma about that!')
         | 
| 41 94 | 
             
                end
         | 
| 42 95 |  | 
| 43 | 
            -
                it  | 
| 44 | 
            -
                   | 
| 96 | 
            +
                it 'works with alternative forms' do
         | 
| 97 | 
            +
                  expect(smiley.parse("That's so funny! :P Will tell my grandma about that :rolleyes: ")).to eq(%(That's so funny! <em class="smiley smiley-razz"></em> Will tell my grandma about that <em class="smiley smiley-rolleyes"></em> ))
         | 
| 45 98 | 
             
                end
         | 
| 46 99 |  | 
| 47 | 
            -
                it  | 
| 48 | 
            -
                   | 
| 100 | 
            +
                it 'parses smileys at the beginning and end of a string' do
         | 
| 101 | 
            +
                  expect(smiley.parse(':D So funny! ;-)')).to eq(%(<em class="smiley smiley-grin"></em> So funny! <em class="smiley smiley-wink"></em>))
         | 
| 49 102 | 
             
                end
         | 
| 50 103 |  | 
| 51 | 
            -
                it  | 
| 52 | 
            -
                   | 
| 104 | 
            +
                it 'parses smileys at the beginning and end of a line' do
         | 
| 105 | 
            +
                  expect(smiley.parse("\n:D So funny! ;-)\n")).to eq(%(\n<em class="smiley smiley-grin"></em> So funny! <em class="smiley smiley-wink"></em>\n))
         | 
| 53 106 | 
             
                end
         | 
| 54 107 |  | 
| 55 | 
            -
                it  | 
| 56 | 
            -
                   | 
| 108 | 
            +
                it 'parses smileys after and before a comma, a dot, a question or exclamation mark, a semicolon, a colon, or a dash' do
         | 
| 109 | 
            +
                  expect(smiley.parse("before: ,;-) .:-) ?:-) !;-) ;:D ::rolleyes: -:P\nafter: ;-), :-). :-)? ;-)! :D; :rolleyes:: :P-")).to eq(%(before: ,<em class="smiley smiley-wink"></em> .<em class="smiley smiley-smile"></em> ?<em class="smiley smiley-smile"></em> !<em class="smiley smiley-wink"></em> ;<em class="smiley smiley-grin"></em> :<em class="smiley smiley-rolleyes"></em> -<em class="smiley smiley-razz"></em>\nafter: <em class="smiley smiley-wink"></em>, <em class="smiley smiley-smile"></em>. <em class="smiley smiley-smile"></em>? <em class="smiley smiley-wink"></em>! <em class="smiley smiley-grin"></em>; <em class="smiley smiley-rolleyes"></em>: <em class="smiley smiley-razz"></em>-))
         | 
| 57 110 | 
             
                end
         | 
| 58 111 |  | 
| 59 | 
            -
                it  | 
| 60 | 
            -
                   | 
| 112 | 
            +
                it 'parses smileys after and before round, box or curly brackets' do
         | 
| 113 | 
            +
                  expect(smiley.parse(' (:-)) [:-)] {:-)} ')).to eq(' (<em class="smiley smiley-smile"></em>) [<em class="smiley smiley-smile"></em>] {<em class="smiley smiley-smile"></em>} ')
         | 
| 114 | 
            +
                end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                it "doesn't parse smileys directly before or after a word" do
         | 
| 117 | 
            +
                  expect(smiley.parse(' :-)word:-) ')).to eq(' :-)word:-) ')
         | 
| 118 | 
            +
                end
         | 
| 119 | 
            +
             | 
| 120 | 
            +
                it 'uses the configured all_class and each_class_prefix' do
         | 
| 121 | 
            +
                  described_class.all_class = 'funny-icon'
         | 
| 122 | 
            +
                  described_class.each_class_prefix = 'smiley-image'
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                  expect(smiley.parse(':-)')).to eq('<em class="funny-icon smiley-image-smile"></em>')
         | 
| 61 125 | 
             
                end
         | 
| 62 126 |  | 
| 63 | 
            -
                it  | 
| 64 | 
            -
                   | 
| 127 | 
            +
                it 'uses snake_case for the CSS class if configured' do
         | 
| 128 | 
            +
                  described_class.css_class_style = :snake_case
         | 
| 129 | 
            +
                  described_class.all_class = 'funny_icon'
         | 
| 130 | 
            +
                  described_class.each_class_prefix = 'smiley_image'
         | 
| 131 | 
            +
             | 
| 132 | 
            +
                  expect(smiley.parse(':-)')).to eq('<em class="funny_icon smiley_image_smile"></em>')
         | 
| 133 | 
            +
                end
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                it 'uses CamelCase for the CSS class if configured' do
         | 
| 136 | 
            +
                  described_class.css_class_style = :camel_case
         | 
| 137 | 
            +
                  described_class.all_class = 'funnyIcon'
         | 
| 138 | 
            +
                  described_class.each_class_prefix = 'smileyImage'
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                  expect(smiley.parse(':-)')).to eq('<em class="funnyIcon smileyImageSmile"></em>')
         | 
| 141 | 
            +
                end
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                it 'uses ERB::Utils.html_escape if available' do
         | 
| 144 | 
            +
                  erb_utils = double('ERB::Utils')
         | 
| 145 | 
            +
                  stub_const('ERB::Utils', erb_utils)
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                  erb_utils.should_receive(:html_escape).with('<script>alert("Hacked!")</script>').and_return('<script>alert("Hacked!")</script>')
         | 
| 148 | 
            +
                  
         | 
| 149 | 
            +
                  smiley.parse('<script>alert("Hacked!")</script>')
         | 
| 150 | 
            +
                end
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                it 'marks the String as HTML safe, if that method is available' do
         | 
| 153 | 
            +
                  String.any_instance.should_receive(:html_safe)
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                  smiley.parse(':-)')
         | 
| 65 156 | 
             
                end
         | 
| 66 157 | 
             
              end
         | 
| 67 158 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,62 +1,50 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: smiley
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version | 
| 4 | 
            -
               | 
| 5 | 
            -
              prerelease: 
         | 
| 6 | 
            -
              segments: 
         | 
| 7 | 
            -
              - 0
         | 
| 8 | 
            -
              - 0
         | 
| 9 | 
            -
              - 1
         | 
| 10 | 
            -
              version: 0.0.1
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 11 5 | 
             
            platform: ruby
         | 
| 12 | 
            -
            authors: | 
| 6 | 
            +
            authors:
         | 
| 13 7 | 
             
            - Johannes Barre
         | 
| 14 8 | 
             
            autorequire: 
         | 
| 15 9 | 
             
            bindir: bin
         | 
| 16 10 | 
             
            cert_chain: []
         | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
            - !ruby/object:Gem::Dependency 
         | 
| 11 | 
            +
            date: 2013-03-30 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 21 14 | 
             
              name: rake
         | 
| 22 | 
            -
               | 
| 23 | 
            -
             | 
| 24 | 
            -
                none: false
         | 
| 25 | 
            -
                requirements: 
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 26 17 | 
             
                - - ~>
         | 
| 27 | 
            -
                  - !ruby/object:Gem::Version | 
| 28 | 
            -
                     | 
| 29 | 
            -
                    segments: 
         | 
| 30 | 
            -
                    - 0
         | 
| 31 | 
            -
                    - 9
         | 
| 32 | 
            -
                    version: "0.9"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '10.0'
         | 
| 33 20 | 
             
              type: :development
         | 
| 34 | 
            -
              version_requirements: *id001
         | 
| 35 | 
            -
            - !ruby/object:Gem::Dependency 
         | 
| 36 | 
            -
              name: rspec
         | 
| 37 21 | 
             
              prerelease: false
         | 
| 38 | 
            -
               | 
| 39 | 
            -
                 | 
| 40 | 
            -
                 | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ~>
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '10.0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rspec
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 41 31 | 
             
                - - ~>
         | 
| 42 | 
            -
                  - !ruby/object:Gem::Version | 
| 43 | 
            -
                     | 
| 44 | 
            -
                    segments: 
         | 
| 45 | 
            -
                    - 2
         | 
| 46 | 
            -
                    - 10
         | 
| 47 | 
            -
                    - 0
         | 
| 48 | 
            -
                    version: 2.10.0
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: 2.13.0
         | 
| 49 34 | 
             
              type: :development
         | 
| 50 | 
            -
               | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ~>
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: 2.13.0
         | 
| 51 41 | 
             
            description: 
         | 
| 52 42 | 
             
            email: igel@igels.net
         | 
| 53 43 | 
             
            executables: []
         | 
| 54 | 
            -
             | 
| 55 44 | 
             
            extensions: []
         | 
| 56 | 
            -
             | 
| 57 45 | 
             
            extra_rdoc_files: []
         | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 46 | 
            +
            files:
         | 
| 47 | 
            +
            - README.md
         | 
| 60 48 | 
             
            - MIT-LICENSE
         | 
| 61 49 | 
             
            - Rakefile
         | 
| 62 50 | 
             
            - Gemfile
         | 
| @@ -66,39 +54,27 @@ files: | |
| 66 54 | 
             
            - spec/spec_helper.rb
         | 
| 67 55 | 
             
            homepage: https://github.com/igel/smiley
         | 
| 68 56 | 
             
            licenses: []
         | 
| 69 | 
            -
             | 
| 57 | 
            +
            metadata: {}
         | 
| 70 58 | 
             
            post_install_message: 
         | 
| 71 59 | 
             
            rdoc_options: []
         | 
| 72 | 
            -
             | 
| 73 | 
            -
            require_paths: 
         | 
| 60 | 
            +
            require_paths:
         | 
| 74 61 | 
             
            - lib
         | 
| 75 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement | 
| 76 | 
            -
               | 
| 77 | 
            -
               | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 85 | 
            -
              none: false
         | 
| 86 | 
            -
              requirements: 
         | 
| 87 | 
            -
              - - ">="
         | 
| 88 | 
            -
                - !ruby/object:Gem::Version 
         | 
| 89 | 
            -
                  hash: 23
         | 
| 90 | 
            -
                  segments: 
         | 
| 91 | 
            -
                  - 1
         | 
| 92 | 
            -
                  - 3
         | 
| 93 | 
            -
                  - 6
         | 
| 62 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 63 | 
            +
              requirements:
         | 
| 64 | 
            +
              - - '>='
         | 
| 65 | 
            +
                - !ruby/object:Gem::Version
         | 
| 66 | 
            +
                  version: '0'
         | 
| 67 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 68 | 
            +
              requirements:
         | 
| 69 | 
            +
              - - '>='
         | 
| 70 | 
            +
                - !ruby/object:Gem::Version
         | 
| 94 71 | 
             
                  version: 1.3.6
         | 
| 95 72 | 
             
            requirements: []
         | 
| 96 | 
            -
             | 
| 97 73 | 
             
            rubyforge_project: 
         | 
| 98 | 
            -
            rubygems_version:  | 
| 74 | 
            +
            rubygems_version: 2.0.0.rc.2
         | 
| 99 75 | 
             
            signing_key: 
         | 
| 100 | 
            -
            specification_version:  | 
| 76 | 
            +
            specification_version: 4
         | 
| 101 77 | 
             
            summary: A small lib to parse smileys. Use CSS to display them!
         | 
| 102 | 
            -
            test_files: | 
| 78 | 
            +
            test_files:
         | 
| 103 79 | 
             
            - spec/smiley_spec.rb
         | 
| 104 80 | 
             
            - spec/spec_helper.rb
         |