textp 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c9ec25aed20285779879b2fbbab6c7f511f45ca9
4
+ data.tar.gz: cfc263582f1c2088e22446f488c17132287ea7ca
5
+ SHA512:
6
+ metadata.gz: 0b57e9f92de5ab8ec96fc87966d4edbc84c8141edc5be053046e1e4d1fc9f3eecb062ffbdbd8d0315da9fa270929b7389458dff50f3b09338cee9b9343f06beb
7
+ data.tar.gz: adffd381cd01d04e829356cd49fa088b159752534c07336150de480649363e81fe96a3938315176b909eda122a060137ec520c582a62775fa4cab069539a9e1c
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ README.rdoc
3
+ ChangeLog.rdoc
4
+ LICENSE.txt
@@ -0,0 +1,2 @@
1
+ html/
2
+ pkg/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format NyanCatFormatter
@@ -0,0 +1,4 @@
1
+ === 0.1.0 / 2014-05-15
2
+
3
+ * Initial release:
4
+ -- Basic link extractor to grab links from text.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.0.0'
3
+ #ruby-gemset=textp
4
+
5
+ gem 'rspec', '~> 3.0.0.beta2'
6
+ gem 'guard'
7
+ gem 'guard-rspec'
8
+ gem 'nyan-cat-formatter'
9
+
10
+ gem 'ruby-oembed', '~> 0.8.9'
11
+ gem 'rdoc', '~> 3.0'
12
+ gem 'rubygems-tasks', '~> 0.2'
@@ -0,0 +1,65 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ celluloid (0.15.2)
5
+ timers (~> 1.1.0)
6
+ coderay (1.1.0)
7
+ diff-lcs (1.2.5)
8
+ ffi (1.9.3)
9
+ formatador (0.2.4)
10
+ guard (2.6.1)
11
+ formatador (>= 0.2.4)
12
+ listen (~> 2.7)
13
+ lumberjack (~> 1.0)
14
+ pry (>= 0.9.12)
15
+ thor (>= 0.18.1)
16
+ guard-rspec (4.2.9)
17
+ guard (~> 2.1)
18
+ rspec (>= 2.14, < 4.0)
19
+ json (1.8.1)
20
+ listen (2.7.5)
21
+ celluloid (>= 0.15.2)
22
+ rb-fsevent (>= 0.9.3)
23
+ rb-inotify (>= 0.9)
24
+ lumberjack (1.0.5)
25
+ method_source (0.8.2)
26
+ nyan-cat-formatter (0.6.0)
27
+ rspec (>= 2.99.0.beta1, >= 2.14.2, < 4)
28
+ pry (0.9.12.6)
29
+ coderay (~> 1.0)
30
+ method_source (~> 0.8)
31
+ slop (~> 3.4)
32
+ rb-fsevent (0.9.4)
33
+ rb-inotify (0.9.4)
34
+ ffi (>= 0.5.0)
35
+ rdoc (3.12.2)
36
+ json (~> 1.4)
37
+ rspec (3.0.0.beta2)
38
+ rspec-core (= 3.0.0.beta2)
39
+ rspec-expectations (= 3.0.0.beta2)
40
+ rspec-mocks (= 3.0.0.beta2)
41
+ rspec-core (3.0.0.beta2)
42
+ rspec-support (= 3.0.0.beta2)
43
+ rspec-expectations (3.0.0.beta2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (= 3.0.0.beta2)
46
+ rspec-mocks (3.0.0.beta2)
47
+ rspec-support (= 3.0.0.beta2)
48
+ rspec-support (3.0.0.beta2)
49
+ ruby-oembed (0.8.9)
50
+ rubygems-tasks (0.2.4)
51
+ slop (3.5.0)
52
+ thor (0.19.1)
53
+ timers (1.1.0)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ guard
60
+ guard-rspec
61
+ nyan-cat-formatter
62
+ rdoc (~> 3.0)
63
+ rspec (~> 3.0.0.beta2)
64
+ ruby-oembed (~> 0.8.9)
65
+ rubygems-tasks (~> 0.2)
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Oovre
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ textp
2
+ =====
3
+
4
+ A text parser that grabs all information from the text given. Links that can be embeded are the main feature right now.
@@ -0,0 +1,27 @@
1
+ = textp
2
+
3
+ * {Homepage}[https://rubygems.org/gems/textp]
4
+ * {Documentation}[http://rubydoc.info/gems/textp/frames]
5
+ * {Email}[mailto:kidd.josh.343 at gmail.com]
6
+
7
+ == Description
8
+
9
+ TODO: Description
10
+
11
+ == Features
12
+
13
+ == Examples
14
+
15
+ require 'textp'
16
+
17
+ == Requirements
18
+
19
+ == Install
20
+
21
+ $ gem install textp
22
+
23
+ == Copyright
24
+
25
+ Copyright (c) 2014
26
+
27
+ See LICENSE.txt for details.
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+
6
+ begin
7
+ gem 'rubygems-tasks', '~> 0.2'
8
+ require 'rubygems/tasks'
9
+
10
+ Gem::Tasks.new
11
+ rescue LoadError => e
12
+ warn e.message
13
+ warn "Run `gem install rubygems-tasks` to install Gem::Tasks."
14
+ end
15
+
16
+ begin
17
+ gem 'rdoc', '~> 3.0'
18
+ require 'rdoc/task'
19
+
20
+ RDoc::Task.new do |rdoc|
21
+ rdoc.title = "textp"
22
+ end
23
+ rescue LoadError => e
24
+ warn e.message
25
+ warn "Run `gem install rdoc` to install 'rdoc/task'."
26
+ end
27
+ task :doc => :rdoc
28
+
29
+ begin
30
+ gem 'rspec', '~> 3.0.0.beta2'
31
+ require 'rspec/core/rake_task'
32
+
33
+ RSpec::Core::RakeTask.new
34
+ rescue LoadError => e
35
+ task :spec do
36
+ abort "Please run `gem install rspec` to install RSpec."
37
+ end
38
+ end
39
+
40
+ task :test => :spec
41
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ require 'textp/parser'
2
+ require 'textp/html_helper'
3
+
4
+ require 'textp/version'
@@ -0,0 +1,51 @@
1
+ require 'json'
2
+ require 'oembed'
3
+
4
+ module Textp
5
+
6
+ class HtmlHelper
7
+ def initialize(text)
8
+ @text = text
9
+ @parser = Parser.new(text)
10
+ end
11
+
12
+ def links
13
+ links = { :links => @parser.links }
14
+ end
15
+
16
+ def links_content
17
+ oembed_data = {}
18
+ OEmbed::Providers.register(OEmbed::Providers::Youtube)
19
+ @parser.links.each do |link|
20
+ resource = OEmbed::Providers.get(link)
21
+ oembed_data[link] ||= {}
22
+ oembed_data[link][:html] ||= resource.html
23
+ oembed_data[link][:provider] ||= {
24
+ :endpoint => resource.provider.endpoint
25
+ }
26
+ end
27
+ oembed_data
28
+ end
29
+
30
+ def parser
31
+ @parser
32
+ end
33
+
34
+ def response
35
+ json_string = {
36
+ :links => @parser.links,
37
+ :oembed_data => links_content
38
+ }.to_json
39
+ end
40
+
41
+ def replacement_content
42
+ content = @text
43
+ @parser.links.each do |link|
44
+ html_content = links_content[link][:html]
45
+ content.gsub!(link, html_content)
46
+ end
47
+ content
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,33 @@
1
+ require 'uri'
2
+
3
+ module Textp
4
+ class Parser
5
+
6
+ # Pass in some text and all things that
7
+ # can be parsed will be parsed and seperated into
8
+ # individual parts.
9
+ #
10
+ # Usage:
11
+ # => Parser.new("Meeting tomorrow at 3:30 PM.")
12
+ # => Parser.new("This embeded video is cool: youtube_link")
13
+
14
+ def initialize(text)
15
+ @text = text
16
+ end
17
+
18
+ def parse
19
+ (!@text.nil?) ? @text : nil
20
+ end
21
+
22
+ def has_links?
23
+ urls = URI.extract(@text)
24
+ (urls.empty?) ? false : true
25
+ end
26
+
27
+ def links
28
+ links = URI.extract(@text)
29
+ links
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ module Textp
2
+ # textp version
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+ require 'textp/version'
3
+
4
+ include Textp
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'textp'
3
+
4
+ describe Textp do
5
+ it "should have a VERSION constant" do
6
+ expect(subject.const_get('VERSION')).to_not be_empty
7
+ end
8
+
9
+ describe "Parser" do
10
+ before(:each) do
11
+ @text = "I have a link http://www.google.com"
12
+ @parser = Parser.new(@text)
13
+ end
14
+ it "should output text" do
15
+ expect(@parser.parse).to eq(@text)
16
+ end
17
+ it "should find urls in text" do
18
+ expect(@parser.has_links?).to_not be(false)
19
+ end
20
+ it "should return links as json" do
21
+ expect(@parser.links).to eq(["http://www.google.com"])
22
+ end
23
+ end
24
+
25
+ describe "HTML Helper" do
26
+
27
+ before(:each) do
28
+ @text = "I have a youtube link https://www.youtube.com/watch?v=9Nxq-5jt10Q"
29
+ @html = HtmlHelper.new(@text)
30
+ end
31
+
32
+ context "Links" do
33
+ it "should have a valid links array" do
34
+ expect(@html.parser.links).to eq(["https://www.youtube.com/watch?v=9Nxq-5jt10Q"])
35
+ end
36
+ it "should convert links to hash" do
37
+ expected = {:links => ["https://www.youtube.com/watch?v=9Nxq-5jt10Q"]}
38
+ expect(@html.links).to eq(expected)
39
+ end
40
+ end
41
+
42
+ context "Html Replacement Content" do
43
+ it "should replace links with html fetched from oembed api" do
44
+ expect(@html.replacement_content).to_not eq("I have a youtube link https://www.youtube.com/watch?v=9Nxq-5jt10Q")
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/textp/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "textp"
7
+ gem.version = Textp::VERSION
8
+ gem.summary = "Simple Text parsing for html or just text."
9
+ gem.description = "Give a string of text with a link and it will replace the link with the embeded HTML content."
10
+ gem.license = "MIT"
11
+ gem.authors = ["Joshua Kidd"]
12
+ gem.email = "kidd.josh.343@gmail.com"
13
+ gem.homepage = "https://rubygems.org/gems/textp"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'ruby-oembed', '~> 0.8.9'
21
+
22
+ gem.add_development_dependency 'rdoc', '~> 3.0'
23
+ gem.add_development_dependency 'rspec', '~> 3.0.0.beta2'
24
+ gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
25
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: textp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Kidd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-oembed
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0.beta2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0.beta2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubygems-tasks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ description: Give a string of text with a link and it will replace the link with the
70
+ embeded HTML content.
71
+ email: kidd.josh.343@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .document
77
+ - .gitignore
78
+ - .rspec
79
+ - ChangeLog.rdoc
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - Guardfile
83
+ - LICENSE
84
+ - README.md
85
+ - README.rdoc
86
+ - Rakefile
87
+ - lib/textp.rb
88
+ - lib/textp/html_helper.rb
89
+ - lib/textp/parser.rb
90
+ - lib/textp/version.rb
91
+ - spec/spec_helper.rb
92
+ - spec/textp_spec.rb
93
+ - textp.gemspec
94
+ homepage: https://rubygems.org/gems/textp
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Simple Text parsing for html or just text.
118
+ test_files:
119
+ - spec/spec_helper.rb
120
+ - spec/textp_spec.rb