typeright 0.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 13bc4a3b0f0714a4482f760fcefc813e235de5e2
4
+ data.tar.gz: 1a5f7d619d40aed8e7aeca9ead01fca4b4411ab2
5
+ SHA512:
6
+ metadata.gz: 62a4ae93dd82bc5eef065e2f7922dac49aa9c3c65d6dc5d10aef8a2d65150d558425b8e20b40725b5a81151a4e3a741e67f8c79fbbd0fdbee3d2af441da401af
7
+ data.tar.gz: 52f1f89a7e38e986c58ece3b6ebbc99be48f685f20c54ad2d4597ebb9f072ff5a996aff97adb12963bda82fce9c5cab0135c15153c1df7e8e0395b2f8490af77
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+ coverage
3
+ rdoc
4
+ pkg
5
+ .bundle
6
+ Gemfile.lock
7
+ *.gem
8
+ *.log
9
+ doc/
data/.hound.yml ADDED
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ enabled: true
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ env: CI="travis"
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0
6
+ - 2.1
7
+ - 2.2
8
+ - rbx-2
9
+ - ruby-head
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: rbx-2
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'pry'
7
+ gem 'rake'
8
+ gem 'rspec', '>= 3'
9
+ gem 'rubocop'
10
+ gem 'guard'
11
+ gem 'guard-rspec'
12
+ gem 'guard-rubocop'
13
+
14
+ gem 'coveralls', require: false if ENV['CI']
15
+ end
data/Guardfile ADDED
@@ -0,0 +1,22 @@
1
+ # Note: The cmd option is now required due to the increasing number of ways
2
+ # rspec may be run, below are examples of the most common uses.
3
+ # * bundler: 'bundle exec rspec'
4
+ # * bundler binstubs: 'bin/rspec'
5
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
6
+ # installed the spring binstubs per the docs)
7
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
8
+ # * 'just' rspec: 'rspec'
9
+
10
+ # guard :rubocop do
11
+ guard :rubocop, all_on_start: false, keep_failed: false, cli: ['-D'] do
12
+ watch(%r{.+\.rb$})
13
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
14
+ end
15
+
16
+ guard :rspec, cmd: 'bundle exec rspec' do
17
+ watch(%r{^spec/.+_spec\.rb$})
18
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19
+ watch(/^generators\/(.+)\.rb$/) { |_m| 'spec/schemaless/worker_spec' }
20
+
21
+ watch('spec/spec_helper.rb') { 'spec' }
22
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Typeright Authors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a
4
+ copy of this software and associated documentation files (the "Software"),
5
+ to deal in the Software without restriction, including without limitation
6
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the
8
+ Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be
11
+ included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # TypeRight
2
+
3
+ ________________________________________________________________
4
+ ______ ____
5
+ / / ) , /
6
+ ---------/---------------__----__---/___ /--------__---/__--_/_-
7
+ / / / / ) /___) / | / / ) / ) /
8
+ _______/______(___/___/___/_(___ _/_____|__/___(___/_/___/_(_ __
9
+ / / /
10
+ (_ / / (_ /
11
+
12
+
13
+
14
+ Makes text more pleasant for the eyes.
15
+
16
+
17
+ Turns this:
18
+
19
+ ```
20
+ And so... "Why?" -- He replied
21
+ Because -> this! And => this!
22
+ Also, notice some math: Pi + 2 * 180 / 2.
23
+ ```
24
+
25
+ Into this:
26
+
27
+ ```
28
+ And so… “Why?” — He replied.
29
+ Because → It’s cool! And ⇒ I like beautiful text!.
30
+ Also, notice some math: π + 2 × 180 ÷ 2.
31
+ ```
32
+
33
+ ## Install
34
+
35
+ gem install typeright
36
+
37
+
38
+ ## Use
39
+
40
+ Typeright.s(a_text)
41
+
42
+
43
+ ## Todo
44
+
45
+ - Spaces
46
+
47
+ ## Won't Do
48
+
49
+ Non UTF-8 modifications. Eg. `Small Caps`.
50
+
51
+ For that complement with a client-side lib:
52
+
53
+
54
+ Inspiration and thanks
55
+
56
+ https://github.com/davidmerfield/Typeset
57
+
58
+
59
+ ## Also nice
60
+
61
+ http://webtypography.net/
62
+ http://kyleamathews.github.io/typography.js/#/
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new
7
+ RuboCop::RakeTask.new
8
+
9
+ task default: :spec
data/bench/all.rb ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'benchmark'
5
+ require 'typeright'
6
+
7
+ puts
8
+ puts " Typeright! v#{Typeright::VERSION}"
9
+
10
+ N = 100_000
11
+ P1 = "Some 'simple' paragraph -> will be nice to -- see"
12
+ P2 = <<DOC
13
+
14
+ From https://pine.fm/LearnToProgram/
15
+
16
+ I guess this all began back in 2002. I was thinking about teaching programming, and what a great language Ruby would be for learning how to program. I mean, we were all excited about Ruby because it was powerful, elegant, and really just fun, but it seemed to me that it would also be a great way to get into programming in the first place.
17
+
18
+ Unfortunately, there wasn't much Ruby documentation geared for newbies at the time. Some of us in the community were talking about what such a "Ruby for the Nuby" tutorial would need, and more generally, how to teach programming at all. The more I thought about this, the more I had to say (which surprised me a bit). Finally, someone said, "Chris, why don't you just write a tutorial instead of talking about it?" So I did.
19
+
20
+ And it wasn't very good. I had all these ideas that were good in theory, but the actual task of making a great tutorial for non-programmers was vastly more challenging than I had realized. (I mean, it seemed good to me, but I already knew how to program.)
21
+
22
+ What saved me was that I made it really easy for people to contact me, and I always tried to help people when they got stuck. When I saw a lot of people getting stuck in one place, I'd rewrite it. It was a lot of work, but it slowly got better and better.
23
+
24
+ A couple of years later, it was getting pretty good. :-) So good, in fact, that I was ready to pronounce it finished, and move on to something else. And right about then came an opportunity to turn the tutorial into a book. Since it was already basically done, I figured this would be no problem. I'd just clean up a few spots, add some more exercises, maybe some more examples, a few more chapters, run it by 50 more reviewers...
25
+
26
+ It took me another year, but now I think it's really really good, mostly because of the hundreds of brave souls who have helped me write it.
27
+
28
+ DOC
29
+
30
+ Benchmark.bmbm do |b|
31
+ b.report { N.times { Typeright.s(P1) } }
32
+ b.report { N.times { Typeright.s(P2) } }
33
+ end
data/bin/typeright ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'typeright'
5
+
6
+ puts
7
+ puts " Typeright! v#{Typeright::VERSION}"
8
+
9
+ Typeright::CLI.work(ARGV)
@@ -0,0 +1,31 @@
1
+ module Typeright
2
+ # Numbers and symbols replacement
3
+ module Calculator
4
+ class << self
5
+ def work(txt)
6
+ math(arrows(txt))
7
+ end
8
+
9
+ def arrows(txt)
10
+ txt
11
+ .gsub(/(^|\s)\=\>(\W)/, '\1⇒\2')
12
+ .gsub(/(^|\s)-\>(\W)/, '\1→\2')
13
+ .gsub(/(^|\s)\<-(\W)/, '\1←\2')
14
+ .gsub(/(^|\s)\<\=(\W)/, '\1⇐\2')
15
+ .gsub(/(^|\s)\<\<(\w)/, '\1«\2')
16
+ .gsub(/(\w)\>\>(\s|$)/, '\1»\2')
17
+ end
18
+
19
+ # Maybe (1) -> ① ⨉×
20
+ def math(txt)
21
+ txt
22
+ .gsub(/(^|\s)Pi(\W)/, '\1π\2')
23
+ .gsub(/(\d\s)\/(\s\d)/, '\1÷\2')
24
+ .gsub(/(\d\s)\*(\s\d)/, '\1×\2')
25
+ .gsub(/(^|\s)\!\=(\W)/, '\1≠\2')
26
+ .gsub(/(^|\s)\+-(\s)/, '\1±\2')
27
+ .gsub(/(\w)%o(\s|$)/, '\1‰\2')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ # require 'thor'
2
+
3
+ module Typeright
4
+ # Nice cli
5
+ class CLI # < Thor
6
+ def self.work(args)
7
+ txt = args.empty? ? STDIN.gets : File.read(args.join)
8
+ STDOUT.puts
9
+ STDOUT.puts Typeright.s txt
10
+ STDOUT.puts
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module Typeright
2
+ # UTF-8 hyphens -- for everyone
3
+ module Punctuator
4
+ def self.work(txt)
5
+ # Elipses
6
+ txt
7
+ .gsub(/\.{3}/, '…')
8
+ .gsub(/--/, '—')
9
+ .tr('-', '–')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module Typeright
2
+ # Let's "quote"
3
+ module Quotator
4
+ def self.work(txt)
5
+ txt
6
+ .gsub(/(\W|^)"(\w)/, '\1“\2') # beginning "
7
+ .gsub(/(“[^"]*)"([^"]*$|[^“"]*“)/, '\1”\2') # ending "
8
+ .gsub(/([^0-9])"/, '\1”') # remaining " at end of word
9
+ .gsub(/(\W|^)'(\S)/, '\1‘\2') # beginning '
10
+ .gsub(/([a-z])'([a-z])/i, '\1’\2') # conjunction's possession
11
+ .gsub(/((‘[^']*)|[a-z])'([^0-9]|$)/i, '\1’\3') # ending '
12
+ .gsub(/(‘)([0-9]{2}[^’]*)(‘([^0-9]|$)|$|’[a-z])/i, '’\2\3') # abbrev. years like '93
13
+ .gsub(/(\B|^)‘(?=([^’]*’\b)*([^’‘]*\W[’‘]\b|[^’‘]*$))/i, '\1’')
14
+ .gsub(/'''/, '‴') # triple prime
15
+ .gsub(/("|'')/, '″') # double prime
16
+ .tr("'", '′')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ # Typeright version
2
+ module Typeright
3
+ VERSION = '0.0.3'
4
+ end
data/lib/typeright.rb ADDED
@@ -0,0 +1,24 @@
1
+ # require 'pry'
2
+ # require 'yaml'
3
+ require 'typeright/version'
4
+ require 'typeright/cli'
5
+
6
+ # Typeright!
7
+ module Typeright
8
+ # autoload :Hyphenator, 'typeright/hyphenator'
9
+ autoload :Punctuator, 'typeright/punctuator'
10
+ autoload :Quotator, 'typeright/quotator'
11
+ autoload :Calculator, 'typeright/calculator'
12
+
13
+ TYPERS = [
14
+ Calculator,
15
+ Punctuator,
16
+ Quotator
17
+ ]
18
+
19
+ def self.s(txt)
20
+ TYPERS.reduce(txt) do |s, t|
21
+ t.work(s)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ # require 'pry'
3
+ begin
4
+ require 'spec'
5
+ rescue LoadError
6
+ require 'rspec'
7
+ end
8
+
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+
12
+ require 'typeright'
13
+ # include Typeright
14
+
15
+ if ENV['CI']
16
+ require 'coveralls'
17
+ Coveralls.wear!
18
+ end
19
+
20
+ FOR_README = <<TXT
21
+ And so... "Why?" -- He replied.
22
+ Because -> It's cool! And => I like beautiful text!'.
23
+ Also, notice some math: Pi + 2 * 180 / 2.
24
+ TXT
25
+
26
+ RSpec.configure do |config|
27
+ # config.mock_with(:mocha)
28
+
29
+ config.after(:suite) do
30
+ puts
31
+ puts FOR_README
32
+ puts
33
+ puts Typeright.s(FOR_README)
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Typeright do
4
+ it 'should do some math +-' do
5
+ expect(Typeright.s('So, Pi +- 3.1?')).to eq('So, π ± 3.1?')
6
+ end
7
+
8
+ it 'should do some math ->' do
9
+ expect(Typeright.s('So, Pi -> 3.1?')).to eq('So, π → 3.1?')
10
+ end
11
+
12
+ it 'should do some math <-' do
13
+ expect(Typeright.s('Go back <- this')).to eq('Go back ← this')
14
+ end
15
+
16
+ it 'should do some math =>' do
17
+ expect(Typeright.s('So, Pi => 3.1?')).to eq('So, π ⇒ 3.1?')
18
+ end
19
+
20
+ it 'should do some math <=' do
21
+ expect(Typeright.s('Go back <= this')).to eq('Go back ⇐ this')
22
+ end
23
+
24
+ it 'should do some math <<>>' do
25
+ expect(Typeright.s('Said <<hello>>')).to eq('Said «hello»')
26
+ end
27
+
28
+ it 'should do some math <<>>' do
29
+ expect(Typeright.s('Said <<hello>>')).to eq('Said «hello»')
30
+ end
31
+
32
+ it 'should not touch ``' do
33
+ expect(Typeright.s('Said `hello`')).to eq('Said `hello`')
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Typeright do
4
+ it 'should change minus to hyphens' do
5
+ expect(Typeright.s('And suddenly -- No more.'))
6
+ .to eq('And suddenly — No more.')
7
+ end
8
+
9
+ it 'should change dots to ellipse' do
10
+ expect(Typeright.s('And suddenly... No more.'))
11
+ .to eq('And suddenly… No more.')
12
+ end
13
+
14
+ it 'should make beautiful quotes' do
15
+ expect(Typeright.s('And suddenly... "No more".'))
16
+ .to eq('And suddenly… “No more”.')
17
+ end
18
+
19
+ it 'should make beautiful quotes' do
20
+ expect(Typeright.s("Walk among us... 'Nevermind!'"))
21
+ .to eq('Walk among us… ‘Nevermind!’')
22
+ end
23
+
24
+ it 'should do some math Pi π' do
25
+ expect(Typeright.s('So, Pi = 3.14...')).to eq('So, π = 3.14…')
26
+ end
27
+
28
+ it 'should do some math != π' do
29
+ expect(Typeright.s('So, Pi != 1???')).to eq('So, π ≠ 1???')
30
+ end
31
+
32
+ it 'should do some math +-' do
33
+ expect(Typeright.s('So, Pi +- 3.1?')).to eq('So, π ± 3.1?')
34
+ end
35
+
36
+ it 'should do some math ->' do
37
+ expect(Typeright.s('So, Pi -> 3.1?')).to eq('So, π → 3.1?')
38
+ end
39
+
40
+ it 'should do some math %o' do
41
+ expect(Typeright.s('It means 10%o')).to eq('It means 10‰')
42
+ end
43
+
44
+ {
45
+ 'pretty :-) So good' => 'pretty :-) So good',
46
+ 'place, I\'d rewrite it' => 'place, I’d rewrite it',
47
+ 'by 50 more reviewers...' => 'by 50 more reviewers…',
48
+ 'So "Why don\'t you" -- implied' => 'So “Why don’t you” — implied',
49
+ 'So "Why don\'t you?"' => 'So “Why don’t you?”',
50
+ 'So "Why don\'t you".' => 'So “Why don’t you”.',
51
+ 'So "Why don\'t you?".' => 'So “Why don’t you?”.'
52
+ }.each do |k, v|
53
+ it "should work nice with #{k} -> #{v}" do
54
+ expect(Typeright.s(k)).to eq(v)
55
+ end
56
+ end
57
+ end
data/typeright.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'typeright/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'typeright'
8
+ s.version = Typeright::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+
11
+ s.authors = ['Marcos Piccinini']
12
+ s.homepage = 'http://github.com/nofxx/typeright'
13
+ s.email = 'x@nofxx.com'
14
+ s.description = 'Make text beautiful'
15
+ s.summary = 'Make text UTF-8 beautiful'
16
+ s.license = 'MIT'
17
+
18
+ s.executables = ['typeright']
19
+ s.default_executable = 'typeright'
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.require_paths = ['lib']
24
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typeright
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Marcos Piccinini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Make text beautiful
14
+ email: x@nofxx.com
15
+ executables:
16
+ - typeright
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".coveralls.yml"
21
+ - ".gitignore"
22
+ - ".hound.yml"
23
+ - ".travis.yml"
24
+ - Gemfile
25
+ - Guardfile
26
+ - MIT-LICENSE
27
+ - README.md
28
+ - Rakefile
29
+ - bench/all.rb
30
+ - bin/typeright
31
+ - lib/typeright.rb
32
+ - lib/typeright/calculator.rb
33
+ - lib/typeright/cli.rb
34
+ - lib/typeright/punctuator.rb
35
+ - lib/typeright/quotator.rb
36
+ - lib/typeright/version.rb
37
+ - spec/spec_helper.rb
38
+ - spec/typeright/calculator_spec.rb
39
+ - spec/typeright_spec.rb
40
+ - typeright.gemspec
41
+ homepage: http://github.com/nofxx/typeright
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.4.5
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Make text UTF-8 beautiful
65
+ test_files:
66
+ - spec/spec_helper.rb
67
+ - spec/typeright/calculator_spec.rb
68
+ - spec/typeright_spec.rb