squib 0.0.4 → 0.0.5
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 +4 -4
 - data/.gitignore +1 -0
 - data/CHANGELOG.md +9 -0
 - data/README.md +38 -33
 - data/Rakefile +1 -1
 - data/bin/squib +6 -6
 - data/lib/squib.rb +8 -8
 - data/lib/squib/api/background.rb +3 -3
 - data/lib/squib/api/data.rb +5 -6
 - data/lib/squib/api/image.rb +13 -10
 - data/lib/squib/api/save.rb +4 -5
 - data/lib/squib/api/settings.rb +4 -4
 - data/lib/squib/api/shapes.rb +20 -20
 - data/lib/squib/api/text.rb +11 -11
 - data/lib/squib/api/units.rb +4 -4
 - data/lib/squib/card.rb +5 -5
 - data/lib/squib/commands/new.rb +5 -5
 - data/lib/squib/constants.rb +10 -10
 - data/lib/squib/deck.rb +24 -22
 - data/lib/squib/graphics/background.rb +3 -3
 - data/lib/squib/graphics/image.rb +13 -6
 - data/lib/squib/graphics/save_doc.rb +13 -11
 - data/lib/squib/graphics/save_images.rb +3 -3
 - data/lib/squib/graphics/shapes.rb +9 -8
 - data/lib/squib/graphics/text.rb +61 -59
 - data/lib/squib/input_helpers.rb +13 -13
 - data/lib/squib/progress.rb +4 -4
 - data/lib/squib/project_template/Gemfile +1 -1
 - data/lib/squib/project_template/deck.rb +3 -3
 - data/lib/squib/version.rb +6 -2
 - data/samples/autoscale_font.rb +4 -4
 - data/samples/basic.rb +6 -7
 - data/samples/cairo_access.rb +27 -0
 - data/samples/colors.rb +2 -2
 - data/samples/custom-layout.yml +5 -5
 - data/samples/custom_config.rb +4 -4
 - data/samples/draw_shapes.rb +8 -8
 - data/samples/hello_world.rb +2 -3
 - data/samples/load_images.rb +6 -1
 - data/samples/portrait-landscape.rb +7 -7
 - data/samples/ranges.rb +13 -14
 - data/samples/save_pdf.rb +2 -2
 - data/samples/text_options.rb +17 -17
 - data/samples/tgc_proofs.rb +3 -3
 - data/samples/use_layout.rb +3 -3
 - data/spec/api/api_text_spec.rb +11 -17
 - data/spec/commands/new_spec.rb +10 -10
 - data/spec/data/easy-circular-extends.yml +1 -1
 - data/spec/data/hard-circular-extends.yml +2 -2
 - data/spec/data/multi-extends-single-entry.yml +3 -3
 - data/spec/data/multi-level-extends.yml +1 -1
 - data/spec/data/no-extends.yml +2 -2
 - data/spec/data/pre-extends.yml +1 -1
 - data/spec/data/self-circular-extends.yml +1 -1
 - data/spec/data/single-extends.yml +1 -1
 - data/spec/data/single-level-multi-extends.yml +1 -1
 - data/spec/deck_spec.rb +62 -62
 - data/spec/graphics/graphics_images_spec.rb +79 -0
 - data/spec/graphics/graphics_save_doc_spec.rb +66 -0
 - data/spec/graphics/graphics_shapes_spec.rb +74 -0
 - data/spec/graphics/graphics_text_spec.rb +135 -0
 - data/spec/input_helpers_spec.rb +61 -40
 - data/spec/samples_run_spec.rb +6 -6
 - data/spec/spec_helper.rb +32 -1
 - data/squib.gemspec +21 -21
 - metadata +22 -14
 
    
        data/spec/commands/new_spec.rb
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'squib'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            describe  Squib::Commands::New do 
     | 
| 
      
 4 
     | 
    
         
            +
            describe  Squib::Commands::New do
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              describe  
     | 
| 
      
 6 
     | 
    
         
            +
              describe '#process' do
         
     | 
| 
       7 
7 
     | 
    
         
             
                before(:all) do
         
     | 
| 
       8 
8 
     | 
    
         
             
                  @old_stderr = $stderr
         
     | 
| 
       9 
9 
     | 
    
         
             
                  $stderr = StringIO.new
         
     | 
| 
       10 
10 
     | 
    
         
             
                  @oldpwd = Dir.pwd
         
     | 
| 
       11 
     | 
    
         
            -
                  Dir.chdir( 
     | 
| 
      
 11 
     | 
    
         
            +
                  Dir.chdir(output_dir)
         
     | 
| 
       12 
12 
     | 
    
         
             
                end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                before(:each) do
         
     | 
| 
         @@ -16,33 +16,33 @@ describe  Squib::Commands::New do 
     | 
|
| 
       16 
16 
     | 
    
         
             
                  @cmd = Squib::Commands::New.new
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                it  
     | 
| 
      
 19 
     | 
    
         
            +
                it 'raises an error if no directory was specified' do
         
     | 
| 
       20 
20 
     | 
    
         
             
                  expect{@cmd.process([])}.to raise_error(ArgumentError, 'Please specify a path.')
         
     | 
| 
       21 
21 
     | 
    
         
             
                end
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                it  
     | 
| 
      
 23 
     | 
    
         
            +
                it 'creates a new template on an fresh directory' do
         
     | 
| 
       24 
24 
     | 
    
         
             
                  @cmd.process(['foo'])
         
     | 
| 
       25 
25 
     | 
    
         
             
                  expect(File.exists?('foo/deck.rb')).to be true
         
     | 
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
                it  
     | 
| 
      
 28 
     | 
    
         
            +
                it 'creates a new template on an empty directory' do
         
     | 
| 
       29 
29 
     | 
    
         
             
                  Dir.mkdir('foo')
         
     | 
| 
       30 
30 
     | 
    
         
             
                  @cmd.process(['foo'])
         
     | 
| 
       31 
31 
     | 
    
         
             
                  expect(File.exists?('foo/deck.rb')).to be true
         
     | 
| 
       32 
32 
     | 
    
         
             
                end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                it  
     | 
| 
      
 34 
     | 
    
         
            +
                it 'does not create a new template on an empty ' do
         
     | 
| 
       35 
35 
     | 
    
         
             
                  Dir.mkdir('foo')
         
     | 
| 
       36 
36 
     | 
    
         
             
                  File.new('foo/somefile.txt', 'w+')
         
     | 
| 
       37 
37 
     | 
    
         
             
                  @cmd.process(['foo'])
         
     | 
| 
       38 
38 
     | 
    
         
             
                  $stderr.rewind
         
     | 
| 
       39 
     | 
    
         
            -
                  expect($stderr.string.chomp).to end_with  
     | 
| 
      
 39 
     | 
    
         
            +
                  expect($stderr.string.chomp).to end_with ' exists and is not empty. Doing nothing and quitting.'
         
     | 
| 
       40 
40 
     | 
    
         
             
                end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
                after(:all) do
         
     | 
| 
       43 
43 
     | 
    
         
             
                  $stderr = @old_stderr
         
     | 
| 
       44 
44 
     | 
    
         
             
                  Dir.chdir(@oldpwd)
         
     | 
| 
       45 
45 
     | 
    
         
             
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       46 
48 
     | 
    
         
             
            end
         
     | 
| 
       47 
     | 
    
         
            -
              
         
     | 
| 
       48 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/data/no-extends.yml
    CHANGED
    
    
    
        data/spec/data/pre-extends.yml
    CHANGED
    
    
    
        data/spec/deck_spec.rb
    CHANGED
    
    | 
         @@ -1,134 +1,134 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'squib/deck'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            describe Squib::Deck do 
     | 
| 
      
 4 
     | 
    
         
            +
            describe Squib::Deck do
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              it  
     | 
| 
       7 
     | 
    
         
            -
                d = Squib::Deck.new 
     | 
| 
      
 6 
     | 
    
         
            +
              it 'initializes with default parameters' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                d = Squib::Deck.new
         
     | 
| 
       8 
8 
     | 
    
         
             
                expect(d.width).to eq(825)
         
     | 
| 
       9 
9 
     | 
    
         
             
                expect(d.height).to eq(1125)
         
     | 
| 
       10 
10 
     | 
    
         
             
                expect(d.cards.size).to eq(1)
         
     | 
| 
       11 
11 
     | 
    
         
             
              end
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
              context  
     | 
| 
       14 
     | 
    
         
            -
                it  
     | 
| 
      
 13 
     | 
    
         
            +
              context 'in dealing with ranges' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                it 'calls text on all cards by default' do
         
     | 
| 
       15 
15 
     | 
    
         
             
                  card1 = instance_double(Squib::Card)
         
     | 
| 
       16 
     | 
    
         
            -
                  card2 = instance_double(Squib::Card) 
     | 
| 
      
 16 
     | 
    
         
            +
                  card2 = instance_double(Squib::Card)
         
     | 
| 
       17 
17 
     | 
    
         
             
                  expect(card1).to receive(:text).once
         
     | 
| 
       18 
18 
     | 
    
         
             
                  expect(card2).to receive(:text).once
         
     | 
| 
       19 
     | 
    
         
            -
                  Squib::Deck.new do 
     | 
| 
       20 
     | 
    
         
            -
                    @cards = [card1, card2] 
     | 
| 
      
 19 
     | 
    
         
            +
                  Squib::Deck.new do
         
     | 
| 
      
 20 
     | 
    
         
            +
                    @cards = [card1, card2]
         
     | 
| 
       21 
21 
     | 
    
         
             
                    text str: 'blah'
         
     | 
| 
       22 
22 
     | 
    
         
             
                  end
         
     | 
| 
       23 
23 
     | 
    
         
             
                end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                it  
     | 
| 
      
 25 
     | 
    
         
            +
                it 'calls text on some cards with an integer' do
         
     | 
| 
       26 
26 
     | 
    
         
             
                  card1 = instance_double(Squib::Card)
         
     | 
| 
       27 
27 
     | 
    
         
             
                  card2 = instance_double(Squib::Card)
         
     | 
| 
       28 
28 
     | 
    
         
             
                  expect(card2).to receive(:text).once
         
     | 
| 
       29 
     | 
    
         
            -
                  Squib::Deck.new do 
     | 
| 
       30 
     | 
    
         
            -
                    @cards = [card1, card2] 
     | 
| 
      
 29 
     | 
    
         
            +
                  Squib::Deck.new do
         
     | 
| 
      
 30 
     | 
    
         
            +
                    @cards = [card1, card2]
         
     | 
| 
       31 
31 
     | 
    
         
             
                    text range: 1, str: 'blah'
         
     | 
| 
       32 
32 
     | 
    
         
             
                  end
         
     | 
| 
       33 
     | 
    
         
            -
                end 
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
                it  
     | 
| 
      
 35 
     | 
    
         
            +
                it 'calls text with ranges' do
         
     | 
| 
       36 
36 
     | 
    
         
             
                  card1 = instance_double(Squib::Card)
         
     | 
| 
       37 
37 
     | 
    
         
             
                  card2 = instance_double(Squib::Card)
         
     | 
| 
       38 
38 
     | 
    
         
             
                  card3 = instance_double(Squib::Card)
         
     | 
| 
       39 
39 
     | 
    
         
             
                  expect(card1).to receive(:text).once
         
     | 
| 
       40 
40 
     | 
    
         
             
                  expect(card2).to receive(:text).once
         
     | 
| 
       41 
     | 
    
         
            -
                  Squib::Deck.new do 
     | 
| 
       42 
     | 
    
         
            -
                    @cards = [card1, card2, card3] 
     | 
| 
      
 41 
     | 
    
         
            +
                  Squib::Deck.new do
         
     | 
| 
      
 42 
     | 
    
         
            +
                    @cards = [card1, card2, card3]
         
     | 
| 
       43 
43 
     | 
    
         
             
                    text range: 0..1, str: 'blah'
         
     | 
| 
       44 
44 
     | 
    
         
             
                  end
         
     | 
| 
       45 
45 
     | 
    
         
             
                end
         
     | 
| 
       46 
46 
     | 
    
         
             
              end
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
              context  
     | 
| 
      
 48 
     | 
    
         
            +
              context '#load_layout' do
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
                it  
     | 
| 
       51 
     | 
    
         
            -
                  d = Squib::Deck.new(layout: test_file('no-extends.yml')) 
     | 
| 
      
 50 
     | 
    
         
            +
                it 'loads a normal layout with no extends' do
         
     | 
| 
      
 51 
     | 
    
         
            +
                  d = Squib::Deck.new(layout: test_file('no-extends.yml'))
         
     | 
| 
       52 
52 
     | 
    
         
             
                  expect(d.layout).to \
         
     | 
| 
       53 
53 
     | 
    
         
             
                    eq({'frame' => {
         
     | 
| 
       54 
     | 
    
         
            -
                          'x' => 38, 
     | 
| 
      
 54 
     | 
    
         
            +
                          'x' => 38,
         
     | 
| 
       55 
55 
     | 
    
         
             
                          'valign' => :middle,
         
     | 
| 
       56 
     | 
    
         
            -
                          'str' =>  
     | 
| 
       57 
     | 
    
         
            -
                          'font' =>  
     | 
| 
      
 56 
     | 
    
         
            +
                          'str' => 'blah',
         
     | 
| 
      
 57 
     | 
    
         
            +
                          'font' => 'Mr. Font',
         
     | 
| 
       58 
58 
     | 
    
         
             
                          }
         
     | 
| 
       59 
59 
     | 
    
         
             
                        }
         
     | 
| 
       60 
60 
     | 
    
         
             
                      )
         
     | 
| 
       61 
61 
     | 
    
         
             
                end
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
                it  
     | 
| 
       64 
     | 
    
         
            -
                  d = Squib::Deck.new(layout: test_file('single-extends.yml')) 
     | 
| 
      
 63 
     | 
    
         
            +
                it 'loads with a single extends' do
         
     | 
| 
      
 64 
     | 
    
         
            +
                  d = Squib::Deck.new(layout: test_file('single-extends.yml'))
         
     | 
| 
       65 
65 
     | 
    
         
             
                  expect(d.layout).to \
         
     | 
| 
       66 
66 
     | 
    
         
             
                    eq({'frame' => {
         
     | 
| 
       67 
     | 
    
         
            -
                          'x' => 38, 
     | 
| 
       68 
     | 
    
         
            -
                          'y' => 38, 
     | 
| 
      
 67 
     | 
    
         
            +
                          'x' => 38,
         
     | 
| 
      
 68 
     | 
    
         
            +
                          'y' => 38,
         
     | 
| 
       69 
69 
     | 
    
         
             
                          },
         
     | 
| 
       70 
70 
     | 
    
         
             
                        'title' => {
         
     | 
| 
       71 
71 
     | 
    
         
             
                          'extends' => 'frame',
         
     | 
| 
       72 
     | 
    
         
            -
                          'x' => 38, 
     | 
| 
       73 
     | 
    
         
            -
                          'y' => 50, 
     | 
| 
      
 72 
     | 
    
         
            +
                          'x' => 38,
         
     | 
| 
      
 73 
     | 
    
         
            +
                          'y' => 50,
         
     | 
| 
       74 
74 
     | 
    
         
             
                          'width' => 100,
         
     | 
| 
       75 
75 
     | 
    
         
             
                          }
         
     | 
| 
       76 
76 
     | 
    
         
             
                        }
         
     | 
| 
       77 
77 
     | 
    
         
             
                      )
         
     | 
| 
       78 
78 
     | 
    
         
             
                end
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
       80 
     | 
    
         
            -
                it  
     | 
| 
       81 
     | 
    
         
            -
                  d = Squib::Deck.new(layout: test_file('pre-extends.yml')) 
     | 
| 
      
 80 
     | 
    
         
            +
                it 'applies the extends regardless of order' do
         
     | 
| 
      
 81 
     | 
    
         
            +
                  d = Squib::Deck.new(layout: test_file('pre-extends.yml'))
         
     | 
| 
       82 
82 
     | 
    
         
             
                  expect(d.layout).to \
         
     | 
| 
       83 
83 
     | 
    
         
             
                    eq({'frame' => {
         
     | 
| 
       84 
     | 
    
         
            -
                          'x' => 38, 
     | 
| 
       85 
     | 
    
         
            -
                          'y' => 38, 
     | 
| 
      
 84 
     | 
    
         
            +
                          'x' => 38,
         
     | 
| 
      
 85 
     | 
    
         
            +
                          'y' => 38,
         
     | 
| 
       86 
86 
     | 
    
         
             
                          },
         
     | 
| 
       87 
87 
     | 
    
         
             
                        'title' => {
         
     | 
| 
       88 
88 
     | 
    
         
             
                          'extends' => 'frame',
         
     | 
| 
       89 
     | 
    
         
            -
                          'x' => 38, 
     | 
| 
       90 
     | 
    
         
            -
                          'y' => 50, 
     | 
| 
      
 89 
     | 
    
         
            +
                          'x' => 38,
         
     | 
| 
      
 90 
     | 
    
         
            +
                          'y' => 50,
         
     | 
| 
       91 
91 
     | 
    
         
             
                          'width' => 100,
         
     | 
| 
       92 
92 
     | 
    
         
             
                          }
         
     | 
| 
       93 
93 
     | 
    
         
             
                        }
         
     | 
| 
       94 
94 
     | 
    
         
             
                      )
         
     | 
| 
       95 
95 
     | 
    
         
             
                end
         
     | 
| 
       96 
96 
     | 
    
         | 
| 
       97 
     | 
    
         
            -
                it  
     | 
| 
       98 
     | 
    
         
            -
                  d = Squib::Deck.new(layout: test_file('single-level-multi-extends.yml')) 
     | 
| 
      
 97 
     | 
    
         
            +
                it 'applies the single-level extends multiple times' do
         
     | 
| 
      
 98 
     | 
    
         
            +
                  d = Squib::Deck.new(layout: test_file('single-level-multi-extends.yml'))
         
     | 
| 
       99 
99 
     | 
    
         
             
                  expect(d.layout).to \
         
     | 
| 
       100 
100 
     | 
    
         
             
                    eq({'frame' => {
         
     | 
| 
       101 
     | 
    
         
            -
                          'x' => 38, 
     | 
| 
       102 
     | 
    
         
            -
                          'y' => 38, 
     | 
| 
      
 101 
     | 
    
         
            +
                          'x' => 38,
         
     | 
| 
      
 102 
     | 
    
         
            +
                          'y' => 38,
         
     | 
| 
       103 
103 
     | 
    
         
             
                          },
         
     | 
| 
       104 
104 
     | 
    
         
             
                        'title' => {
         
     | 
| 
       105 
105 
     | 
    
         
             
                          'extends' => 'frame',
         
     | 
| 
       106 
     | 
    
         
            -
                          'x' => 38, 
     | 
| 
       107 
     | 
    
         
            -
                          'y' => 50, 
     | 
| 
      
 106 
     | 
    
         
            +
                          'x' => 38,
         
     | 
| 
      
 107 
     | 
    
         
            +
                          'y' => 50,
         
     | 
| 
       108 
108 
     | 
    
         
             
                          'width' => 100,
         
     | 
| 
       109 
109 
     | 
    
         
             
                          },
         
     | 
| 
       110 
110 
     | 
    
         
             
                        'title2' => {
         
     | 
| 
       111 
111 
     | 
    
         
             
                          'extends' => 'frame',
         
     | 
| 
       112 
     | 
    
         
            -
                          'x' => 75, 
     | 
| 
       113 
     | 
    
         
            -
                          'y' => 150, 
     | 
| 
      
 112 
     | 
    
         
            +
                          'x' => 75,
         
     | 
| 
      
 113 
     | 
    
         
            +
                          'y' => 150,
         
     | 
| 
       114 
114 
     | 
    
         
             
                          'width' => 150,
         
     | 
| 
       115 
115 
     | 
    
         
             
                          },
         
     | 
| 
       116 
116 
     | 
    
         
             
                        }
         
     | 
| 
       117 
117 
     | 
    
         
             
                      )
         
     | 
| 
       118 
118 
     | 
    
         
             
                end
         
     | 
| 
       119 
119 
     | 
    
         | 
| 
       120 
     | 
    
         
            -
                it  
     | 
| 
       121 
     | 
    
         
            -
                  d = Squib::Deck.new(layout: test_file('multi-extends-single-entry.yml')) 
     | 
| 
      
 120 
     | 
    
         
            +
                it 'applies multiple extends in a single rule' do
         
     | 
| 
      
 121 
     | 
    
         
            +
                  d = Squib::Deck.new(layout: test_file('multi-extends-single-entry.yml'))
         
     | 
| 
       122 
122 
     | 
    
         
             
                  expect(d.layout).to \
         
     | 
| 
       123 
123 
     | 
    
         
             
                    eq({'aunt' => {
         
     | 
| 
       124 
     | 
    
         
            -
                          'a' => 101, 
     | 
| 
       125 
     | 
    
         
            -
                          'b' => 102, 
     | 
| 
       126 
     | 
    
         
            -
                          'c' => 103, 
     | 
| 
      
 124 
     | 
    
         
            +
                          'a' => 101,
         
     | 
| 
      
 125 
     | 
    
         
            +
                          'b' => 102,
         
     | 
| 
      
 126 
     | 
    
         
            +
                          'c' => 103,
         
     | 
| 
       127 
127 
     | 
    
         
             
                          },
         
     | 
| 
       128 
128 
     | 
    
         
             
                        'uncle' => {
         
     | 
| 
       129 
     | 
    
         
            -
                          'x' => 104, 
     | 
| 
       130 
     | 
    
         
            -
                          'y' => 105, 
     | 
| 
       131 
     | 
    
         
            -
                          'b' => 106, 
     | 
| 
      
 129 
     | 
    
         
            +
                          'x' => 104,
         
     | 
| 
      
 130 
     | 
    
         
            +
                          'y' => 105,
         
     | 
| 
      
 131 
     | 
    
         
            +
                          'b' => 106,
         
     | 
| 
       132 
132 
     | 
    
         
             
                          },
         
     | 
| 
       133 
133 
     | 
    
         
             
                        'child' => {
         
     | 
| 
       134 
134 
     | 
    
         
             
                          'extends' => ['uncle','aunt'],
         
     | 
| 
         @@ -142,45 +142,45 @@ describe Squib::Deck do 
     | 
|
| 
       142 
142 
     | 
    
         
             
                      )
         
     | 
| 
       143 
143 
     | 
    
         
             
                end
         
     | 
| 
       144 
144 
     | 
    
         | 
| 
       145 
     | 
    
         
            -
                it  
     | 
| 
       146 
     | 
    
         
            -
                  d = Squib::Deck.new(layout: test_file('multi-level-extends.yml')) 
     | 
| 
      
 145 
     | 
    
         
            +
                it 'applies multi-level extends' do
         
     | 
| 
      
 146 
     | 
    
         
            +
                  d = Squib::Deck.new(layout: test_file('multi-level-extends.yml'))
         
     | 
| 
       147 
147 
     | 
    
         
             
                  expect(d.layout).to \
         
     | 
| 
       148 
148 
     | 
    
         
             
                    eq({'frame' => {
         
     | 
| 
       149 
     | 
    
         
            -
                          'x' => 38, 
     | 
| 
       150 
     | 
    
         
            -
                          'y' => 38, 
     | 
| 
      
 149 
     | 
    
         
            +
                          'x' => 38,
         
     | 
| 
      
 150 
     | 
    
         
            +
                          'y' => 38,
         
     | 
| 
       151 
151 
     | 
    
         
             
                          },
         
     | 
| 
       152 
152 
     | 
    
         
             
                        'title' => {
         
     | 
| 
       153 
153 
     | 
    
         
             
                          'extends' => 'frame',
         
     | 
| 
       154 
     | 
    
         
            -
                          'x' => 38, 
     | 
| 
       155 
     | 
    
         
            -
                          'y' => 50, 
     | 
| 
      
 154 
     | 
    
         
            +
                          'x' => 38,
         
     | 
| 
      
 155 
     | 
    
         
            +
                          'y' => 50,
         
     | 
| 
       156 
156 
     | 
    
         
             
                          'width' => 100,
         
     | 
| 
       157 
157 
     | 
    
         
             
                          },
         
     | 
| 
       158 
158 
     | 
    
         
             
                        'subtitle' => {
         
     | 
| 
       159 
159 
     | 
    
         
             
                          'extends' => 'title',
         
     | 
| 
       160 
160 
     | 
    
         
             
                          'x' => 38,
         
     | 
| 
       161 
     | 
    
         
            -
                          'y' => 150, 
     | 
| 
      
 161 
     | 
    
         
            +
                          'y' => 150,
         
     | 
| 
       162 
162 
     | 
    
         
             
                          'width' => 100,
         
     | 
| 
       163 
163 
     | 
    
         
             
                          },
         
     | 
| 
       164 
164 
     | 
    
         
             
                        }
         
     | 
| 
       165 
165 
     | 
    
         
             
                      )
         
     | 
| 
       166 
166 
     | 
    
         
             
                end
         
     | 
| 
       167 
167 
     | 
    
         | 
| 
       168 
     | 
    
         
            -
                it  
     | 
| 
      
 168 
     | 
    
         
            +
                it 'fails on a self-circular extends' do
         
     | 
| 
       169 
169 
     | 
    
         
             
                  file = test_file('self-circular-extends.yml')
         
     | 
| 
       170 
170 
     | 
    
         
             
                  expect { Squib::Deck.new(layout: file) }.to \
         
     | 
| 
       171 
     | 
    
         
            -
                    raise_error(RuntimeError,  
     | 
| 
      
 171 
     | 
    
         
            +
                    raise_error(RuntimeError, 'Invalid layout: circular extends with \'a\'')
         
     | 
| 
       172 
172 
     | 
    
         
             
                end
         
     | 
| 
       173 
173 
     | 
    
         | 
| 
       174 
     | 
    
         
            -
                it  
     | 
| 
      
 174 
     | 
    
         
            +
                it 'fails on a easy-circular extends' do
         
     | 
| 
       175 
175 
     | 
    
         
             
                  file = test_file('easy-circular-extends.yml')
         
     | 
| 
       176 
176 
     | 
    
         
             
                  expect { Squib::Deck.new(layout: file) }.to \
         
     | 
| 
       177 
     | 
    
         
            -
                    raise_error(RuntimeError,  
     | 
| 
      
 177 
     | 
    
         
            +
                    raise_error(RuntimeError, 'Invalid layout: circular extends with \'a\'')
         
     | 
| 
       178 
178 
     | 
    
         
             
                end
         
     | 
| 
       179 
179 
     | 
    
         | 
| 
       180 
     | 
    
         
            -
                it  
     | 
| 
      
 180 
     | 
    
         
            +
                it 'hard on a easy-circular extends' do
         
     | 
| 
       181 
181 
     | 
    
         
             
                  file = test_file('hard-circular-extends.yml')
         
     | 
| 
       182 
182 
     | 
    
         
             
                  expect { Squib::Deck.new(layout: file) }.to \
         
     | 
| 
       183 
     | 
    
         
            -
                    raise_error(RuntimeError,  
     | 
| 
      
 183 
     | 
    
         
            +
                    raise_error(RuntimeError, 'Invalid layout: circular extends with \'a\'')
         
     | 
| 
       184 
184 
     | 
    
         
             
                end
         
     | 
| 
       185 
185 
     | 
    
         | 
| 
       186 
186 
     | 
    
         
             
              end
         
     | 
| 
         @@ -0,0 +1,79 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'squib'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe Squib::Card do
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              before(:each) do
         
     | 
| 
      
 7 
     | 
    
         
            +
                @deck    = double(Squib::Deck)
         
     | 
| 
      
 8 
     | 
    
         
            +
                @context = double(Cairo::Context)
         
     | 
| 
      
 9 
     | 
    
         
            +
                @svg     = double(RSVG::Handle)
         
     | 
| 
      
 10 
     | 
    
         
            +
                allow(Cairo::Context).to receive(:new).and_return(@context)
         
     | 
| 
      
 11 
     | 
    
         
            +
                allow(Cairo::ImageSurface).to receive(:from_png).and_return(nil)
         
     | 
| 
      
 12 
     | 
    
         
            +
                allow(Cairo::ImageSurface).to receive(:new).and_return(nil)
         
     | 
| 
      
 13 
     | 
    
         
            +
                allow(RSVG::Handle).to receive(:new_from_file).and_return(@svg)
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              context '#png' do
         
     | 
| 
      
 17 
     | 
    
         
            +
                it 'makes all the expected calls on a smoke test' do
         
     | 
| 
      
 18 
     | 
    
         
            +
                  expect(@context).to receive(:save).once
         
     | 
| 
      
 19 
     | 
    
         
            +
                  expect(@context).to receive(:translate).with(-37, -38).once
         
     | 
| 
      
 20 
     | 
    
         
            +
                  expect(@context).to receive(:rotate).with(0.0).once
         
     | 
| 
      
 21 
     | 
    
         
            +
                  expect(@context).to receive(:translate).with(37, 38).once
         
     | 
| 
      
 22 
     | 
    
         
            +
                  expect(@context).to receive(:set_source).with(nil, 37, 38).once
         
     | 
| 
      
 23 
     | 
    
         
            +
                  expect(@context).to receive(:paint).with(0.9).once
         
     | 
| 
      
 24 
     | 
    
         
            +
                  expect(@context).to receive(:restore).once
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  card = Squib::Card.new(@deck, 100, 150)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  # png(file, x, y, alpha, blend, angle)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  card.png('foo.png', 37, 38, 0.9, :none, 0.0)
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                it 'sets blend when needed' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @context.as_null_object
         
     | 
| 
      
 33 
     | 
    
         
            +
                  expect(@context).to receive(:operator=).with(:overlay).once
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  card = Squib::Card.new(@deck, 100, 150)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  card.png('foo.png', 37, 38, 0.9, :overlay, 0.0)
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              context '#svg' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                it 'makes all the expected calls on a smoke test' do
         
     | 
| 
      
 42 
     | 
    
         
            +
                  expect(@svg).to receive(:width).and_return(100).twice
         
     | 
| 
      
 43 
     | 
    
         
            +
                  expect(@svg).to receive(:height).and_return(100).twice
         
     | 
| 
      
 44 
     | 
    
         
            +
                  expect(@context).to receive(:save).once
         
     | 
| 
      
 45 
     | 
    
         
            +
                  expect(@context).to receive(:translate).with(-37, -38).once
         
     | 
| 
      
 46 
     | 
    
         
            +
                  expect(@context).to receive(:rotate).with(0.0).once
         
     | 
| 
      
 47 
     | 
    
         
            +
                  expect(@context).to receive(:translate).with(37, 38).once
         
     | 
| 
      
 48 
     | 
    
         
            +
                  expect(@context).to receive(:scale).with(1.0, 1.0).once
         
     | 
| 
      
 49 
     | 
    
         
            +
                  expect(@context).to receive(:render_rsvg_handle).with(@svg, 'id').once
         
     | 
| 
      
 50 
     | 
    
         
            +
                  expect(@context).to receive(:set_source).with(nil, 37, 38).once
         
     | 
| 
      
 51 
     | 
    
         
            +
                  expect(@context).to receive(:paint).with(0.9).once
         
     | 
| 
      
 52 
     | 
    
         
            +
                  expect(@context).to receive(:restore).once
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  card = Squib::Card.new(@deck, 100, 150)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  # svg(file, id, x, y, width, height, alpha, blend, angle)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  card.svg('foo.png', 'id', 37, 38, :native, :native, 0.9, :none, 0.0)
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                it 'sets blend when needed' do
         
     | 
| 
      
 60 
     | 
    
         
            +
                  @context.as_null_object
         
     | 
| 
      
 61 
     | 
    
         
            +
                  @svg.as_null_object
         
     | 
| 
      
 62 
     | 
    
         
            +
                  expect(@context).to receive(:operator=).with(:overlay).once
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                  card = Squib::Card.new(@deck, 100, 150)
         
     | 
| 
      
 65 
     | 
    
         
            +
                  card.svg('foo.png', nil, 37, 38, :native, :native, 0.9, :overlay, 0.0)
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                it 'sets width & height when needed' do
         
     | 
| 
      
 69 
     | 
    
         
            +
                  @context.as_null_object
         
     | 
| 
      
 70 
     | 
    
         
            +
                  expect(@svg).to receive(:width).and_return(100).once
         
     | 
| 
      
 71 
     | 
    
         
            +
                  expect(@svg).to receive(:height).and_return(100).once
         
     | 
| 
      
 72 
     | 
    
         
            +
                  expect(@context).to receive(:scale).with(2.0, 3.0).once
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                  card = Squib::Card.new(@deck, 100, 150)
         
     | 
| 
      
 75 
     | 
    
         
            +
                  card.svg('foo.png', nil, 37, 38, 200, 300, 0.9, :none, 0.0)
         
     | 
| 
      
 76 
     | 
    
         
            +
                end
         
     | 
| 
      
 77 
     | 
    
         
            +
              end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            end
         
     |