translighterate 0.0.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8193c5a842a9d40a6bf6a94d80f2d7f24df87cc
4
- data.tar.gz: aab40fb8c8a1149e36b5da2e93be0eef2217ead1
3
+ metadata.gz: db4370d7bb61f58ce95b79a8551bc5170a575207
4
+ data.tar.gz: d322eee9e0245d64f4ac4398fe2890e2dc6dfb9c
5
5
  SHA512:
6
- metadata.gz: a351519c1f9dae18f20eebe59946f376e4a3de8f2d74c4e96f8a88deab728bd9183a99a5a5757f3090159348e876bd7bc62ec416e8b00e93f974f802a024ae0c
7
- data.tar.gz: 62b4f5680ff0fd6f609fae9ed9c8ce2450459127ca2092cbf0d0949e53c2ce72274f027a961fe079d5cf455e03f35976ebbdb839d357c5daebd5e4456860d0aa
6
+ metadata.gz: 46f026bdcdfc91e5a939ac527fbd502f832cb89e4a4f768ad4ace6578db8eecf7110c2d58d7e9cf28603eb4152ff7e561d3b7cea2ad9c211da802e992cc8b5fd
7
+ data.tar.gz: d32220fb84ef787126a40e23be718f2d235c44cdbe4bf4eb102846467be9f25bb401af63226a7fce18cdf7b89aecbc4e2bea1b2d18385c3a9d4d36db064131fc
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in translighterate.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jeremy Fleischman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # Translighterate
2
+
3
+ (Created after getting no responses to this [Stack Overflow question](http://stackoverflow.com/questions/34166987/rails-gem-for-transliterate-highlight).)
4
+
5
+ This is a version of Rails's [highlight](http://apidock.com/rails/ActionView/Helpers/TextHelper/highlight) that is transliteration aware.
6
+
7
+ For example, highlighting 'duss' in 'Düsseldorf' will actually match something:
8
+
9
+ ```ruby
10
+ irb(main):001:0> require 'translighterate'
11
+ => true
12
+ irb(main):002:0> Translighterate::highlight("Düsseldorf", "duss")
13
+ => "<mark>Düss</mark>eldorf"
14
+ ```
15
+
16
+ as opposed to this behavior with Rails's [highlight](http://apidock.com/rails/ActionView/Helpers/TextHelper/highlight):
17
+
18
+ ```ruby
19
+ irb(main):002:0> require 'action_view'
20
+ => true
21
+ irb(main):004:0> include ActionView::Helpers::TextHelper
22
+ => Object
23
+ irb(main):005:0> highlight("Düsseldorf", "duss")
24
+ => "Düsseldorf"
25
+ ```
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'translighterate'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install translighterate
42
+
43
+ ## Usage
44
+
45
+ We have one class `Translighterate` with one method `highlight`.
46
+
47
+ ```ruby
48
+ irb(main):001:0> require 'translighterate'
49
+ => true
50
+ irb(main):002:0> Translighterate::highlight("Düsseldorf", "duss")
51
+ => "<mark>Düss</mark>eldorf"
52
+ ```
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ### Testing
61
+
62
+ `bin/rspec` to run the tests.
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jfly/translighterate.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "translighterate"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rspec ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,7 +1,10 @@
1
+ require "translighterate/version"
1
2
  require 'action_view'
2
3
  include ActionView::Helpers::TextHelper
3
4
 
4
- class Translighterate
5
+ module Translighterate
6
+ # Copied (and modified!) from
7
+ # https://github.com/rails/rails/blob/495ef4124e292dcc7062e3e1f04f623053113101/actionview/lib/action_view/helpers/text_helper.rb#L130
5
8
  def self.highlight(text, phrases, options = {})
6
9
  text = sanitize(text) if options.fetch(:sanitize, true)
7
10
 
@@ -15,15 +18,25 @@ class Translighterate
15
18
  # Transliteration trick from:
16
19
  # https://github.com/cubing/worldcubeassociation.org/issues/238#issuecomment-234702800
17
20
  transliterated = text.mb_chars.normalize(:kd).gsub(/[\p{Mn}]/,'').to_s
18
- transliterated.gsub(/(#{match})(?![^<]*?>)/i) do |found|
19
- original_text_found = text[Range.new(*$~.offset(0), true)]
20
- if block_given?
21
- yield original_text_found
22
- else
23
- highlighter = options.fetch(:highlighter, '<mark>\1</mark>')
24
- highlighter.gsub(/\\1/, original_text_found)
25
- end
21
+ transliterated = transliterated.gsub "ł", "l"
22
+ transliterated = transliterated.gsub "Ł", "L"
23
+
24
+ previous_match_end_index = 0
25
+ result = ""
26
+ transliterated.scan(/(#{match})(?![^<]*?>)/i) do
27
+ match_range = $~.offset(0)
28
+ result += text[previous_match_end_index...match_range[0]]
29
+ original_text_found = text[Range.new(*match_range, true)]
30
+ previous_match_end_index = match_range[1]
31
+
32
+ result += if block_given?
33
+ yield original_text_found
34
+ else
35
+ highlighter = options.fetch(:highlighter, '<mark>\1</mark>')
36
+ highlighter.gsub(/\\1/, original_text_found)
37
+ end
26
38
  end
39
+ result += text[previous_match_end_index..-1]
27
40
  end.html_safe
28
41
  end
29
42
  end
@@ -0,0 +1,3 @@
1
+ module Translighterate
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "translighterate/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "translighterate"
8
+ spec.version = Translighterate::VERSION
9
+ spec.authors = ["Jeremy Fleischman"]
10
+ spec.email = ["jeremyfleischman@gmail.com"]
11
+
12
+ spec.summary = "A version of Rails's highlight that is transliteration aware."
13
+ spec.description = "For example, highlighting 'duss' in 'Düsseldorf' will actually match something."
14
+ spec.homepage = "https://github.com/jfly/translighterate"
15
+
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "actionview", ">= 4.0", "< 6.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.15"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "byebug", "~> 9.0"
31
+ end
metadata CHANGED
@@ -1,79 +1,112 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translighterate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Fleischman
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-04 00:00:00.000000000 Z
11
+ date: 2017-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '4.2'
22
+ version: '6.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
23
36
  requirements:
24
37
  - - "~>"
25
38
  - !ruby/object:Gem::Version
26
- version: '4.2'
39
+ version: '1.15'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.15'
27
47
  - !ruby/object:Gem::Dependency
28
- name: rspec
48
+ name: rake
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
51
  - - "~>"
32
52
  - !ruby/object:Gem::Version
33
- version: '3.5'
53
+ version: '10.0'
34
54
  type: :development
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
37
57
  requirements:
38
58
  - - "~>"
39
59
  - !ruby/object:Gem::Version
40
- version: '3.5'
60
+ version: '10.0'
41
61
  - !ruby/object:Gem::Dependency
42
- name: byebug
62
+ name: rspec
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '9.0'
67
+ version: '3.0'
48
68
  type: :development
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '9.0'
74
+ version: '3.0'
55
75
  - !ruby/object:Gem::Dependency
56
- name: rake
76
+ name: byebug
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
79
  - - "~>"
60
80
  - !ruby/object:Gem::Version
61
- version: '11.2'
81
+ version: '9.0'
62
82
  type: :development
63
83
  prerelease: false
64
84
  version_requirements: !ruby/object:Gem::Requirement
65
85
  requirements:
66
86
  - - "~>"
67
87
  - !ruby/object:Gem::Version
68
- version: '11.2'
88
+ version: '9.0'
69
89
  description: For example, highlighting 'duss' in 'Düsseldorf' will actually match
70
90
  something.
71
- email: jeremyfleischman@gmail.com
91
+ email:
92
+ - jeremyfleischman@gmail.com
72
93
  executables: []
73
94
  extensions: []
74
95
  extra_rdoc_files: []
75
96
  files:
97
+ - ".gitignore"
98
+ - ".rspec"
99
+ - ".travis.yml"
100
+ - Gemfile
101
+ - LICENSE.txt
102
+ - README.md
103
+ - Rakefile
104
+ - bin/console
105
+ - bin/rspec
106
+ - bin/setup
76
107
  - lib/translighterate.rb
108
+ - lib/translighterate/version.rb
109
+ - translighterate.gemspec
77
110
  homepage: https://github.com/jfly/translighterate
78
111
  licenses:
79
112
  - MIT
@@ -94,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
127
  version: '0'
95
128
  requirements: []
96
129
  rubyforge_project:
97
- rubygems_version: 2.5.1
130
+ rubygems_version: 2.6.13
98
131
  signing_key:
99
132
  specification_version: 4
100
133
  summary: A version of Rails's highlight that is transliteration aware.