bread-basket 0.0.0 → 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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +4 -0
  3. data/.rubocop.yml +18 -0
  4. data/.travis.yml +4 -1
  5. data/Gemfile +1 -1
  6. data/Guardfile +7 -2
  7. data/README.md +28 -17
  8. data/Rakefile +13 -6
  9. data/bin/bread-basket +14 -0
  10. data/bread-basket.gemspec +29 -24
  11. data/lib/bread/basket.rb +12 -6
  12. data/lib/bread/basket/cli.rb +10 -0
  13. data/lib/bread/basket/poster.rb +38 -0
  14. data/lib/bread/basket/poster/block_code_handler.rb +50 -0
  15. data/lib/bread/basket/poster/block_renderer.rb +14 -0
  16. data/lib/bread/basket/poster/box.rb +119 -0
  17. data/lib/bread/basket/poster/box_checker.rb +60 -0
  18. data/lib/bread/basket/poster/columns.rb +90 -0
  19. data/lib/bread/basket/poster/css_reader.rb +130 -0
  20. data/lib/bread/basket/poster/dimensions_helper.rb +123 -0
  21. data/lib/bread/basket/poster/header_callback.rb +29 -0
  22. data/lib/bread/basket/poster/header_maker.rb +74 -0
  23. data/lib/bread/basket/poster/image_box.rb +93 -0
  24. data/lib/bread/basket/poster/layout.rb +108 -0
  25. data/lib/bread/basket/poster/pdf_builder.rb +113 -0
  26. data/lib/bread/basket/poster/poster_maker.rb +55 -0
  27. data/lib/bread/basket/poster/prawn_patches/column_box.rb +17 -0
  28. data/lib/bread/basket/poster/text_renderer.rb +89 -0
  29. data/lib/bread/basket/poster/units_helper.rb +39 -0
  30. data/lib/bread/basket/version.rb +1 -1
  31. data/samples/block_sample.css +86 -0
  32. data/samples/flow_sample.css +68 -0
  33. data/samples/ipsum.jpg +0 -0
  34. data/samples/lorem.jpg +0 -0
  35. data/samples/lorem_block.md +86 -0
  36. data/samples/lorem_flow.md +58 -0
  37. data/samples/lorem_flow.pdf +3834 -6
  38. data/samples/sample.md +59 -0
  39. data/samples/simple.css +19 -0
  40. data/samples/simple.md +3 -0
  41. data/samples/ucair_logo.png +0 -0
  42. data/spec/cli_spec.rb +13 -0
  43. data/spec/poster/block_code_handler_spec.rb +47 -0
  44. data/spec/poster/box_spec.rb +114 -0
  45. data/spec/poster/columns_spec.rb +64 -0
  46. data/spec/poster/css_reader_spec.rb +115 -0
  47. data/spec/poster/header_maker_spec.rb +49 -0
  48. data/spec/poster/image_box_spec.rb +69 -0
  49. data/spec/poster/layout_spec.rb +75 -0
  50. data/spec/poster/pdf_builder_spec.rb +60 -0
  51. data/spec/poster/poster_maker_spec.rb +15 -0
  52. data/spec/poster/test_files/bad_file.md +1 -0
  53. data/spec/poster/test_files/basic_block.css +14 -0
  54. data/spec/poster/test_files/basic_flow.css +31 -0
  55. data/spec/poster/test_files/block_code_test.css +13 -0
  56. data/spec/poster/test_files/builder.css +39 -0
  57. data/spec/poster/test_files/circular.css +39 -0
  58. data/spec/poster/test_files/dragon.png +0 -0
  59. data/spec/poster/test_files/fitted_image.css +39 -0
  60. data/spec/poster/test_files/good_file.md +5 -0
  61. data/spec/poster/test_files/good_file.pdf +0 -0
  62. data/spec/poster/test_files/header_test.css +22 -0
  63. data/spec/poster/test_files/nearly_empty.css +10 -0
  64. data/spec/poster/test_files/self_referential.css +108 -0
  65. data/spec/poster/test_files/ucair_logo.png +0 -0
  66. data/spec/poster/text_renderer_spec.rb +54 -0
  67. data/spec/poster/units_helper_spec.rb +36 -0
  68. data/spec/spec_helper.rb +6 -0
  69. metadata +212 -34
  70. data/bread-basket-0.0.1.gem +0 -0
  71. data/spec/basket_spec.rb +0 -7
@@ -0,0 +1,59 @@
1
+ ---
2
+ stylesheet: example_flow
3
+ title: Comparison of Pre-interpolation Algorithms for k-Space regridding
4
+ authors: KC Erb, Ganesh Adluru, Srikant Kamesh Iyer, Devavrat Likhite, John A Roberts, and Edward DiBella[2]
5
+ affiliations:
6
+ - UCAIR, University of Utah, Salt Lake, Utah, United States
7
+ - Department of Radiology, University of Utah, Salt Lake, Utah, United States
8
+ ---
9
+
10
+ # Formatting
11
+
12
+ You note sections in your poster with the # sign. 1 # is the largest section
13
+ size ## is next smallest ### next and so forth.
14
+
15
+ To make text *italic* use one star, for **bold** use two. Underlines are hard
16
+ to see on posters so if you _must_ use them it is done with underscores.
17
+
18
+ You can include super and subscripts in your text. Superscript is just like you expect
19
+ with a carat putting the rest of the characters following it up top: 10^21.
20
+ Subscripts don't have a shortcut so you will have to use tags: sub<sub>script</sub>.
21
+
22
+ You can make your text shine out with your accent color and weight with ==highlighting==.
23
+ And you can get a different accent style with `code text markers`.
24
+
25
+
26
+ # Sciency Things
27
+
28
+ You can use equations in your document via LaTeX. You'll need to have
29
+ `pdflatex` installed on your machine.
30
+
31
+ ```
32
+ P = \frac{1}{\hbar \omega} \int ||D-gm||^2 dx
33
+ ```
34
+
35
+
36
+ A figure is easy to include
37
+
38
+ ```figure:fig1-a.png
39
+ The caption goes in here. `2+2`
40
+ ```
41
+
42
+ If you want to use a normal code block just leave off the figure keyword
43
+
44
+ ```ruby
45
+ puts "Cool rad awesome!"
46
+ ```
47
+
48
+ You can write up a spiffy table via normal markdown style
49
+
50
+ | Tables | Are | Cool |
51
+ | ------------- |:-------------:| -----:|
52
+ | col 3 is | right-aligned | $1600 |
53
+ | col 2 is | centered | $12 |
54
+ | zebra stripes | are neat | $1 |
55
+
56
+
57
+ Ooh and a fancy feature is the pullquote:
58
+
59
+ > This text will get pulled into its own quote if the template has a pullquote.
@@ -0,0 +1,19 @@
1
+ .layout {
2
+ width: 4.ft;
3
+ height: 3.ft;
4
+ margin: 1.in;
5
+
6
+ font-size: 36;
7
+ font-family: helvetica;
8
+ }
9
+
10
+ .columns {
11
+ count: 4;
12
+ top: title.left + margin;
13
+ }
14
+
15
+ .left-logo {
16
+ src: ucair_logo.png;
17
+ top: top;
18
+ left: left;
19
+ }
@@ -0,0 +1,3 @@
1
+ ---
2
+ stylesheet: simple
3
+ ---
Binary file
@@ -0,0 +1,13 @@
1
+ # Some bare-bones CLI specs. At this point the CLI is so simple
2
+ # I'm not sure that it needs real specs . . .
3
+
4
+ describe Bread::Basket::Cli do
5
+ context 'poster' do
6
+ let(:file) { 'example.md' }
7
+
8
+ it 'gives file to Poster' do
9
+ expect(Bread::Basket::Poster::PosterMaker).to receive(:new).with(file)
10
+ subject.poster(file)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,47 @@
1
+ describe Bread::Basket::Poster::BlockCodeHandler do
2
+ let(:pdf) { Prawn::Document.new }
3
+ # explanation of before(:all) in css_reader_spec
4
+ context 'when used to create images' do
5
+ let(:first_line) { 'dragon.png' }
6
+ let(:content) { "Here's a *caption* with **markdown**" }
7
+
8
+ before(:each) do
9
+ metadata = { 'stylesheet' => 'block_code_test' }
10
+ Bread::Basket::Poster.dir_path = './spec/poster/test_files'
11
+ @layout = Bread::Basket::Poster::Layout.new(metadata)
12
+ Bread::Basket::Poster.layout = @layout
13
+ Bread::Basket::Poster.pdf = pdf
14
+ end
15
+
16
+ subject do
17
+ Bread::Basket::Poster::BlockCodeHandler.new(pdf, @layout, first_line, content)
18
+ end
19
+
20
+ # yeah sorta bare bones here, open to suggestions
21
+ it 'doesnt fail' do
22
+ subject
23
+ end
24
+ end
25
+
26
+ context 'when given a bad first line' do
27
+ let(:first_line) { 'bleh' }
28
+ let(:content) { 'Feed me!' }
29
+
30
+ before(:each) do
31
+ metadata = { 'stylesheet' => 'block_code_test' }
32
+ Bread::Basket::Poster.dir_path = './spec/poster/test_files'
33
+ @layout = Bread::Basket::Poster::Layout.new(metadata)
34
+ Bread::Basket::Poster.layout = @layout
35
+ Bread::Basket::Poster.pdf = pdf
36
+ end
37
+
38
+ subject do
39
+ Bread::Basket::Poster::BlockCodeHandler.new(pdf, @layout, first_line, content)
40
+ end
41
+
42
+ # yeah sorta bare bones here, open to suggestions
43
+ it 'doesnt fail' do
44
+ subject
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,114 @@
1
+ describe Bread::Basket::Poster::Box do
2
+ # explanation of before all in css_reader_spec
3
+ before(:all) do
4
+ metadata = { 'stylesheet' => 'self_referential' }
5
+ Bread::Basket::Poster.dir_path = './spec/poster/test_files'
6
+ @name = '.simple-selector'
7
+ @layout = Bread::Basket::Poster::Layout.new(metadata)
8
+ end
9
+
10
+ describe 'css_reader sets up columns[0] correctly via reference' do
11
+ subject { @layout.columns[0] }
12
+ its(:top) { should eq(500) }
13
+ its(:height) { should eq(495) }
14
+ end
15
+
16
+ describe 'css_reader leaves columns[1] pending due to stretchy dependence' do
17
+ subject { @layout.columns[1] }
18
+ its(:top) do
19
+ # There are a few things hiding here, it converts the command name from - to _
20
+ # and it correctly inserts margin as 5.0
21
+ h = { pending: { 'stretchy_box.bottom' => 0 },
22
+ command: ['stretchy_box.bottom', :-, 5.0]
23
+ }
24
+ should eq h
25
+ end
26
+ its(:height) { should be_nil }
27
+ end
28
+
29
+ context 'interdependent self-reference' do
30
+ describe 'box a' do
31
+ subject { @layout.box_a }
32
+ its(:left) { should eq 200 }
33
+ its(:height) { should eq 125 }
34
+ end
35
+
36
+ describe 'box b' do
37
+ subject { @layout.box_b }
38
+ its(:top) { should eq 700 }
39
+ its(:height) { should eq 125 }
40
+ end
41
+
42
+ describe 'box c' do
43
+ subject { @layout.box_c }
44
+ its(:left) { should eq 200 }
45
+ its(:top) { should eq 700 }
46
+ end
47
+ end
48
+
49
+ describe 'math operations' do
50
+ subject { @layout.math }
51
+ its(:left) { should eq 10 }
52
+ its(:top) { should eq 580 }
53
+ its(:width) { should eq 185 }
54
+ its(:height) { should eq 520.0 / 3 }
55
+ end
56
+
57
+ it 'inspects itself' do
58
+ inspect_string = 'top: 700.0; left: 200.0; width: 500.0; height: 200.0; ' \
59
+ 'bottom: 500.0; right: 700.0;'
60
+ expect(@layout.simple_box.inspect).to eq inspect_string
61
+ end
62
+
63
+ context 'when unusual bounds are given' do
64
+ describe 'no width' do
65
+ subject { @layout.no_width }
66
+ its(:width) { should eq 100 }
67
+ end
68
+
69
+ describe 'no left' do
70
+ subject { @layout.no_left }
71
+ its(:left) { should eq 1000 }
72
+ end
73
+
74
+ describe 'no top' do
75
+ subject { @layout.no_top }
76
+ its(:top) { should eq 55 }
77
+ end
78
+
79
+ describe 'top and height' do
80
+ subject { @layout.top_and_height }
81
+ its(:top) { should eq 70 }
82
+ its(:height) { should eq 55 }
83
+ its(:bottom) { should eq 15 }
84
+ end
85
+
86
+ describe 'when horizontally overdetermined' do
87
+ subject { @layout.horizontally_overdetermined }
88
+ it 'ignores the `right` specification' do
89
+ expect(subject.right).to eq 330
90
+ end
91
+ end
92
+
93
+ describe 'when vertically overdetermined' do
94
+ subject { @layout.vertically_overdetermined }
95
+ it 'ignores the `bottom` specification' do
96
+ expect(subject.bottom).to eq 43
97
+ end
98
+ end
99
+
100
+ describe 'when making a box with insufficient inputs' do
101
+ subject { Bread::Basket::Poster::Box.new('.bread-box', @layout, @specs) }
102
+
103
+ it 'fails if only 1 of left, right or width are given' do
104
+ @specs = { 'left' => 15, 'top' => 33 }
105
+ expect { subject }.to raise_error SystemExit
106
+ end
107
+
108
+ it 'fails if no top, but only bottom or height given' do
109
+ @specs = { 'left' => 52, 'width' => 15, 'bottom' => 20 }
110
+ expect { subject }.to raise_error SystemExit
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,64 @@
1
+ describe Bread::Basket::Poster::Columns do
2
+ # explanation of before all in css_reader_spec
3
+ before(:all) do
4
+ metadata = { 'stylesheet' => 'basic_flow' }
5
+ Bread::Basket::Poster.dir_path = './spec/poster/test_files'
6
+ @layout = Bread::Basket::Poster::Layout.new(metadata)
7
+ end
8
+
9
+ it 'quits if specs are wrong' do
10
+ specs = { 'left' => 2, 'top' => 40, 'width' => 100 }
11
+ expect do
12
+ Bread::Basket::Poster::Columns.new specs, @layout
13
+ end.to raise_error SystemExit
14
+ end
15
+
16
+ it 'duplicates tops into an array of length count' do
17
+ specs = { 'count' => 2, 'top' => 40 }
18
+ columns = Bread::Basket::Poster::Columns.new specs, @layout
19
+ expect(columns.tops).to eq [40, 40]
20
+ end
21
+
22
+ it 'uses top array as-is if count matches tops arr length' do
23
+ specs = { 'count' => 2, 'top' => [37, 25] }
24
+ columns = Bread::Basket::Poster::Columns.new specs, @layout
25
+ expect(columns.tops).to eq [37, 25]
26
+ end
27
+
28
+ it 'makes symmetric tops for even column number' do
29
+ specs = { 'count' => 4, 'top' => [40, 10] }
30
+ columns = Bread::Basket::Poster::Columns.new specs, @layout
31
+ expect(columns.tops).to eq [40, 10, 10, 40]
32
+ end
33
+
34
+ it 'makes symmetric tops for odd column number' do
35
+ specs = { 'count' => 5, 'top' => [40, 10, 30] }
36
+ columns = Bread::Basket::Poster::Columns.new specs, @layout
37
+ expect(columns.tops).to eq [40, 10, 30, 10, 40]
38
+ end
39
+
40
+ it 'uses layout font to determine column spacing and widths' do
41
+ specs = { 'count' => 5, 'top' => [40, 10, 30] }
42
+ columns = Bread::Basket::Poster::Columns.new specs, @layout
43
+ expect(columns.width).to eq 194.8
44
+ end
45
+
46
+ it 'fails to create symmetric tops for top input' do
47
+ specs = { 'count' => 4, 'top' => [40, 10, 30] }
48
+ expect do
49
+ Bread::Basket::Poster::Columns.new specs, @layout
50
+ end.to raise_error SystemExit
51
+ end
52
+
53
+ it 'uses columns font-size for spacing if provided' do
54
+ specs = { 'count' => 5, 'top' => [40, 10, 30], 'font-size' => 37 }
55
+ columns = Bread::Basket::Poster::Columns.new specs, @layout
56
+ expect(columns.spacing).to eq 37
57
+ end
58
+
59
+ it 'uses layout font-size for spacing if no font-size specified' do
60
+ specs = { 'count' => 5, 'top' => [40, 10, 30] }
61
+ columns = Bread::Basket::Poster::Columns.new specs, @layout
62
+ expect(columns.spacing).to eq 24
63
+ end
64
+ end
@@ -0,0 +1,115 @@
1
+ describe Bread::Basket::Poster::CSSReader do
2
+ # This will actually run through all kinds of boxes, dimensions helpers
3
+ # and the like, but I'm trying to only spec out the jobs of css_reader.
4
+ context 'when given the basic_flow stylesheet' do
5
+ # Using a before block here because I want to alter the load path without
6
+ # actually loading a markdown file from the start. Layout needs a real css
7
+ # file to talk to in order to initialize correctly.
8
+ before(:all) do
9
+ metadata = { 'stylesheet' => 'basic_flow' }
10
+ Bread::Basket::Poster.dir_path = './spec/poster/test_files'
11
+ @layout = Bread::Basket::Poster::Layout.new(metadata)
12
+ end
13
+
14
+ describe 'css_reader sets up the layout properties' do
15
+ subject { @layout }
16
+ its(:top) { should eq(720) }
17
+ its(:bottom) { should eq(0) }
18
+ its(:height) { should eq(720) }
19
+ its(:left) { should eq(0) }
20
+ its(:right) { should eq(1080) }
21
+ its(:width) { should eq(1080) }
22
+
23
+ its(:font_size) { should eq(24) }
24
+ its(:font_family) { should eq('times') }
25
+ its(:boxes) do
26
+ boxes = %w(columns[0] columns[1] columns[2] columns[3] .stretchy-box .image)
27
+ should eq boxes
28
+ end
29
+ end
30
+
31
+ describe 'css_reader sets up columns[0]' do
32
+ subject { @layout.columns[0] }
33
+ its(:top) { should eq(648) }
34
+ its(:bottom) { should eq(5) }
35
+ its(:height) { should eq(643) }
36
+ its(:left) { should eq(5) }
37
+ its(:right) { should eq(254.5) }
38
+ its(:width) { should eq(249.5) }
39
+ end
40
+
41
+ describe 'css_reader sets up columns[1]' do
42
+ subject { @layout.columns[1] }
43
+ its(:top) { should eq(576) }
44
+ its(:bottom) { should eq(5) }
45
+ its(:height) { should eq(571) }
46
+ its(:left) { should eq(278.5) }
47
+ its(:right) { should eq(528) }
48
+ its(:width) { should eq(249.5) }
49
+ end
50
+
51
+ describe 'css_reader sets up the bounds for stretchy box' do
52
+ subject { @layout.stretchy_box }
53
+ its(:top) { should eq(100) }
54
+ its(:bottom) { should eq(:stretchy) }
55
+ its(:height) { should eq(:stretchy) }
56
+ its(:left) { should eq(200) }
57
+ its(:right) { should eq(700) }
58
+ its(:width) { should eq(500) }
59
+ it 'has font-size style' do
60
+ font_size = subject.styles['font-size']
61
+ expect(font_size).to eq 22
62
+ end
63
+ end
64
+
65
+ describe 'css_reader sets up the bounds for image' do
66
+ subject { @layout.image }
67
+ its(:top) { should eq(720) }
68
+ its(:bottom) { should eq(308) }
69
+ its(:height) { should eq(412) }
70
+ its(:left) { should eq(576) }
71
+ its(:right) { should eq(1080) }
72
+ its(:width) { should eq(504) }
73
+ end
74
+
75
+ describe 'css_reader creates header style' do
76
+ subject { @layout.header }
77
+ it 'should have background color in its hash' do
78
+ expect(subject['background-color']).to eq('#ffffff')
79
+ end
80
+ end
81
+
82
+ describe "css_reader's other functions" do
83
+ subject { @layout.css_reader }
84
+
85
+ it 'convert string css rules string into hash of strings' do
86
+ css_rules = 'bread: howdy; basket: belly'
87
+ specs_hash = { 'bread' => 'howdy', 'basket' => 'belly' }
88
+ expect(subject.rules_to_specs(css_rules)).to eq specs_hash
89
+ end
90
+
91
+ it 'convert css rules with commas into hash of arrays' do
92
+ css_rules = 'bread: howdy, belly'
93
+ specs_hash = { 'bread' => %w(howdy belly) }
94
+ expect(subject.rules_to_specs(css_rules)).to eq specs_hash
95
+ end
96
+
97
+ it 'convert selector names into valid ruby names' do
98
+ selector_name = '#a-nice-name.'
99
+ method_name = 'a_nice_name'
100
+ expect(subject.to_method_name(selector_name)).to eq method_name
101
+ end
102
+ end
103
+ end
104
+
105
+ context 'when given the basic_block stylesheet' do
106
+ it 'fails if mismatch between css and layout type' do
107
+ metadata = { 'stylesheet' => 'basic_block', 'layout' => 'flow' }
108
+ Bread::Basket::Poster.dir_path = './spec/poster/test_files'
109
+
110
+ expect do
111
+ Bread::Basket::Poster::Layout.new(metadata)
112
+ end.to raise_error SystemExit
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,49 @@
1
+ describe Bread::Basket::Poster::HeaderMaker do
2
+ let(:pdf) { Prawn::Document.new }
3
+ # explanation of before(:all) in css_reader_spec
4
+ context 'when header selector is missing' do
5
+ let(:metadata) { { 'stylesheet' => 'nearly_empty' } }
6
+ let(:layout) { Bread::Basket::Poster::Layout.new(metadata) }
7
+
8
+ before(:each) do
9
+ Bread::Basket::Poster.dir_path = './spec/poster/test_files'
10
+ end
11
+
12
+ subject { Bread::Basket::Poster::HeaderMaker.new(pdf, layout) }
13
+
14
+ it "doesn't fail" do
15
+ expect do
16
+ subject.create_header('Header', 'font-size' => 12)
17
+ end.not_to raise_error
18
+ end
19
+
20
+ it 'returns layout styles as empty hash' do
21
+ expect(subject.layout_styles).to eq({})
22
+ end
23
+ end
24
+
25
+ context 'when header styles are provided they override' do
26
+ let(:metadata) { { 'stylesheet' => 'header_test' } }
27
+ let(:layout) { Bread::Basket::Poster::Layout.new(metadata) }
28
+ let(:header_maker) { Bread::Basket::Poster::HeaderMaker.new(pdf, layout) }
29
+
30
+ before(:each) do
31
+ Bread::Basket::Poster.dir_path = './spec/poster/test_files'
32
+ styles = Bread::Basket::Poster.current_styles
33
+ header_maker.create_header('Header', styles)
34
+ end
35
+
36
+ subject { header_maker.styles }
37
+
38
+ its(['width']) { should eq(300) }
39
+ its(['height']) { should eq(55) }
40
+
41
+ its(['font-size']) { should eq(73) }
42
+ its(['color']) { should eq('#cc00FF') }
43
+ its(['margin-top']) { should eq(13) }
44
+ its(['margin-bottom']) { should eq(17) }
45
+ its(['radius']) { should eq(11) }
46
+ its(['background-color']) { should eq('#000000') }
47
+ its(['font-family']) { should eq('Courier') }
48
+ end
49
+ end