geo_pattern 1.4.0 → 1.6.0
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 +5 -5
- data/CHANGELOG.md +24 -0
- data/README.md +80 -16
- data/lib/geo_pattern/background.rb +9 -7
- data/lib/geo_pattern/background_generators/solid_generator.rb +4 -2
- data/lib/geo_pattern/color.rb +3 -1
- data/lib/geo_pattern/color_generators/base_color_generator.rb +10 -15
- data/lib/geo_pattern/color_generators/simple_generator.rb +2 -0
- data/lib/geo_pattern/color_preset.rb +7 -1
- data/lib/geo_pattern/errors.rb +2 -0
- data/lib/geo_pattern/geo_pattern_task.rb +11 -9
- data/lib/geo_pattern/helpers.rb +7 -5
- data/lib/geo_pattern/pattern.rb +6 -4
- data/lib/geo_pattern/pattern_generator.rb +14 -12
- data/lib/geo_pattern/pattern_helpers.rb +29 -11
- data/lib/geo_pattern/pattern_preset.rb +3 -1
- data/lib/geo_pattern/pattern_sieve.rb +5 -3
- data/lib/geo_pattern/pattern_store.rb +20 -18
- data/lib/geo_pattern/pattern_validator.rb +4 -2
- data/lib/geo_pattern/rake_task.rb +19 -16
- data/lib/geo_pattern/roles/comparable_metadata.rb +3 -1
- data/lib/geo_pattern/roles/named_generator.rb +3 -1
- data/lib/geo_pattern/seed.rb +2 -0
- data/lib/geo_pattern/structure.rb +9 -7
- data/lib/geo_pattern/structure_generators/base_generator.rb +17 -14
- data/lib/geo_pattern/structure_generators/chevrons_generator.rb +19 -17
- data/lib/geo_pattern/structure_generators/concentric_circles_generator.rb +19 -17
- data/lib/geo_pattern/structure_generators/diamonds_generator.rb +23 -17
- data/lib/geo_pattern/structure_generators/hexagons_generator.rb +25 -23
- data/lib/geo_pattern/structure_generators/mosaic_squares_generator.rb +35 -35
- data/lib/geo_pattern/structure_generators/nested_squares_generator.rb +23 -21
- data/lib/geo_pattern/structure_generators/octagons_generator.rb +12 -11
- data/lib/geo_pattern/structure_generators/overlapping_circles_generator.rb +13 -11
- data/lib/geo_pattern/structure_generators/overlapping_rings_generator.rb +15 -13
- data/lib/geo_pattern/structure_generators/plaid_generator.rb +18 -18
- data/lib/geo_pattern/structure_generators/plus_signs_generator.rb +24 -18
- data/lib/geo_pattern/structure_generators/sine_waves_generator.rb +17 -15
- data/lib/geo_pattern/structure_generators/squares_generator.rb +10 -9
- data/lib/geo_pattern/structure_generators/tessellation_generator.rb +36 -34
- data/lib/geo_pattern/structure_generators/triangles_generator.rb +22 -19
- data/lib/geo_pattern/structure_generators/xes_generator.rb +26 -19
- data/lib/geo_pattern/svg_image.rb +10 -8
- data/lib/geo_pattern/version.rb +3 -1
- data/lib/geo_pattern.rb +53 -51
- metadata +61 -139
- data/.gitignore +0 -18
- data/.rspec +0 -3
- data/.rubocop.yml +0 -71
- data/.simplecov +0 -25
- data/.travis.yml +0 -12
- data/Gemfile +0 -26
- data/Rakefile +0 -86
- data/fixtures/generated_patterns/chevrons.svg +0 -1
- data/fixtures/generated_patterns/concentric_circles.svg +0 -1
- data/fixtures/generated_patterns/diamonds.svg +0 -1
- data/fixtures/generated_patterns/diamonds_with_base_color.svg +0 -1
- data/fixtures/generated_patterns/diamonds_with_color.svg +0 -1
- data/fixtures/generated_patterns/hexagons.svg +0 -1
- data/fixtures/generated_patterns/mosaic_squares.svg +0 -1
- data/fixtures/generated_patterns/nested_squares.svg +0 -1
- data/fixtures/generated_patterns/octagons.svg +0 -1
- data/fixtures/generated_patterns/overlapping_circles.svg +0 -1
- data/fixtures/generated_patterns/overlapping_rings.svg +0 -1
- data/fixtures/generated_patterns/plaid.svg +0 -1
- data/fixtures/generated_patterns/plus_signs.svg +0 -1
- data/fixtures/generated_patterns/sine_waves.svg +0 -1
- data/fixtures/generated_patterns/squares.svg +0 -1
- data/fixtures/generated_patterns/tessellation.svg +0 -1
- data/fixtures/generated_patterns/triangles.svg +0 -1
- data/fixtures/generated_patterns/xes.svg +0 -1
- data/geo_pattern.gemspec +0 -29
- data/script/bootstrap +0 -30
- data/script/console +0 -8
- data/script/test +0 -21
- data/spec/background_generators/solid_generator_spec.rb +0 -50
- data/spec/background_spec.rb +0 -25
- data/spec/color_generators/base_color_generator_spec.rb +0 -31
- data/spec/color_generators/simple_generator_spec.rb +0 -12
- data/spec/color_preset_spec.rb +0 -53
- data/spec/color_spec.rb +0 -15
- data/spec/geo_pattern_spec.rb +0 -115
- data/spec/helpers_spec.rb +0 -65
- data/spec/pattern_preset_spec.rb +0 -41
- data/spec/pattern_sieve_spec.rb +0 -66
- data/spec/pattern_spec.rb +0 -72
- data/spec/pattern_store_spec.rb +0 -47
- data/spec/pattern_validator_spec.rb +0 -28
- data/spec/seed_spec.rb +0 -14
- data/spec/spec_helper.rb +0 -18
- data/spec/structure_generators/chevrons_generator_spec.rb +0 -5
- data/spec/structure_generators/concentric_circles_generator_spec.rb +0 -5
- data/spec/structure_generators/diamonds_generator_spec.rb +0 -5
- data/spec/structure_generators/hexagons_generator_spec.rb +0 -5
- data/spec/structure_generators/mosaic_squares_generator_spec.rb +0 -5
- data/spec/structure_generators/nested_squares_generator_spec.rb +0 -5
- data/spec/structure_generators/octagons_generator_spec.rb +0 -5
- data/spec/structure_generators/overlapping_circles_generator_spec.rb +0 -5
- data/spec/structure_generators/overlapping_rings_generator_spec.rb +0 -5
- data/spec/structure_generators/plaid_generator_spec.rb +0 -5
- data/spec/structure_generators/plus_signs_generator_spec.rb +0 -5
- data/spec/structure_generators/sine_waves_generator_spec.rb +0 -5
- data/spec/structure_generators/squares_generator_spec.rb +0 -5
- data/spec/structure_generators/tessellation_generator_spec.rb +0 -5
- data/spec/structure_generators/triangles_generator_spec.rb +0 -5
- data/spec/structure_generators/xes_generator_spec.rb +0 -5
- data/spec/structure_spec.rb +0 -38
- data/spec/support/aruba.rb +0 -24
- data/spec/support/helpers/fixtures.rb +0 -12
- data/spec/support/kernel.rb +0 -40
- data/spec/support/matchers/image.rb +0 -17
- data/spec/support/matchers/name.rb +0 -15
- data/spec/support/rspec.rb +0 -24
- data/spec/support/shared_examples/generator.rb +0 -46
- data/spec/support/shared_examples/pattern.rb +0 -31
- data/spec/support/shared_examples/pattern_name.rb +0 -7
- data/spec/support/shared_examples/structure.rb +0 -48
- data/spec/support/string.rb +0 -2
- data/spec/svg_spec.rb +0 -12
data/geo_pattern.gemspec
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require 'geo_pattern/version'
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name = 'geo_pattern'
|
|
8
|
-
spec.version = GeoPattern::VERSION
|
|
9
|
-
spec.authors = ['Jason Long']
|
|
10
|
-
spec.email = ['jlong@github.com']
|
|
11
|
-
spec.summary = 'Generate SVG beautiful patterns'
|
|
12
|
-
spec.description = 'Generate SVG beautiful patterns'
|
|
13
|
-
spec.homepage = 'https://github.com/jasonlong/geo_pattern'
|
|
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.required_ruby_version = '~>2'
|
|
22
|
-
|
|
23
|
-
spec.add_dependency 'color', '~> 1.5'
|
|
24
|
-
spec.add_development_dependency 'bundler', '~> 1.5'
|
|
25
|
-
|
|
26
|
-
spec.post_install_message = <<-EOS
|
|
27
|
-
Class style pattern names are deprecated as of 1.3.1
|
|
28
|
-
EOS
|
|
29
|
-
end
|
data/script/bootstrap
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
set -e
|
|
4
|
-
|
|
5
|
-
info_msg="\e[0;32m[INFO]\e[0;30m"
|
|
6
|
-
error_msg="\e[0;31mFAILED\e[0;30m"
|
|
7
|
-
|
|
8
|
-
function output_error_log {
|
|
9
|
-
[[ -f error.log ]] && ( cat error.log >&2; rm error.log)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
echo -ne "$info_msg Checking if ruby installed? "
|
|
13
|
-
which 'ruby' >/dev/null 2>error.log || ( echo -e "$error_msg\n\nCould not find \`ruby\`. Please install ruby or add it to PATH"; output_error_log; exit 1 )
|
|
14
|
-
echo OK
|
|
15
|
-
|
|
16
|
-
echo -en "$info_msg rubygem \"rake\" "
|
|
17
|
-
gem install rake >/dev/null 2>error.log || ( echo -e "$error_msg\n\nAn error occurred during installation of rake. Run \`gem install rake\` yourself."; output_error_log; exit 1 )
|
|
18
|
-
echo OK
|
|
19
|
-
|
|
20
|
-
if [ -n "$CI" ]; then
|
|
21
|
-
echo -e "$info_msg Bootstrapping in CI mode"
|
|
22
|
-
rake_task='bootstrap:ci'
|
|
23
|
-
else
|
|
24
|
-
echo -e "$info_msg Bootstrapping in normal mode"
|
|
25
|
-
rake_task='bootstrap'
|
|
26
|
-
fi
|
|
27
|
-
|
|
28
|
-
echo -en "$info_msg Running rake task \"$rake_task\" "
|
|
29
|
-
rake --trace $rake_task >error.log 2>&1 || ( echo -e "$error_msg\n\nAn error occurred during run of rake-task \"$rake_task\". Run \`rake $rake_task\` yourself."; output_error_log; exit 1 )
|
|
30
|
-
echo OK
|
data/script/console
DELETED
data/script/test
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
set -e
|
|
4
|
-
|
|
5
|
-
function output_error_log {
|
|
6
|
-
[[ -f error.log ]] && ( cat error.log >&2; rm error.log)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
info_msg="\e[0;32m[INFO]\e[0;30m"
|
|
10
|
-
error_msg="\e[0;31mFAILED\e[0;30m"
|
|
11
|
-
|
|
12
|
-
if [ -n "$CI" ]; then
|
|
13
|
-
echo -e "$info_msg Testing in CI mode"
|
|
14
|
-
rake_task='test:ci'
|
|
15
|
-
else
|
|
16
|
-
echo -e "$info_msg Testing in normal mode"
|
|
17
|
-
rake_task='test'
|
|
18
|
-
fi
|
|
19
|
-
|
|
20
|
-
echo -en "$info_msg Running rake task \"$rake_task\" "
|
|
21
|
-
bundle exec rake --trace $rake_task
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe BackgroundGenerators::SolidGenerator do
|
|
4
|
-
subject(:generator) { described_class.new(seed, preset) }
|
|
5
|
-
|
|
6
|
-
let(:seed) { instance_double('GeoPattern::Seed') }
|
|
7
|
-
let(:preset) { instance_double('GeoPattern::ColorPreset') }
|
|
8
|
-
let(:pattern) { instance_double('GeoPattern::Pattern') }
|
|
9
|
-
let(:background_metadata) { instance_double('GeoPattern::BackgroundMetadata') }
|
|
10
|
-
|
|
11
|
-
let(:color) { '#aaaaaa' }
|
|
12
|
-
let(:base_color) { '#bbbbbb' }
|
|
13
|
-
let(:base_color_should_be_used) { true }
|
|
14
|
-
|
|
15
|
-
before :each do
|
|
16
|
-
allow(seed).to receive(:to_i).with(14, 3).and_return(2616)
|
|
17
|
-
allow(seed).to receive(:to_i).with(17, 1).and_return(3)
|
|
18
|
-
|
|
19
|
-
allow(preset).to receive(:mode?).with(:base_color).and_return(base_color_should_be_used)
|
|
20
|
-
allow(preset).to receive(:color).and_return(color)
|
|
21
|
-
allow(preset).to receive(:base_color).and_return(base_color)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it { is_expected.not_to be_nil }
|
|
25
|
-
|
|
26
|
-
describe '#generate' do
|
|
27
|
-
context 'when base color is given' do
|
|
28
|
-
let(:generated_color) { %w(187 187 187) }
|
|
29
|
-
|
|
30
|
-
before :each do
|
|
31
|
-
expect(pattern).to receive(:background=).with(have_image_with_rgb_color(generated_color))
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it { generator.generate(pattern) }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'when color is given' do
|
|
38
|
-
let(:base_color_should_be_used) { false }
|
|
39
|
-
let(:generated_color) { %w(170 170 170) }
|
|
40
|
-
|
|
41
|
-
before :each do
|
|
42
|
-
expect(pattern).to receive(:background=).with(have_image_with_rgb_color(generated_color))
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it { generator.generate(pattern) }
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it_behaves_like 'a named generator', :solid
|
|
49
|
-
end
|
|
50
|
-
end
|
data/spec/background_spec.rb
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Background do
|
|
4
|
-
subject(:metadata) { described_class.new(image: svg_image, preset: preset, generator: generator, color: color) }
|
|
5
|
-
|
|
6
|
-
let(:svg_image) { instance_double('GeoPattern::SvgImage') }
|
|
7
|
-
let(:svg_image_content) { fixtures_path('generated_patterns/sine_waves.svg').read.chomp }
|
|
8
|
-
let(:preset) { instance_double('GeoPattern::ColorPreset') }
|
|
9
|
-
let(:generator) { stub_const('GeoPattern::BackgroundGenerators::SolidGenerator', Class.new) }
|
|
10
|
-
|
|
11
|
-
let(:color) { '#aaaaaa' }
|
|
12
|
-
let(:base_color) { '#bbbbbb' }
|
|
13
|
-
|
|
14
|
-
it { is_expected.not_to be_nil }
|
|
15
|
-
|
|
16
|
-
before :each do
|
|
17
|
-
allow(preset).to receive(:color).and_return(color)
|
|
18
|
-
allow(preset).to receive(:base_color).and_return(base_color)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it_behaves_like 'a metadata argument', :color
|
|
22
|
-
it_behaves_like 'a metadata argument', :generator
|
|
23
|
-
it_behaves_like 'a forwarded metadata argument', :base_color
|
|
24
|
-
it_behaves_like 'a forwarded metadata argument', :color
|
|
25
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe ColorGenerators::BaseColorGenerator do
|
|
4
|
-
subject(:generator) { described_class.new(color_string, seed) }
|
|
5
|
-
|
|
6
|
-
let(:seed) { instance_double('GeoPattern::Seed') }
|
|
7
|
-
let(:seed_value1) { 2616 }
|
|
8
|
-
let(:seed_value2) { 2 }
|
|
9
|
-
|
|
10
|
-
let(:color_string) { '#ff00ff' }
|
|
11
|
-
|
|
12
|
-
it { is_expected.not_to be_nil }
|
|
13
|
-
|
|
14
|
-
before :each do
|
|
15
|
-
allow(seed).to receive(:to_i).with(14, 3).and_return(seed_value1)
|
|
16
|
-
allow(seed).to receive(:to_i).with(17, 1).and_return(seed_value2)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe '#generate' do
|
|
20
|
-
let(:color) { generator.generate }
|
|
21
|
-
|
|
22
|
-
context 'when sat offset is % 2 == 0' do
|
|
23
|
-
it { expect(color.to_svg).to eq 'rgb(210, 255, 0)' }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context 'when sat offset is not % 2 == 0' do
|
|
27
|
-
let(:seed_value2) { 3 }
|
|
28
|
-
it { expect(color.to_svg).to eq 'rgb(207, 251, 4)' }
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
RSpec.describe ColorGenerators::SimpleGenerator do
|
|
2
|
-
subject(:generator) { described_class.new(color_string) }
|
|
3
|
-
|
|
4
|
-
let(:color_string) { '#ff00ff' }
|
|
5
|
-
|
|
6
|
-
it { is_expected.not_to be_nil }
|
|
7
|
-
|
|
8
|
-
describe '#generate' do
|
|
9
|
-
let(:color) { generator.generate }
|
|
10
|
-
it { expect(color.to_svg).to eq 'rgb(255, 0, 255)' }
|
|
11
|
-
end
|
|
12
|
-
end
|
data/spec/color_preset_spec.rb
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe ColorPreset do
|
|
4
|
-
subject(:preset) { ColorPreset.new(**options) }
|
|
5
|
-
let(:options) do
|
|
6
|
-
{
|
|
7
|
-
base_color: '#0f0f0f'
|
|
8
|
-
}
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it { expect(preset).not_to be nil }
|
|
12
|
-
|
|
13
|
-
describe '#base_color' do
|
|
14
|
-
it { expect(preset.base_color).to eq '#0f0f0f' }
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe '#color' do
|
|
18
|
-
context 'when set' do
|
|
19
|
-
let(:options) do
|
|
20
|
-
{
|
|
21
|
-
base_color: '#0f0f0f',
|
|
22
|
-
color: '#1f1f1f'
|
|
23
|
-
}
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it { expect(preset.color).to eq '#1f1f1f' }
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe '#mode?' do
|
|
31
|
-
context 'when nil' do
|
|
32
|
-
let(:options) do
|
|
33
|
-
{
|
|
34
|
-
base_color: '#0f0f0f',
|
|
35
|
-
color: nil
|
|
36
|
-
}
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it { expect(preset).to be_mode :base_color }
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
context 'when defined' do
|
|
43
|
-
let(:options) do
|
|
44
|
-
{
|
|
45
|
-
base_color: '#0f0f0f',
|
|
46
|
-
color: '#1f1f1f'
|
|
47
|
-
}
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it { expect(preset).to be_mode :color }
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
data/spec/color_spec.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe GeoPattern::Color do
|
|
4
|
-
subject(:color) { described_class.new(color_string) }
|
|
5
|
-
let(:color_string) { '#ff00ff' }
|
|
6
|
-
let(:seed) { instance_double('GeoPattern::Seed') }
|
|
7
|
-
|
|
8
|
-
describe '#to_svg' do
|
|
9
|
-
it { expect(color.to_svg).to eq 'rgb(255, 0, 255)' }
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe '#to_html' do
|
|
13
|
-
it { expect(color.to_html).to eq color_string }
|
|
14
|
-
end
|
|
15
|
-
end
|
data/spec/geo_pattern_spec.rb
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require 'spec_helper'
|
|
3
|
-
|
|
4
|
-
RSpec.describe GeoPattern do
|
|
5
|
-
subject(:pattern) { GeoPattern.generate(input) }
|
|
6
|
-
let(:input) { 'Mastering Markdown' }
|
|
7
|
-
let(:color) { '#ffcc00' }
|
|
8
|
-
let(:rgb_base_color) { PatternHelpers.html_to_rgb_for_string(seed, color) }
|
|
9
|
-
let(:seed) { instance_double('GeoPattern::Seed') }
|
|
10
|
-
|
|
11
|
-
before :each do
|
|
12
|
-
allow(seed).to receive(:to_i).with(14, 3).and_return(2616)
|
|
13
|
-
allow(seed).to receive(:to_i).with(17, 1).and_return(3)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it { expect(pattern).not_to be_nil }
|
|
17
|
-
|
|
18
|
-
describe '.generate' do
|
|
19
|
-
context 'when invoked with the same input it returns the same output' do
|
|
20
|
-
let(:other_pattern) { GeoPattern.generate(input) }
|
|
21
|
-
it { expect(pattern.to_svg).to eq other_pattern.to_svg }
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
context 'when an invalid option is given' do
|
|
25
|
-
subject(:pattern) { GeoPattern.generate(input, **args) }
|
|
26
|
-
let(:args) { { unknown: true } }
|
|
27
|
-
|
|
28
|
-
it { expect { pattern }.to raise_error ArgumentError }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context 'set background color of generated pattern' do
|
|
32
|
-
let(:new_color) { '#ffcc00' }
|
|
33
|
-
|
|
34
|
-
context 'when a base color is set' do
|
|
35
|
-
subject(:pattern) { GeoPattern.generate(input, base_color: color) }
|
|
36
|
-
let(:new_color) { '#04fbf6' }
|
|
37
|
-
|
|
38
|
-
it { expect(pattern.background.color.to_html).to eq(new_color) }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
context 'when a color is set' do
|
|
42
|
-
subject(:pattern) { GeoPattern.generate(input, color: color) }
|
|
43
|
-
|
|
44
|
-
it { expect(pattern.background.color.to_html).to eq(new_color) }
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context 'specify the pattern' do
|
|
49
|
-
subject(:pattern) { GeoPattern.generate(input, patterns: chosen_pattern) }
|
|
50
|
-
|
|
51
|
-
let(:chosen_pattern) { :sine_waves }
|
|
52
|
-
|
|
53
|
-
context 'when the deprecated generator option is used' do
|
|
54
|
-
subject(:pattern) { GeoPattern.generate(input, generator: chosen_pattern) }
|
|
55
|
-
subject(:other_pattern) { GeoPattern.generate(input, patterns: chosen_pattern) }
|
|
56
|
-
|
|
57
|
-
it { expect { pattern.to_svg }.to output(/deprecated/).to_stderr }
|
|
58
|
-
it { silence(:stderr) { expect(pattern.to_svg).to eq other_pattern.to_svg } }
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
context 'when multiple patterns are selected' do
|
|
62
|
-
let(:chosen_pattern) { [:sine_waves, :xes] }
|
|
63
|
-
|
|
64
|
-
it { expect(pattern.structure.name).to eq(:sine_waves).or eq(:xes) }
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
context 'when an old style pattern was chosen via class name' do
|
|
68
|
-
it_behaves_like 'an old style pattern', ChevronPattern, :chevrons
|
|
69
|
-
it_behaves_like 'an old style pattern', ConcentricCirclesPattern, :concentric_circles
|
|
70
|
-
it_behaves_like 'an old style pattern', DiamondPattern, :diamonds
|
|
71
|
-
it_behaves_like 'an old style pattern', HexagonPattern, :hexagons
|
|
72
|
-
it_behaves_like 'an old style pattern', MosaicSquaresPattern, :mosaic_squares
|
|
73
|
-
it_behaves_like 'an old style pattern', NestedSquaresPattern, :nested_squares
|
|
74
|
-
it_behaves_like 'an old style pattern', OctagonPattern, :octagons
|
|
75
|
-
it_behaves_like 'an old style pattern', OverlappingCirclesPattern, :overlapping_circles
|
|
76
|
-
it_behaves_like 'an old style pattern', OverlappingRingsPattern, :overlapping_rings
|
|
77
|
-
it_behaves_like 'an old style pattern', PlaidPattern, :plaid
|
|
78
|
-
it_behaves_like 'an old style pattern', PlusSignPattern, :plus_signs
|
|
79
|
-
it_behaves_like 'an old style pattern', SineWavePattern, :sine_waves
|
|
80
|
-
it_behaves_like 'an old style pattern', SquarePattern, :squares
|
|
81
|
-
it_behaves_like 'an old style pattern', TessellationPattern, :tessellation
|
|
82
|
-
it_behaves_like 'an old style pattern', TrianglePattern, :triangles
|
|
83
|
-
it_behaves_like 'an old style pattern', XesPattern, :xes
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
context 'when an valid pattern was chosen' do
|
|
87
|
-
it_behaves_like 'a chosen pattern', :chevrons
|
|
88
|
-
it_behaves_like 'a chosen pattern', :concentric_circles
|
|
89
|
-
it_behaves_like 'a chosen pattern', :diamonds
|
|
90
|
-
it_behaves_like 'a chosen pattern', :hexagons
|
|
91
|
-
it_behaves_like 'a chosen pattern', :mosaic_squares
|
|
92
|
-
it_behaves_like 'a chosen pattern', :nested_squares
|
|
93
|
-
it_behaves_like 'a chosen pattern', :octagons
|
|
94
|
-
it_behaves_like 'a chosen pattern', :overlapping_circles
|
|
95
|
-
it_behaves_like 'a chosen pattern', :overlapping_rings
|
|
96
|
-
it_behaves_like 'a chosen pattern', :plaid
|
|
97
|
-
it_behaves_like 'a chosen pattern', :plus_signs
|
|
98
|
-
it_behaves_like 'a chosen pattern', :sine_waves
|
|
99
|
-
it_behaves_like 'a chosen pattern', :squares
|
|
100
|
-
it_behaves_like 'a chosen pattern', :tessellation
|
|
101
|
-
it_behaves_like 'a chosen pattern', :triangles
|
|
102
|
-
it_behaves_like 'a chosen pattern', :xes
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
context 'when invalid patterns were chosen' do
|
|
106
|
-
InvalidPatternClass = Class.new
|
|
107
|
-
|
|
108
|
-
it_behaves_like 'an invalid pattern', InvalidPatternClass
|
|
109
|
-
it_behaves_like 'an invalid pattern', 'invalid_pattern'
|
|
110
|
-
it_behaves_like 'an invalid pattern', :invalid_pattern
|
|
111
|
-
it_behaves_like 'an invalid pattern', [:sine_waves, 'invalid_pattern']
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
data/spec/helpers_spec.rb
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Helpers do
|
|
4
|
-
describe '.underscore' do
|
|
5
|
-
subject { described_class.underscore string }
|
|
6
|
-
|
|
7
|
-
context 'when string is empty' do
|
|
8
|
-
let(:string) { '' }
|
|
9
|
-
|
|
10
|
-
it { is_expected.to eq '' }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
context 'when string is in snakecase' do
|
|
14
|
-
let(:string) { 'HelloWorld' }
|
|
15
|
-
|
|
16
|
-
it { is_expected.to eq 'hello_world' }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context 'when string is in snakecase at some places' do
|
|
20
|
-
let(:string) { 'helloWorld' }
|
|
21
|
-
|
|
22
|
-
it { is_expected.to eq 'hello_world' }
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe '.demodulize' do
|
|
27
|
-
subject { described_class.demodulize string }
|
|
28
|
-
|
|
29
|
-
context 'when constant' do
|
|
30
|
-
before :each do
|
|
31
|
-
stub_const('HelloWorld', Class.new)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
let(:string) { HelloWorld }
|
|
35
|
-
|
|
36
|
-
it { is_expected.to eq 'HelloWorld' }
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context 'when string' do
|
|
40
|
-
context 'is empty' do
|
|
41
|
-
let(:string) { '' }
|
|
42
|
-
|
|
43
|
-
it { is_expected.to eq '' }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'starts with ::' do
|
|
47
|
-
let(:string) { '::Class' }
|
|
48
|
-
|
|
49
|
-
it { is_expected.to eq 'Class' }
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context 'has :: in betweend' do
|
|
53
|
-
let(:string) { 'HelloWorld::Class' }
|
|
54
|
-
|
|
55
|
-
it { is_expected.to eq 'Class' }
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context 'when no namespaces is given' do
|
|
59
|
-
let(:string) { 'HelloWorld' }
|
|
60
|
-
|
|
61
|
-
it { is_expected.to eq 'HelloWorld' }
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
data/spec/pattern_preset_spec.rb
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe PatternPreset do
|
|
4
|
-
subject(:preset) { PatternPreset.new(options) }
|
|
5
|
-
let(:options) do
|
|
6
|
-
{
|
|
7
|
-
fill_color_dark: '#222',
|
|
8
|
-
fill_color_light: '#ddd',
|
|
9
|
-
stroke_color: '#000',
|
|
10
|
-
stroke_opacity: 0.02,
|
|
11
|
-
opacity_min: 0.02,
|
|
12
|
-
opacity_max: 0.15
|
|
13
|
-
}
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it { expect(preset).not_to be nil }
|
|
17
|
-
|
|
18
|
-
describe '#fill_color_dark' do
|
|
19
|
-
it { expect(preset.fill_color_dark).to eq '#222' }
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe '#fill_color_light' do
|
|
23
|
-
it { expect(preset.fill_color_light).to eq '#ddd' }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe '#stroke_color' do
|
|
27
|
-
it { expect(preset.stroke_color).to eq '#000' }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe '#stroke_opacity' do
|
|
31
|
-
it { expect(preset.stroke_opacity).to eq 0.02 }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
describe '#opacity_min' do
|
|
35
|
-
it { expect(preset.opacity_min).to eq 0.02 }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe '#opacity_max' do
|
|
39
|
-
it { expect(preset.opacity_max).to eq 0.15 }
|
|
40
|
-
end
|
|
41
|
-
end
|
data/spec/pattern_sieve_spec.rb
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe PatternSieve do
|
|
4
|
-
subject(:sieve) { PatternSieve.new(requested_patterns, seed, store) }
|
|
5
|
-
|
|
6
|
-
before :each do
|
|
7
|
-
stub_const('Pattern1', Class.new)
|
|
8
|
-
stub_const('Pattern2', Class.new)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
let(:store) { instance_double('GeoPattern::PatternStore') }
|
|
12
|
-
let(:available_patterns) { [Pattern1, Pattern2] }
|
|
13
|
-
let(:requested_patterns) { [:pattern1, :pattern2] }
|
|
14
|
-
let(:seed) { instance_double('GeoPattern::Seed') }
|
|
15
|
-
|
|
16
|
-
before :each do
|
|
17
|
-
allow(seed).to receive(:to_i).with(20, 1).and_return(1)
|
|
18
|
-
allow(store).to receive(:[])
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# Minimum valid object test
|
|
22
|
-
it { expect(sieve).not_to be_nil }
|
|
23
|
-
|
|
24
|
-
describe '#fetch' do
|
|
25
|
-
context 'when requested_patterns is empty' do
|
|
26
|
-
let(:requested_patterns) { nil }
|
|
27
|
-
|
|
28
|
-
before :each do
|
|
29
|
-
expect(store).to receive(:all).and_return(available_patterns)
|
|
30
|
-
expect(store).not_to receive(:[])
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it { expect(sieve.fetch).to eq Pattern2 }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context 'when a valid pattern is requested' do
|
|
37
|
-
let(:requested_patterns) { [:pattern1] }
|
|
38
|
-
|
|
39
|
-
before :each do
|
|
40
|
-
expect(store).to receive(:[]).with(:pattern1).and_return(Pattern1)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it { expect(sieve.fetch).to eq Pattern1 }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'when an invalid pattern is requested' do
|
|
47
|
-
let(:requested_patterns) { [:patternX] }
|
|
48
|
-
|
|
49
|
-
before :each do
|
|
50
|
-
allow(store).to receive(:[]).with(:patternX).and_return(nil)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it { expect(sieve.fetch).to be nil }
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
context 'when a requested pattern is nil' do
|
|
57
|
-
let(:requested_patterns) { [:pattern1, nil, :pattern2] }
|
|
58
|
-
|
|
59
|
-
before :each do
|
|
60
|
-
expect(store).not_to receive(:[]).with(nil)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it { sieve.fetch }
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
data/spec/pattern_spec.rb
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Pattern do
|
|
4
|
-
subject(:pattern) { Pattern.new(svg_image) }
|
|
5
|
-
|
|
6
|
-
let(:svg_image) { instance_double('GeoPattern::SvgImage') }
|
|
7
|
-
let(:svg_image_content) { fixtures_path('generated_patterns/sine_waves.svg').read.chomp }
|
|
8
|
-
let(:background) { instance_double('GeoPattern::Background') }
|
|
9
|
-
let(:background_image) { instance_double('GeoPattern::SvgImage') }
|
|
10
|
-
let(:background_body) { %(<rect x="0" y="0" width="100%" height="100%" fill="rgb(121, 131, 76)" />) }
|
|
11
|
-
let(:structure) { instance_double('GeoPattern::Structure') }
|
|
12
|
-
let(:structure_image) { instance_double('GeoPattern::SvgImage') }
|
|
13
|
-
let(:structure_body) { %(<path d=\"M0 53 C 28.0 0, 52.0 0, 80 53 S 132.0 106, 160 53 S 212.0 0, 240.0, 53\" fill=\"none\" stroke=\"#222\" style=\"opacity:0.046;stroke-width:6px;\" transform=\"translate(-40, -79.5)\" />) }
|
|
14
|
-
|
|
15
|
-
it { expect(pattern).not_to be_nil }
|
|
16
|
-
|
|
17
|
-
before :each do
|
|
18
|
-
allow(svg_image).to receive(:to_s).and_return svg_image_content
|
|
19
|
-
allow(svg_image).to receive(:height=).and_return 100
|
|
20
|
-
allow(svg_image).to receive(:width=).and_return 100
|
|
21
|
-
|
|
22
|
-
allow(background).to receive(:image).and_return background_image
|
|
23
|
-
|
|
24
|
-
allow(structure).to receive(:image).and_return structure_image
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe '#to_s' do
|
|
28
|
-
before :each do
|
|
29
|
-
allow(svg_image).to receive(:to_s).and_return(svg_image_content)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it { expect(pattern.to_s).to eq svg_image_content }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe '#to_base64' do
|
|
36
|
-
before :each do
|
|
37
|
-
allow(svg_image).to receive(:to_s).and_return(svg_image_content)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it { expect(pattern.to_base64).to include 'PHN2ZyB4bWxuc' }
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe '#to_data_uri' do
|
|
44
|
-
before :each do
|
|
45
|
-
allow(svg_image).to receive(:to_s).and_return(svg_image_content)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it { expect(pattern.to_data_uri).to include 'PHN2ZyB4bWxuc' }
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe '#generate_me' do
|
|
52
|
-
context 'when a background is added' do
|
|
53
|
-
let(:generator) { instance_double('GeoPattern::BackgroundGenerator') }
|
|
54
|
-
|
|
55
|
-
before :each do
|
|
56
|
-
expect(generator).to receive(:generate).with(pattern)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it do
|
|
60
|
-
pattern.generate_me(generator)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
describe '#include?' do
|
|
66
|
-
it do
|
|
67
|
-
expect(svg_image).to receive(:include?)
|
|
68
|
-
|
|
69
|
-
pattern.include? ''
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|