touch_up 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a3510239f264f68568fbf64a0de3153c57c68c7
4
+ data.tar.gz: 14d61fb892f66a11ff3bddef5b75ff1fe1737d19
5
+ SHA512:
6
+ metadata.gz: 1b499a73451c0bc5f18aa16b285137cd6c173a919d34601c3123406a6368f095b72e41a231cf98aa5606ba1d1b9f77559fb036947955b502b98a7932c28e5436
7
+ data.tar.gz: d38cf1dc3ff43e5eba9f7ff8b286edf35c52e6a59173b6a5c6ab2b39123fb85439fa55fd51f307bad3e5d544bad1189f974b32f66a72af2b18f5b3292b900fc5
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+
2
+ Copyright (c) 2015 da99
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+
2
+ # Touch_Up
3
+
4
+ I have no idea.
5
+
6
+ ## Installation
7
+
8
+ gem 'touch_up'
9
+
10
+ ## Usage
11
+
12
+ No coming any time soon.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.1
data/lib/touch_up.rb ADDED
@@ -0,0 +1,76 @@
1
+
2
+ require 'escape_escape_escape'
3
+ require 'twitter-text'
4
+
5
+ class Touch_Up
6
+
7
+ NOTHING = ''.freeze
8
+
9
+ include Twitter::Extractor
10
+
11
+ class << self
12
+ end # === class self ===
13
+
14
+ def initialize str
15
+ @origin = str
16
+ end
17
+
18
+ def to_html
19
+ @origin.
20
+
21
+ # "a" (anchor) tags, auto-linking
22
+ gsub(%r@(\*([^\*]+)\*\s+)?([^\.\s]+\.[^\.\s]+[^\s]+[^\.\s])@) { |full, match|
23
+
24
+ text = $2
25
+ raw_link = Escape_Escape_Escape.decode_html($3)
26
+
27
+ link = extract_urls(raw_link).first
28
+
29
+ if !link
30
+ full
31
+ else
32
+
33
+ append = raw_link.sub(link, NOTHING)
34
+ short_link = link
35
+ clean_short_link = Escape_Escape_Escape.html(short_link)
36
+
37
+ if !link['://']
38
+ link = 'http://' + link
39
+ end
40
+
41
+ begin
42
+ clean_link = Escape_Escape_Escape.href(link)
43
+
44
+ if text
45
+ "<a href=\"#{clean_link}\">#{text}</a>#{append}"
46
+ else
47
+ "<a href=\"#{clean_link}\">#{clean_short_link}</a>#{append}"
48
+ end
49
+
50
+ rescue Escape_Escape_Escape::Invalid_HREF
51
+ full
52
+ end # begin
53
+
54
+ end # if
55
+
56
+
57
+ }.
58
+
59
+
60
+ # "i", "del", "strong" tags
61
+ gsub(/(?<=\s)([\*\/\-]{1,2})([^\1\<\>]+)(\1|\-\*)(?=\s)/) { |full, match|
62
+ case
63
+ when $1 == $3 && $1 == '/'
64
+ "<i>#{$2}</i>"
65
+ when $1 == '*-' && $3 == '-*'
66
+ "<del>#{$2}</del>"
67
+ when $1 == $3 && $1 == '*'
68
+ "<strong>#{$2}</strong>"
69
+ else
70
+ full
71
+ end
72
+ }
73
+
74
+ end
75
+
76
+ end # === class Touch_Up ===
@@ -0,0 +1,94 @@
1
+
2
+ describe 'it runs' do
3
+
4
+ it "turns slash-ed text into italics: /slash/ <i>slash</i>" do
5
+ text = Touch_Up.new(<<-EOF)
6
+ This is my /slash/ text.
7
+ EOF
8
+ text.to_html.strip.should == <<-EOF.strip
9
+ This is my <i>slash</i> text.
10
+ EOF
11
+ end # === it turns slash-ed text into italics: /slash/ <i>slash</i>
12
+
13
+ it "turns star-ed text to strong: *bold* <strong>bold</strong>" do
14
+ text = Touch_Up.new(<<-EOF)
15
+ This is my brave and *bold* text.
16
+ EOF
17
+ text.to_html.strip.should == <<-EOF.strip
18
+ This is my brave and <strong>bold</strong> text.
19
+ EOF
20
+ end # === it turns star-ed text to strong: *bold* <strong>bold</strong>
21
+
22
+ it "turns star-dash-ed text to strong: *-del-* <del>del</del>" do
23
+ text = Touch_Up.new(<<-EOF)
24
+ This is my *-old-* text.
25
+ EOF
26
+ text.to_html.strip.should == <<-EOF.strip
27
+ This is my <del>old</del> text.
28
+ EOF
29
+ end # === it "turns star-dash-ed text to strong: *-del-* <del>del</del>" do
30
+
31
+ end # === describe 'it runs'
32
+
33
+ describe "linking" do
34
+
35
+ it "turns text into links: *my link* google.com" do
36
+ text = Touch_Up.new "This is *my link* google.com."
37
+ text.to_html.should == "This is <a href=\"http:&#47;&#47;google.com\">my link</a>."
38
+ end
39
+
40
+ it "turns only text with a period inside to links: text. vs my.text." do
41
+ text = Touch_Up.new "This is *bold* text. This is my *link* lewrockwell.com."
42
+ text.to_html.should == "This is <strong>bold</strong> text. This is my <a href=\"http:&#47;&#47;lewrockwell.com\">link</a>."
43
+ end
44
+
45
+ it "does not create invalid links: javascript://alert('text.text')" do
46
+ Touch_Up.new("This is my *link* javascript://alert('text.text').").
47
+ to_html.should == "This is my <strong>link</strong> javascript://alert('text.text')."
48
+ end
49
+
50
+ it "ignores ending punctuation: .com." do
51
+ text = Touch_Up.new "This is *my link* google.com."
52
+ text.to_html.should == "This is <a href=\"http:&#47;&#47;google.com\">my link</a>."
53
+ end
54
+
55
+ it "ignores ending punctuation: .com?" do
56
+ text = Touch_Up.new "Is it this google.com?"
57
+ text.to_html.should == "Is it this <a href=\"http:&#47;&#47;google.com\">google.com</a>?"
58
+ end
59
+
60
+ it "ignores ending punctuation: .com!" do
61
+ text = Touch_Up.new "Yes google.com!"
62
+ text.to_html.should == "Yes <a href=\"http:&#47;&#47;google.com\">google.com</a>!"
63
+ end
64
+
65
+ it "allows a ? in the url, but ignores ending punctuation: my.website.com/?image?" do
66
+ text = Touch_Up.new "Yes my.website.com/?image? Yes."
67
+ text.to_html.should == "Yes <a href=\"http:&#47;&#47;my.website.com&#47;?image\">my.website.com&#47;?image</a>? Yes."
68
+ end
69
+
70
+ it "does not auto-link links in anchor tags: <a href=\"...\">..." do
71
+ text = Touch_Up.new "*my* google.com. another.link."
72
+ text.to_html.should == "<a href=\"http:&#47;&#47;google.com\">my</a>. <a href=\"http:&#47;&#47;another.link\">another.link</a>."
73
+ end
74
+
75
+ it "does not auto-link invalid urls: http://www.yahoo.com/&" do
76
+ txt = "This is invalid: http://кц.рф"
77
+ Touch_Up.new(txt).
78
+ to_html.should == txt
79
+ end
80
+
81
+ it "does not double-escape hrefs" do
82
+ href = Escape_Escape_Escape.href "http://www.google.com/"
83
+ txt = %^my link #{href}^
84
+ Touch_Up.new(txt).
85
+ to_html.should == %^my link <a href="#{href}">#{href}</a>^
86
+ end
87
+
88
+ it "escapes content for anchor tags" do
89
+ href="www.google.com/?text=text&more=more"
90
+ Touch_Up.new("my link #{href}").
91
+ to_html.should == %^my link <a href="#{Escape_Escape_Escape.href 'http://' + href}">#{Escape_Escape_Escape.href href}</a>^
92
+ end
93
+
94
+ end # === describe "linking"
@@ -0,0 +1,4 @@
1
+
2
+ require 'Bacon_Colored'
3
+ require 'touch_up'
4
+ require 'pry'
data/touch_up.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "touch_up"
7
+ spec.version = `cat VERSION`
8
+ spec.authors = ["da99"]
9
+ spec.email = ["i-hate-spam-1234567@mailinator.com"]
10
+ spec.summary = %q{My alternative to markdown for morons.}
11
+ spec.description = %q{
12
+ Provides italics, strikes, bold, and links.
13
+ Nothing else.
14
+ }
15
+ spec.homepage = "https://github.com/da99/touch_up"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |file|
19
+ file.index('bin/') == 0 && file != "bin/#{File.basename Dir.pwd}"
20
+ }
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.required_ruby_version = '>= 2.2.0'
26
+
27
+ spec.add_development_dependency "pry" , "~> 0.9"
28
+ spec.add_development_dependency "bundler" , "~> 1.5"
29
+ spec.add_development_dependency "bacon" , "~> 1.0"
30
+ spec.add_development_dependency "Bacon_Colored" , "~> 0.1"
31
+
32
+ spec.add_dependency "twitter-text" , ">= 1.11.0"
33
+ spec.add_dependency "escape_escape_escape" , "> 1.4.0"
34
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: touch_up
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - da99
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bacon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: Bacon_Colored
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: twitter-text
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.11.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.11.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: escape_escape_escape
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.4.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.4.0
97
+ description: "\n Provides italics, strikes, bold, and links.\n Nothing else.\n
98
+ \ "
99
+ email:
100
+ - i-hate-spam-1234567@mailinator.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - VERSION
110
+ - lib/touch_up.rb
111
+ - specs/0010-it-runs.rb
112
+ - specs/lib/helpers.rb
113
+ - touch_up.gemspec
114
+ homepage: https://github.com/da99/touch_up
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 2.2.0
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.5
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: My alternative to markdown for morons.
138
+ test_files: []