html_mockup 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/html_mockup.gemspec +2 -1
- data/lib/html_mockup/extractor.rb +34 -17
- metadata +19 -8
data/CHANGELOG.md
CHANGED
data/html_mockup.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "html_mockup"
|
5
|
-
s.version = "0.6.
|
5
|
+
s.version = "0.6.5"
|
6
6
|
|
7
7
|
s.authors = ["Flurin Egger", "Edwin van der Graaf"]
|
8
8
|
s.email = ["info@digitpaint.nl", "flurin@digitpaint.nl"]
|
@@ -28,4 +28,5 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_dependency("thor", ["~> 0.16.0"])
|
29
29
|
s.add_dependency("rack", [">= 1.0.0"])
|
30
30
|
s.add_dependency("tilt", [">= 0"])
|
31
|
+
s.add_dependency("hpricot", [">= 0.6.4"])
|
31
32
|
end
|
@@ -5,16 +5,23 @@ module HtmlMockup
|
|
5
5
|
|
6
6
|
attr_reader :project, :target_path
|
7
7
|
|
8
|
+
|
9
|
+
# @param [Project] project Project object
|
10
|
+
# @param [String,Pathname] target_path Path to extract to
|
11
|
+
# @param [Hash] options Options hash
|
12
|
+
|
13
|
+
# @option options [Array] :url_attributes The element attributes to parse and relativize
|
14
|
+
# @option options [Array] :url_relativize Wether or not we should relativize
|
8
15
|
def initialize(project, target_path, options={})
|
9
16
|
@project = project
|
10
17
|
@target_path = Pathname.new(target_path)
|
11
18
|
|
12
19
|
@options = {
|
13
|
-
:url_attributes => %w{src href action}
|
20
|
+
:url_attributes => %w{src href action},
|
21
|
+
:url_relativize => true
|
14
22
|
}
|
15
23
|
|
16
24
|
@options.update(options) if options
|
17
|
-
|
18
25
|
end
|
19
26
|
|
20
27
|
def run!
|
@@ -34,23 +41,12 @@ module HtmlMockup
|
|
34
41
|
Dir.chdir(source_path) do
|
35
42
|
Dir.glob(filter).each do |file_name|
|
36
43
|
source = HtmlMockup::Template.open(file_name, :partial_path => partial_path).render
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@options[:url_attributes].each do |attribute|
|
41
|
-
(doc/"*[@#{attribute}]").each do |tag|
|
42
|
-
converted_url = convert_relative_url_to_absolute_url(tag[attribute], cur_dir, up_to_root)
|
43
|
-
|
44
|
-
case converted_url
|
45
|
-
when String
|
46
|
-
tag[attribute] = converted_url
|
47
|
-
when nil
|
48
|
-
puts "Could not resolve link #{tag[attribute]} in #{file_name}"
|
49
|
-
end
|
50
|
-
end
|
44
|
+
|
45
|
+
if @options[:url_relativize]
|
46
|
+
source = relativize_urls(source, file_name)
|
51
47
|
end
|
52
48
|
|
53
|
-
File.open(target_path + file_name,"w"){|f| f.write(
|
49
|
+
File.open(target_path + file_name,"w"){|f| f.write(source) }
|
54
50
|
end
|
55
51
|
end
|
56
52
|
end
|
@@ -58,6 +54,27 @@ module HtmlMockup
|
|
58
54
|
|
59
55
|
protected
|
60
56
|
|
57
|
+
def relativize_urls(source, file_name)
|
58
|
+
cur_dir = Pathname.new(file_name).dirname
|
59
|
+
up_to_root = File.join([".."] * (file_name.split("/").size - 1))
|
60
|
+
|
61
|
+
doc = Hpricot(source)
|
62
|
+
@options[:url_attributes].each do |attribute|
|
63
|
+
(doc/"*[@#{attribute}]").each do |tag|
|
64
|
+
converted_url = convert_relative_url_to_absolute_url(tag[attribute], cur_dir, up_to_root)
|
65
|
+
|
66
|
+
case converted_url
|
67
|
+
when String
|
68
|
+
tag[attribute] = converted_url
|
69
|
+
when nil
|
70
|
+
puts "Could not resolve link #{tag[attribute]} in #{file_name}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
doc.to_original_html
|
76
|
+
end
|
77
|
+
|
61
78
|
# @return [false, nil, String] False if it can't be converted, nil if it can't be resolved and the converted string if it can be resolved.
|
62
79
|
def convert_relative_url_to_absolute_url(url, cur_dir, up_to_root)
|
63
80
|
# Skip if the url doesn't start with a / (but not with //)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_mockup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: thor
|
17
|
-
requirement: &
|
17
|
+
requirement: &70323203509020 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.16.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70323203509020
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rack
|
28
|
-
requirement: &
|
28
|
+
requirement: &70323203508540 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70323203508540
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: tilt
|
39
|
-
requirement: &
|
39
|
+
requirement: &70323202817780 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,18 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70323202817780
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: hpricot
|
50
|
+
requirement: &70323202816620 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.6.4
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70323202816620
|
48
59
|
description:
|
49
60
|
email:
|
50
61
|
- info@digitpaint.nl
|