crayfish 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/crayfish/html.rb CHANGED
@@ -71,6 +71,33 @@ module Crayfish
71
71
  @pdf = pdf
72
72
  end
73
73
 
74
+ def asset_paths
75
+ @@asset_paths ||= ::ActionView::Helpers::AssetTagHelper::AssetPaths.new(::Rails.configuration.action_controller)
76
+ end
77
+
78
+ def public_path_to_fs_path path
79
+ search_paths = [::Rails.public_path] + ::Rails.configuration.assets.paths
80
+ search_paths.each do |search_path|
81
+ if File.exists?("#{search_path}/#{path}")
82
+ return "#{search_path}/#{path}"
83
+ end
84
+ end
85
+
86
+ if /^\/assets\/(?<path>.*)$/ =~ path
87
+ search_paths.each do |search_path|
88
+ if File.exists?("#{search_path}/#{path}")
89
+ return "#{search_path}/#{path}"
90
+ end
91
+ end
92
+ end
93
+ raise "Could not locate #{path} in #{search_paths.inspect}"
94
+ end
95
+
96
+ def image_fs_path image
97
+ public_path = asset_paths.compute_public_path(image, 'images')
98
+ public_path_to_fs_path(public_path)
99
+ end
100
+
74
101
  def apply_style cell,style
75
102
  # background-color:#ccccff
76
103
  style.split(';').each do |style|
@@ -107,8 +134,7 @@ module Crayfish
107
134
 
108
135
  case name
109
136
  when :img
110
- # we would really like to use image_path here
111
- image = {:image => "app#{node.attributes['src'].value}"}
137
+ image = { :image => image_fs_path(node.attributes['src'].value) }
112
138
  image[:width] = node.attributes['width'].value.to_f if node.attributes['width']
113
139
  image[:height] = node.attributes['height'].value.to_f if node.attributes['height']
114
140
  return image
@@ -21,5 +21,5 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
 
23
23
  module Crayfish
24
- VERSION = "0.2.2"
24
+ VERSION = "0.2.3"
25
25
  end
@@ -1425,3 +1425,203 @@ undefined local variable or method `aaa' for #<CrayfishActionViewTest::ActionVie
1425
1425
   (0.1ms) rollback transaction
1426
1426
   (0.0ms) begin transaction
1427
1427
   (0.0ms) rollback transaction
1428
+  (0.3ms) begin transaction
1429
+  (0.0ms) rollback transaction
1430
+  (0.0ms) begin transaction
1431
+ unknown node p in CrayHtml
1432
+  (0.0ms) rollback transaction
1433
+  (0.0ms) begin transaction
1434
+  (0.0ms) rollback transaction
1435
+  (0.0ms) begin transaction
1436
+  (0.0ms) rollback transaction
1437
+  (0.0ms) begin transaction
1438
+  (0.0ms) rollback transaction
1439
+  (0.0ms) begin transaction
1440
+  (0.0ms) rollback transaction
1441
+  (0.0ms) begin transaction
1442
+  (0.0ms) rollback transaction
1443
+  (0.0ms) begin transaction
1444
+  (0.0ms) rollback transaction
1445
+  (0.0ms) begin transaction
1446
+  (0.0ms) rollback transaction
1447
+  (0.2ms) begin transaction
1448
+  (0.0ms) rollback transaction
1449
+  (0.0ms) begin transaction
1450
+ unknown node p in CrayHtml
1451
+  (0.0ms) rollback transaction
1452
+  (0.0ms) begin transaction
1453
+  (0.0ms) rollback transaction
1454
+  (0.0ms) begin transaction
1455
+  (0.0ms) rollback transaction
1456
+  (0.0ms) begin transaction
1457
+  (0.0ms) rollback transaction
1458
+  (0.0ms) begin transaction
1459
+  (0.0ms) rollback transaction
1460
+  (0.0ms) begin transaction
1461
+  (0.0ms) rollback transaction
1462
+  (0.0ms) begin transaction
1463
+  (0.0ms) rollback transaction
1464
+  (0.0ms) begin transaction
1465
+  (0.0ms) rollback transaction
1466
+  (0.3ms) begin transaction
1467
+  (0.0ms) rollback transaction
1468
+  (0.0ms) begin transaction
1469
+ unknown node p in CrayHtml
1470
+  (0.0ms) rollback transaction
1471
+  (0.0ms) begin transaction
1472
+  (0.0ms) rollback transaction
1473
+  (0.0ms) begin transaction
1474
+  (0.0ms) rollback transaction
1475
+  (0.0ms) begin transaction
1476
+  (0.0ms) rollback transaction
1477
+  (0.0ms) begin transaction
1478
+  (0.0ms) rollback transaction
1479
+  (0.0ms) begin transaction
1480
+  (0.0ms) rollback transaction
1481
+  (0.0ms) begin transaction
1482
+  (0.0ms) rollback transaction
1483
+  (0.3ms) begin transaction
1484
+  (0.0ms) rollback transaction
1485
+  (0.0ms) begin transaction
1486
+ unknown node p in CrayHtml
1487
+  (0.0ms) rollback transaction
1488
+  (0.0ms) begin transaction
1489
+  (0.0ms) rollback transaction
1490
+  (0.0ms) begin transaction
1491
+  (0.0ms) rollback transaction
1492
+  (0.0ms) begin transaction
1493
+  (0.0ms) rollback transaction
1494
+  (0.0ms) begin transaction
1495
+  (0.0ms) rollback transaction
1496
+  (0.0ms) begin transaction
1497
+  (0.0ms) rollback transaction
1498
+  (0.0ms) begin transaction
1499
+  (0.0ms) rollback transaction
1500
+  (0.0ms) begin transaction
1501
+  (0.0ms) rollback transaction
1502
+  (0.3ms) begin transaction
1503
+  (0.0ms) rollback transaction
1504
+  (0.0ms) begin transaction
1505
+ unknown node p in CrayHtml
1506
+  (0.0ms) rollback transaction
1507
+  (0.0ms) begin transaction
1508
+  (0.0ms) rollback transaction
1509
+  (0.0ms) begin transaction
1510
+  (0.0ms) rollback transaction
1511
+  (0.0ms) begin transaction
1512
+  (0.0ms) rollback transaction
1513
+  (0.0ms) begin transaction
1514
+  (0.0ms) rollback transaction
1515
+  (0.0ms) begin transaction
1516
+  (0.0ms) rollback transaction
1517
+  (0.0ms) begin transaction
1518
+  (0.0ms) rollback transaction
1519
+  (0.0ms) begin transaction
1520
+  (0.0ms) rollback transaction
1521
+  (0.0ms) begin transaction
1522
+  (0.0ms) rollback transaction
1523
+  (0.3ms) begin transaction
1524
+  (0.0ms) rollback transaction
1525
+  (0.0ms) begin transaction
1526
+ unknown node p in CrayHtml
1527
+  (0.0ms) rollback transaction
1528
+  (0.0ms) begin transaction
1529
+  (0.0ms) rollback transaction
1530
+  (0.0ms) begin transaction
1531
+  (0.0ms) rollback transaction
1532
+  (0.0ms) begin transaction
1533
+  (0.0ms) rollback transaction
1534
+  (0.0ms) begin transaction
1535
+  (0.0ms) rollback transaction
1536
+  (0.0ms) begin transaction
1537
+  (0.0ms) rollback transaction
1538
+  (0.0ms) begin transaction
1539
+  (0.0ms) rollback transaction
1540
+  (0.0ms) begin transaction
1541
+  (0.0ms) rollback transaction
1542
+  (0.0ms) begin transaction
1543
+  (0.0ms) rollback transaction
1544
+  (0.2ms) begin transaction
1545
+  (0.0ms) rollback transaction
1546
+  (0.0ms) begin transaction
1547
+ unknown node p in CrayHtml
1548
+  (0.0ms) rollback transaction
1549
+  (0.0ms) begin transaction
1550
+  (0.0ms) rollback transaction
1551
+  (0.0ms) begin transaction
1552
+  (0.0ms) rollback transaction
1553
+  (0.0ms) begin transaction
1554
+  (0.0ms) rollback transaction
1555
+  (0.0ms) begin transaction
1556
+  (0.0ms) rollback transaction
1557
+  (0.0ms) begin transaction
1558
+  (0.0ms) rollback transaction
1559
+  (0.0ms) begin transaction
1560
+  (0.0ms) rollback transaction
1561
+  (0.0ms) begin transaction
1562
+  (0.0ms) rollback transaction
1563
+  (0.0ms) begin transaction
1564
+  (0.0ms) rollback transaction
1565
+  (0.3ms) begin transaction
1566
+  (0.0ms) rollback transaction
1567
+  (0.0ms) begin transaction
1568
+ unknown node p in CrayHtml
1569
+  (0.0ms) rollback transaction
1570
+  (0.0ms) begin transaction
1571
+  (0.0ms) rollback transaction
1572
+  (0.0ms) begin transaction
1573
+  (0.0ms) rollback transaction
1574
+  (0.0ms) begin transaction
1575
+  (0.0ms) rollback transaction
1576
+  (0.0ms) begin transaction
1577
+  (0.0ms) rollback transaction
1578
+  (0.0ms) begin transaction
1579
+  (0.0ms) rollback transaction
1580
+  (0.0ms) begin transaction
1581
+  (0.0ms) rollback transaction
1582
+  (0.0ms) begin transaction
1583
+  (0.0ms) rollback transaction
1584
+  (0.0ms) begin transaction
1585
+  (0.0ms) rollback transaction
1586
+  (0.3ms) begin transaction
1587
+  (0.0ms) rollback transaction
1588
+  (0.0ms) begin transaction
1589
+ unknown node p in CrayHtml
1590
+  (0.0ms) rollback transaction
1591
+  (0.0ms) begin transaction
1592
+  (0.0ms) rollback transaction
1593
+  (0.0ms) begin transaction
1594
+  (0.0ms) rollback transaction
1595
+  (0.0ms) begin transaction
1596
+  (0.0ms) rollback transaction
1597
+  (0.0ms) begin transaction
1598
+  (0.0ms) rollback transaction
1599
+  (0.0ms) begin transaction
1600
+  (0.0ms) rollback transaction
1601
+  (0.0ms) begin transaction
1602
+  (0.0ms) rollback transaction
1603
+  (0.0ms) begin transaction
1604
+  (0.0ms) rollback transaction
1605
+  (0.0ms) begin transaction
1606
+  (0.0ms) rollback transaction
1607
+  (0.2ms) begin transaction
1608
+  (0.0ms) rollback transaction
1609
+  (0.0ms) begin transaction
1610
+ unknown node p in CrayHtml
1611
+  (0.0ms) rollback transaction
1612
+  (0.0ms) begin transaction
1613
+  (0.0ms) rollback transaction
1614
+  (0.0ms) begin transaction
1615
+  (0.0ms) rollback transaction
1616
+  (0.0ms) begin transaction
1617
+  (0.0ms) rollback transaction
1618
+  (0.0ms) begin transaction
1619
+  (0.0ms) rollback transaction
1620
+  (0.0ms) begin transaction
1621
+  (0.0ms) rollback transaction
1622
+  (0.0ms) begin transaction
1623
+  (0.0ms) rollback transaction
1624
+  (0.0ms) begin transaction
1625
+  (0.0ms) rollback transaction
1626
+  (0.0ms) begin transaction
1627
+  (0.0ms) rollback transaction
data/test/html_test.rb CHANGED
@@ -28,11 +28,29 @@ class HtmlTest < ActiveSupport::TestCase
28
28
  @html = ::Crayfish::Html.new(nil,nil)
29
29
  end
30
30
 
31
+ test "should locate public files" do
32
+ ::Rails.stubs(:public_path).returns('/pub')
33
+ ::Rails.configuration.assets.stubs(:paths).returns([])
34
+ File.expects(:exists?).with("/pub/a.file").returns(true)
35
+ assert_equal "/pub/a.file", @html.public_path_to_fs_path('a.file')
36
+ end
37
+
38
+ test "should locate public files in a asset path" do
39
+ ::Rails.stubs(:public_path).returns('/pub')
40
+ ::Rails.configuration.assets.stubs(:paths).returns(['/assets'])
41
+ File.expects(:exists?).with("/pub/a.file").returns(false)
42
+ File.expects(:exists?).with("/assets/a.file").returns(true)
43
+ assert_equal "/assets/a.file", @html.public_path_to_fs_path('a.file')
44
+ end
45
+
31
46
  test "compile img" do
32
47
  img = stub('html img')
33
48
  img.stubs(:name).returns(:img)
34
- img.stubs(:attributes).returns({ 'src' => OpenStruct.new(:value => '/some url')})
35
- assert_equal @html.compile(img), :image=>"app/some url"
49
+ img.stubs(:attributes).returns({ 'src' => OpenStruct.new(:value => 'a.file')})
50
+ ::Rails.stubs(:public_path).returns('/pub')
51
+ ::Rails.configuration.assets.stubs(:paths).returns([])
52
+ File.expects(:exists?).with("/pub//images/a.file").returns(true)
53
+ assert_equal @html.compile(img), :image=>"/pub//images/a.file"
36
54
  end
37
55
 
38
56
  test "compile empty td" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crayfish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-27 00:00:00.000000000Z
12
+ date: 2012-05-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70290046667320 !ruby/object:Gem::Requirement
16
+ requirement: &70107095324480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70290046667320
24
+ version_requirements: *70107095324480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: prawn
27
- requirement: &70290046666360 !ruby/object:Gem::Requirement
27
+ requirement: &70107095323160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70290046666360
35
+ version_requirements: *70107095323160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &70290046665540 !ruby/object:Gem::Requirement
38
+ requirement: &70107095321480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70290046665540
46
+ version_requirements: *70107095321480
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &70290046663920 !ruby/object:Gem::Requirement
49
+ requirement: &70107095319680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70290046663920
57
+ version_requirements: *70107095319680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
60
- requirement: &70290046660760 !ruby/object:Gem::Requirement
60
+ requirement: &70107095318780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70290046660760
68
+ version_requirements: *70107095318780
69
69
  description: Crayfish - PDF templating for Rails
70
70
  email:
71
71
  - patrick.hanevold@gmail.com
@@ -133,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  segments:
135
135
  - 0
136
- hash: 791229958043033619
136
+ hash: 4351079184167744567
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  segments:
144
144
  - 0
145
- hash: 791229958043033619
145
+ hash: 4351079184167744567
146
146
  requirements: []
147
147
  rubyforge_project:
148
148
  rubygems_version: 1.8.15