text-marker 0.0.1

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: ecb01a506370f70d3b8215401bbe9be1611e6906
4
+ data.tar.gz: e1f6be7eeef9bc0199ac419a6deb97e74cf6d86a
5
+ SHA512:
6
+ metadata.gz: fadc9f88a55aa568d5f8212255bbc2d1a9327a314ff96d3284063d95f0785b0df57eaacc9faab810f7cbf2786dc2977e38f672503e1dcfdac2db5ce8eeecc11a
7
+ data.tar.gz: 0590e42d4d9b8feee0aa18db0b8cd72e5bee5ed15fb1a02d69a5ae0f11e35da5df6ccf924363a7cd75f7cd76606cc5676a01834fbc897ee2dee289d8ff840939
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in text-maker.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 geisonfgf
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.
22
+
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ TextMarker
2
+ ===========
3
+
4
+ Gem that mark string in a text. It is possible mark the text with html tags.
5
+
6
+ Installation
7
+ ============
8
+
9
+ Gemfile
10
+ -------
11
+
12
+ 1) add in your Gemfile
13
+
14
+ gem 'text-marker'
15
+
16
+ 2) run this line in your prompt
17
+
18
+ $ bundle install text-marker
19
+
20
+
21
+ RubyGems
22
+ -------
23
+
24
+ $ gem install text-marker
25
+
26
+ Usage
27
+ =====
28
+
29
+ ```ruby
30
+ require 'text-marker'
31
+
32
+ snippet_to_be_marked = "text"
33
+ text = "Some text to be marked. After used TextMaker in this text it will return this text with desired text marked."
34
+
35
+ text_marked = TextMarker::Marker.new(text).mark_first_ocurrence_of(snippet_to_be_marked)
36
+
37
+ tm = TextMarker.Marker.new "Text"
38
+ tm_tag1 = TextMarker::Tag.new :tag, :background_color, :text_color
39
+
40
+ text_with_all_ocurrence_of_snipped_marked = tm.mark_all_ocurrence_of(
41
+ "snippet-to-be-marked", tm_tag1)
42
+
43
+ text_with_all_ocurrences_of_snipped_marked = tm.mark_all_ocurrence_of(
44
+ "snippet-to-be-marked", TextMarker::Tag.new :span)
45
+
46
+ text_with_first_ocurrence_of_snipped_marked = tm.mark_first_ocurrence_of(
47
+ "snippet-to-be-marked", TextMarker::Tag.new :span, :yellow)
48
+ ```
49
+
50
+ Author
51
+ ======
52
+
53
+ #### Created and maintained by
54
+ Geison Felipe Goes Flores
55
+
56
+ geisonfgf@gmail.com
57
+
58
+ @geisonfgfg
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it ( https://github.com/[my-github-username]/text-marker/fork )
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create a new Pull Request
67
+
68
+ License
69
+ =======
70
+
71
+ TextMarker is licensed under the MIT license.
72
+
73
+ See LICENSE for the full license text.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rspec/core/rake_task'
2
+ require "bundler/gem_tasks"
3
+
4
+ # Default directory to look in is `/specs`
5
+ # Run with `rake spec`
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ task.rspec_opts = ['--color', '--format', 'nested']
8
+ end
9
+
10
+ task :default => :spec
data/lib/textmarker.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "textmarker/version"
2
+
3
+ module TextMarker
4
+ class Marker
5
+ attr_accessor :text
6
+
7
+ def initialize(text="")
8
+ @text = text
9
+ end
10
+
11
+ def mark_all_ocurrence_of(snippet_to_be_marked, tag=Tag.new)
12
+ @text.gsub(snippet_to_be_marked, build_marked_snippet(snippet_to_be_marked, tag))
13
+ end
14
+
15
+ def mark_first_ocurrence_of(snippet_to_be_marked, tag=Tag.new)
16
+ @text.sub(snippet_to_be_marked, build_marked_snippet(snippet_to_be_marked, tag))
17
+ end
18
+
19
+ private
20
+
21
+ def build_marked_snippet(snippet_to_be_marked, tag)
22
+ tag.open_tag + snippet_to_be_marked + tag.close_tag
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ require "textmarker/version"
2
+
3
+ module TextMarker
4
+ class Tag
5
+ attr_accessor :tag, :background_color, :text_color
6
+ attr_reader :open_tag, :close_tag
7
+
8
+ def initialize(tag=:span, background_color=:yellow, text_color=:black)
9
+ @tag = tag
10
+ @background_color = background_color
11
+ @text_color = text_color
12
+
13
+ @open_tag = generate_open_tag
14
+ @close_tag = generate_close_tag
15
+ end
16
+
17
+ def to_s
18
+ generate_open_tag + generate_close_tag
19
+ end
20
+
21
+ private
22
+
23
+ def generate_open_tag
24
+ "<#{@tag} style='background_color: #{@background_color}; color: #{@text_color};'>"
25
+ end
26
+
27
+ def generate_close_tag
28
+ "</#{@tag}>"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module TextMarker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'textmarker'
5
+ require 'textmarker/tag'
data/spec/tag_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe "TextMarker::Tag.new" do
4
+ before(:each) do
5
+ @instance_default = TextMarker::Tag.new
6
+ @instance = TextMarker::Tag.new :h1, :black, :white
7
+ end
8
+
9
+ it 'Shoud create a Default Tag object' do
10
+ expect(@instance_default).to be_a TextMarker::Tag
11
+ expect(@instance_default.tag).to eq :span
12
+ expect(@instance_default.open_tag).to eq "<span style='background_color: yellow; color: black;'>"
13
+ expect(@instance_default.close_tag).to eq "</span>"
14
+ expect(@instance_default.background_color).to eq :yellow
15
+ expect(@instance_default.text_color).to eq :black
16
+ expect(@instance_default.to_s).to eq "<span style='background_color: yellow; color: black;'></span>"
17
+ end
18
+
19
+ it 'Shoud create a Tag object' do
20
+ expect(@instance).to be_a TextMarker::Tag
21
+ expect(@instance.tag).to eq :h1
22
+ expect(@instance.open_tag).to eq "<h1 style='background_color: black; color: white;'>"
23
+ expect(@instance.close_tag).to eq "</h1>"
24
+ expect(@instance.background_color).to eq :black
25
+ expect(@instance.text_color).to eq :white
26
+ expect(@instance.to_s).to eq "<h1 style='background_color: black; color: white;'></h1>"
27
+ end
28
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe "TextMarker::Marker" do
4
+ before(:each) do
5
+ @instance_tag = TextMarker::Tag.new :h1, :black, :white
6
+ @instance_default = TextMarker::Marker.new
7
+ @instance_with_text = TextMarker::Marker.new "Some text to be marked."
8
+ @instance_with_long_text = TextMarker::Marker.new "Some text to be marked. After used TextMaker in this text it will return this text with desired text marked."
9
+ end
10
+
11
+ it 'Shoud create a Marker object with no text' do
12
+ expect(@instance_default).to be_a TextMarker::Marker
13
+ expect(@instance_default.text).to eq ""
14
+ end
15
+
16
+ it 'Shoud create a Marker object with text' do
17
+ expect(@instance_with_text).to be_a TextMarker::Marker
18
+ expect(@instance_with_text.text).to eq "Some text to be marked."
19
+ end
20
+
21
+ it 'Shoud return the text passed to Marker with the first snippet of desired text marked, passing a default Tag' do
22
+ expect(@instance_with_long_text).to be_a TextMarker::Marker
23
+ expect(@instance_with_long_text.text).to eq "Some text to be marked. After used TextMaker in this text it will return this text with desired text marked."
24
+ expect(@instance_with_long_text.mark_first_ocurrence_of("text")).to eq "Some <span style='background_color: yellow; color: black;'>text</span> to be marked. After used TextMaker in this text it will return this text with desired text marked."
25
+ end
26
+
27
+ it 'Shoud return the text passed to Marker with the first snippet of desired text marked, passing a custom Tag' do
28
+ expect(@instance_with_long_text).to be_a TextMarker::Marker
29
+ expect(@instance_with_long_text.text).to eq "Some text to be marked. After used TextMaker in this text it will return this text with desired text marked."
30
+ expect(@instance_with_long_text.mark_first_ocurrence_of("text", @instance_tag)).to eq "Some <h1 style='background_color: black; color: white;'>text</h1> to be marked. After used TextMaker in this text it will return this text with desired text marked."
31
+ end
32
+
33
+ it 'Shoud return the text passed to Marker with the snippets of desired text marked, passing a default Tag' do
34
+ expect(@instance_with_long_text).to be_a TextMarker::Marker
35
+ expect(@instance_with_long_text.text).to eq "Some text to be marked. After used TextMaker in this text it will return this text with desired text marked."
36
+ expect(@instance_with_long_text.mark_all_ocurrence_of("text")).to eq "Some <span style='background_color: yellow; color: black;'>text</span> to be marked. After used TextMaker in this <span style='background_color: yellow; color: black;'>text</span> it will return this <span style='background_color: yellow; color: black;'>text</span> with desired <span style='background_color: yellow; color: black;'>text</span> marked."
37
+ end
38
+
39
+ it 'Shoud return the text passed to Marker with the snippets of desired text marked, passing a custom Tag' do
40
+ expect(@instance_with_long_text).to be_a TextMarker::Marker
41
+ expect(@instance_with_long_text.text).to eq "Some text to be marked. After used TextMaker in this text it will return this text with desired text marked."
42
+ expect(@instance_with_long_text.mark_all_ocurrence_of("text", @instance_tag)).to eq "Some <h1 style='background_color: black; color: white;'>text</h1> to be marked. After used TextMaker in this <h1 style='background_color: black; color: white;'>text</h1> it will return this <h1 style='background_color: black; color: white;'>text</h1> with desired <h1 style='background_color: black; color: white;'>text</h1> marked."
43
+ end
44
+
45
+ it 'Shoud return the exact same text passed to Marker, passing a default Tag and a snippet that does not exist in the text' do
46
+ snippet_not_found_in_text = "snippet_not_found_in_text"
47
+ text = "Some text to be marked. After used TextMaker in this text it will return this text with desired text marked."
48
+ expect(@instance_with_long_text).to be_a TextMarker::Marker
49
+ expect(@instance_with_long_text.text).to eq text
50
+ expect(@instance_with_long_text.mark_first_ocurrence_of(snippet_not_found_in_text)).to eq text
51
+ expect(@instance_with_long_text.mark_all_ocurrence_of(snippet_not_found_in_text)).to eq text
52
+ end
53
+
54
+ it 'Shoud return the text passed to Marker with the first snippet of desired text marked, passing a default Tag and using Marker in one line' do
55
+ text = "Some text to be marked. After used TextMaker in this text it will return this text with desired text marked."
56
+ expect(TextMarker::Marker.new(text).mark_first_ocurrence_of("text")).to eq "Some <span style='background_color: yellow; color: black;'>text</span> to be marked. After used TextMaker in this text it will return this text with desired text marked."
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "textmarker/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "text-marker"
8
+ spec.version = TextMarker::VERSION
9
+ spec.authors = ["Geison Goes"]
10
+ spec.email = ["geisonfgf@gmail.com"]
11
+ spec.summary = %q{Gem that mark string in a text.}
12
+ spec.description = %q{Gem that mark string in a text. It is possible mark the text with html tags.}
13
+ spec.homepage = "https://github.com/geisonfgf/text-marker"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "simplecov"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: text-marker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Geison Goes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simplecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Gem that mark string in a text. It is possible mark the text with html
70
+ tags.
71
+ email:
72
+ - geisonfgf@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .DS_Store
78
+ - .gitignore
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - lib/textmarker.rb
84
+ - lib/textmarker/tag.rb
85
+ - lib/textmarker/version.rb
86
+ - spec/spec_helper.rb
87
+ - spec/tag_spec.rb
88
+ - spec/textmarker_spec.rb
89
+ - text-maker.gemspec
90
+ homepage: https://github.com/geisonfgf/text-marker
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.4
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Gem that mark string in a text.
114
+ test_files:
115
+ - spec/spec_helper.rb
116
+ - spec/tag_spec.rb
117
+ - spec/textmarker_spec.rb