geo_pattern 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/Gemfile +20 -0
- data/README.md +4 -4
- data/Rakefile +23 -1
- data/geo_pattern.gemspec +8 -10
- data/lib/geo_pattern.rb +28 -4
- data/lib/geo_pattern/helpers.rb +7 -0
- data/lib/geo_pattern/pattern_generator.rb +0 -4
- data/lib/geo_pattern/{pattern/pattern_helpers.rb → pattern_helpers.rb} +0 -2
- data/lib/geo_pattern/svg.rb +6 -0
- data/lib/geo_pattern/version.rb +1 -1
- data/spec/geo_pattern_spec.rb +44 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/aruba.rb +24 -0
- data/spec/support/helpers.rb +34 -0
- data/spec/support/rspec.rb +24 -0
- data/spec/support/string.rb +2 -0
- data/spec/svg_spec.rb +12 -0
- metadata +22 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81c3c62556904d41859cbdc5f24b309d27643d61
|
4
|
+
data.tar.gz: 13208f9b302c0294458d5c6d33ed41c5ea6bddf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 429e50e9f25823d253761aae3b9fedf5a113271bd1cbeb495a32b4f7d828af56a7c9a8308553e85e50f93266d3e2c19f90fb93a72504c096d029aec6c962f3d2
|
7
|
+
data.tar.gz: 77b6992af30dba44823e148850fa32e7de5b0b04454c091818d4ce99714a8bb4e07b89f148d47ae06903389472063b23e0b94b455e6cca194991c6a44dbc3eb9
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
@@ -2,3 +2,23 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in geopatterns.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'aruba'
|
9
|
+
gem 'rake'
|
10
|
+
gem 'rubocop'
|
11
|
+
gem 'simplecov'
|
12
|
+
gem 'fuubar'
|
13
|
+
gem 'inch'
|
14
|
+
gem 'activesupport'
|
15
|
+
gem 'pry'
|
16
|
+
|
17
|
+
if RUBY_VERSION >= "2"
|
18
|
+
gem 'byebug'
|
19
|
+
gem 'pry-byebug'
|
20
|
+
else
|
21
|
+
gem 'debugger'
|
22
|
+
gem 'pry-debugger'
|
23
|
+
end
|
24
|
+
end
|
data/README.md
CHANGED
@@ -28,25 +28,25 @@ Or install it yourself as:
|
|
28
28
|
Make a new pattern:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
pattern = GeoPattern.generate(
|
31
|
+
pattern = GeoPattern.generate('Mastering Markdown')
|
32
32
|
```
|
33
33
|
|
34
34
|
To specify a base background color (with a hue and saturation that adjusts depending on the string):
|
35
35
|
|
36
36
|
```ruby
|
37
|
-
pattern = GeoPattern.generate(
|
37
|
+
pattern = GeoPattern.generate('Mastering Markdown', base_color: '#fc0')
|
38
38
|
```
|
39
39
|
|
40
40
|
To use a specific background color (w/o any hue or saturation adjustments):
|
41
41
|
|
42
42
|
```ruby
|
43
|
-
pattern = GeoPattern.generate(
|
43
|
+
pattern = GeoPattern.generate('Mastering Markdown', color: '#fc0')
|
44
44
|
```
|
45
45
|
|
46
46
|
To use a specific [pattern generator](#available-patterns):
|
47
47
|
|
48
48
|
```ruby
|
49
|
-
pattern = GeoPattern.generate(
|
49
|
+
pattern = GeoPattern.generate('Mastering Markdown', generator: GeoPattern::SineWavePattern)
|
50
50
|
```
|
51
51
|
|
52
52
|
Get the SVG string:
|
data/Rakefile
CHANGED
@@ -1 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require 'rubocop/rake_task'
|
2
|
+
require 'inch/rake'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
desc 'Default task running Tests'
|
6
|
+
task default: :test
|
7
|
+
|
8
|
+
desc 'Run test suite'
|
9
|
+
task test: 'test:rspec'
|
10
|
+
# task test: %w(test:rspec test:rubocop)
|
11
|
+
|
12
|
+
namespace :test do
|
13
|
+
|
14
|
+
RSpec::Core::RakeTask.new(:rspec)
|
15
|
+
|
16
|
+
RuboCop::RakeTask.new
|
17
|
+
|
18
|
+
Inch::Rake::Suggest.new
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace :gem do
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
end
|
data/geo_pattern.gemspec
CHANGED
@@ -4,22 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'geo_pattern/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'geo_pattern'
|
8
8
|
spec.version = GeoPattern::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Jason Long']
|
10
|
+
spec.email = ['jlong@github.com']
|
11
11
|
spec.summary = %q{Generate SVG beautiful patterns}
|
12
12
|
spec.description = %q{Generate SVG beautiful patterns}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/jasonlong/geo_pattern'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency
|
22
|
-
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
-
spec.add_development_dependency "rake"
|
21
|
+
spec.add_dependency 'color', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
25
23
|
end
|
data/lib/geo_pattern.rb
CHANGED
@@ -1,7 +1,31 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require '
|
4
|
-
|
1
|
+
require 'base64'
|
2
|
+
require 'digest/sha1'
|
3
|
+
require 'color'
|
4
|
+
|
5
|
+
require 'geo_pattern/version'
|
6
|
+
require 'geo_pattern/svg'
|
7
|
+
require 'geo_pattern/pattern_helpers'
|
8
|
+
require 'geo_pattern/helpers'
|
9
|
+
|
10
|
+
require 'geo_pattern/pattern/base_pattern'
|
11
|
+
require 'geo_pattern/pattern/chevron_pattern'
|
12
|
+
require 'geo_pattern/pattern/concentric_circles_pattern'
|
13
|
+
require 'geo_pattern/pattern/diamond_pattern'
|
14
|
+
require 'geo_pattern/pattern/hexagon_pattern'
|
15
|
+
require 'geo_pattern/pattern/mosaic_squares_pattern'
|
16
|
+
require 'geo_pattern/pattern/nested_squares_pattern'
|
17
|
+
require 'geo_pattern/pattern/octagon_pattern'
|
18
|
+
require 'geo_pattern/pattern/overlapping_circles_pattern'
|
19
|
+
require 'geo_pattern/pattern/overlapping_rings_pattern'
|
20
|
+
require 'geo_pattern/pattern/plaid_pattern'
|
21
|
+
require 'geo_pattern/pattern/plus_sign_pattern'
|
22
|
+
require 'geo_pattern/pattern/sine_wave_pattern'
|
23
|
+
require 'geo_pattern/pattern/square_pattern'
|
24
|
+
require 'geo_pattern/pattern/tessellation_pattern'
|
25
|
+
require 'geo_pattern/pattern/triangle_pattern'
|
26
|
+
require 'geo_pattern/pattern/xes_pattern'
|
27
|
+
|
28
|
+
require 'geo_pattern/pattern_generator'
|
5
29
|
|
6
30
|
module GeoPattern
|
7
31
|
def self.generate(string=Time.now, opts={})
|
data/lib/geo_pattern/svg.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module GeoPattern
|
2
2
|
class SVG
|
3
|
+
include Comparable
|
4
|
+
|
3
5
|
def initialize
|
4
6
|
@width = 100
|
5
7
|
@height = 100
|
@@ -67,5 +69,9 @@ module GeoPattern
|
|
67
69
|
def self.as_comment(str)
|
68
70
|
"<!-- #{str} -->"
|
69
71
|
end
|
72
|
+
|
73
|
+
def <=>(other)
|
74
|
+
to_s <=> other.to_s
|
75
|
+
end
|
70
76
|
end
|
71
77
|
end
|
data/lib/geo_pattern/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe GeoPattern do
|
5
|
+
let(:string) { 'Mastering Markdown' }
|
6
|
+
|
7
|
+
context '.generate' do
|
8
|
+
it 'generates a pattern for a string' do
|
9
|
+
pattern = GeoPattern.generate(string)
|
10
|
+
expect(pattern).not_to be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'is always the same' do
|
14
|
+
pattern1 = GeoPattern.generate(string)
|
15
|
+
pattern2 = GeoPattern.generate(string)
|
16
|
+
|
17
|
+
expect(pattern1.svg_string).to eq pattern2.svg_string
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets background color with adjusting hue and saturation based on string' do
|
21
|
+
html_base_color = '#fc0'
|
22
|
+
rgb_base_color = html_to_rgb_for_string(string, html_base_color)
|
23
|
+
pattern = GeoPattern.generate(string, base_color: html_base_color)
|
24
|
+
|
25
|
+
expect(pattern.svg_string).to include(rgb_base_color)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets background color' do
|
29
|
+
html_base_color = '#fc0'
|
30
|
+
rgb_base_color = html_to_rgb(html_base_color)
|
31
|
+
pattern = GeoPattern.generate(string, color: html_base_color)
|
32
|
+
|
33
|
+
expect(pattern.svg_string).to include(rgb_base_color)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'uses the specified generator' do
|
37
|
+
|
38
|
+
pattern1 = GeoPattern.generate(string, generator: GeoPattern::SineWavePattern)
|
39
|
+
pattern2 = GeoPattern.generate(string)
|
40
|
+
|
41
|
+
expect(pattern1.svg_string).not_to eq pattern2.svg_string
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.command_name 'rspec'
|
6
|
+
SimpleCov.start
|
7
|
+
|
8
|
+
# Pull in all of the gems including those in the `test` group
|
9
|
+
require 'bundler'
|
10
|
+
Bundler.require :default, :test, :development
|
11
|
+
|
12
|
+
require 'geo_pattern'
|
13
|
+
|
14
|
+
# Make some helpers available
|
15
|
+
include GeoPattern::Helpers
|
16
|
+
|
17
|
+
# Loading support files
|
18
|
+
#::File.expand_path('../support/*.rb', __FILE__)
|
19
|
+
require_files_matching_pattern ::File.expand_path('../support/*.rb', __FILE__)
|
20
|
+
require_files_matching_pattern ::File.expand_path('../shared_examples/*.rb', __FILE__)
|
21
|
+
|
22
|
+
# No need to add the namespace to every class tested
|
23
|
+
include GeoPattern
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'aruba/api'
|
3
|
+
require 'aruba/reporting'
|
4
|
+
|
5
|
+
# Spec Helpers
|
6
|
+
module SpecHelper
|
7
|
+
# Helpers for aruba
|
8
|
+
module Aruba
|
9
|
+
include ::Aruba::Api
|
10
|
+
|
11
|
+
def dirs
|
12
|
+
@dirs ||= %w(tmp rspec)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec.configure do |c|
|
18
|
+
c.include SpecHelper::Aruba
|
19
|
+
|
20
|
+
c.before :each do
|
21
|
+
clean_current_dir
|
22
|
+
restore_env
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SpecHelpers
|
2
|
+
def html_to_rgb(color)
|
3
|
+
generate_rgb_string(Color::RGB.from_html(color))
|
4
|
+
end
|
5
|
+
|
6
|
+
def html_to_rgb_for_string(string, base_color)
|
7
|
+
hash = Digest::SHA1.hexdigest string
|
8
|
+
|
9
|
+
hue_offset = GeoPattern::PatternHelpers.map(GeoPattern::PatternHelpers.hex_val(hash, 14, 3), 0, 4095, 0, 359)
|
10
|
+
sat_offset = GeoPattern::PatternHelpers.hex_val(hash, 17, 1)
|
11
|
+
base_color = Color::RGB.from_html(base_color).to_hsl
|
12
|
+
base_color.hue = base_color.hue - hue_offset;
|
13
|
+
|
14
|
+
if (sat_offset % 2 == 0)
|
15
|
+
base_color.saturation = base_color.saturation + sat_offset
|
16
|
+
else
|
17
|
+
base_color.saturation = base_color.saturation - sat_offset
|
18
|
+
end
|
19
|
+
|
20
|
+
generate_rgb_string(base_color.to_rgb)
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate_rgb_string(rgb)
|
24
|
+
r = (rgb.r * 255).round
|
25
|
+
g = (rgb.g * 255).round
|
26
|
+
b = (rgb.b * 255).round
|
27
|
+
|
28
|
+
format("rgb(%d, %d, %d)", r, g, b)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec.configure do |config|
|
33
|
+
config.include SpecHelpers
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.expect_with :rspec do |expectations|
|
3
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
4
|
+
end
|
5
|
+
|
6
|
+
config.mock_with :rspec do |mocks|
|
7
|
+
mocks.verify_partial_doubles = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.filter_run :focus
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
|
13
|
+
config.disable_monkey_patching!
|
14
|
+
config.warnings = false
|
15
|
+
|
16
|
+
if config.files_to_run.one?
|
17
|
+
config.default_formatter = 'doc'
|
18
|
+
end
|
19
|
+
|
20
|
+
config.profile_examples = 10
|
21
|
+
|
22
|
+
config.order = :random
|
23
|
+
Kernel.srand config.seed
|
24
|
+
end
|
data/spec/svg_spec.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geo_pattern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Long
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: color
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.5'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
description: Generate SVG beautiful patterns
|
56
42
|
email:
|
57
43
|
- jlong@github.com
|
@@ -60,12 +46,15 @@ extensions: []
|
|
60
46
|
extra_rdoc_files: []
|
61
47
|
files:
|
62
48
|
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
63
51
|
- Gemfile
|
64
52
|
- LICENSE.txt
|
65
53
|
- README.md
|
66
54
|
- Rakefile
|
67
55
|
- geo_pattern.gemspec
|
68
56
|
- lib/geo_pattern.rb
|
57
|
+
- lib/geo_pattern/helpers.rb
|
69
58
|
- lib/geo_pattern/pattern/base_pattern.rb
|
70
59
|
- lib/geo_pattern/pattern/chevron_pattern.rb
|
71
60
|
- lib/geo_pattern/pattern/concentric_circles_pattern.rb
|
@@ -76,7 +65,6 @@ files:
|
|
76
65
|
- lib/geo_pattern/pattern/octagon_pattern.rb
|
77
66
|
- lib/geo_pattern/pattern/overlapping_circles_pattern.rb
|
78
67
|
- lib/geo_pattern/pattern/overlapping_rings_pattern.rb
|
79
|
-
- lib/geo_pattern/pattern/pattern_helpers.rb
|
80
68
|
- lib/geo_pattern/pattern/plaid_pattern.rb
|
81
69
|
- lib/geo_pattern/pattern/plus_sign_pattern.rb
|
82
70
|
- lib/geo_pattern/pattern/sine_wave_pattern.rb
|
@@ -85,8 +73,16 @@ files:
|
|
85
73
|
- lib/geo_pattern/pattern/triangle_pattern.rb
|
86
74
|
- lib/geo_pattern/pattern/xes_pattern.rb
|
87
75
|
- lib/geo_pattern/pattern_generator.rb
|
76
|
+
- lib/geo_pattern/pattern_helpers.rb
|
88
77
|
- lib/geo_pattern/svg.rb
|
89
78
|
- lib/geo_pattern/version.rb
|
79
|
+
- spec/geo_pattern_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- spec/support/aruba.rb
|
82
|
+
- spec/support/helpers.rb
|
83
|
+
- spec/support/rspec.rb
|
84
|
+
- spec/support/string.rb
|
85
|
+
- spec/svg_spec.rb
|
90
86
|
homepage: https://github.com/jasonlong/geo_pattern
|
91
87
|
licenses:
|
92
88
|
- MIT
|
@@ -111,4 +107,12 @@ rubygems_version: 2.2.0
|
|
111
107
|
signing_key:
|
112
108
|
specification_version: 4
|
113
109
|
summary: Generate SVG beautiful patterns
|
114
|
-
test_files:
|
110
|
+
test_files:
|
111
|
+
- spec/geo_pattern_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/support/aruba.rb
|
114
|
+
- spec/support/helpers.rb
|
115
|
+
- spec/support/rspec.rb
|
116
|
+
- spec/support/string.rb
|
117
|
+
- spec/svg_spec.rb
|
118
|
+
has_rdoc:
|