terrimporter 0.7.2 → 0.7.3
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.
- data/lib/terrimporter/importer.rb +18 -13
- data/lib/terrimporter/importer_helper.rb +16 -1
- data/lib/terrimporter/version.rb +2 -2
- data/public/javascripts/base.js +1 -0
- data/public/stylesheets/base.css +1 -0
- data/test/fixtures/css/invalid.css +1 -0
- data/test/unit/test_importer.rb +11 -3
- metadata +8 -12
- data/test/test/tmp/public/javascripts/base.js +0 -1
- data/test/test/tmp/public/javascripts/lib/dynlib.js +0 -1
- data/test/test/tmp/public/stylesheets/base.css +0 -1
- data/test/test/tmp/public/stylesheets/ie.css +0 -1
@@ -54,23 +54,28 @@ module TerrImporter
|
|
54
54
|
constructed_file_path = (config.replace_style_strings? ? unclean_file_path : file_path)
|
55
55
|
@downloader.download(source_url, constructed_file_path)
|
56
56
|
|
57
|
-
if
|
58
|
-
|
59
|
-
|
60
|
-
File.open(
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
if file_contains_valid_css?(constructed_file_path)
|
58
|
+
if config.replace_style_strings?
|
59
|
+
LOG.info "CSS line replacements"
|
60
|
+
File.open(file_path, 'w') do |d|
|
61
|
+
File.open(constructed_file_path, 'r') do |s|
|
62
|
+
lines = s.readlines
|
63
|
+
lines.each do |line|
|
64
|
+
d.print replace_stylesheet_lines!(line)
|
65
|
+
end
|
64
66
|
end
|
65
67
|
end
|
68
|
+
else
|
69
|
+
LOG.debug "Skipping css line replacements"
|
66
70
|
end
|
67
|
-
else
|
68
|
-
LOG.debug "Skipping css line replacements"
|
69
|
-
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
if File.exists?(unclean_file_path)
|
73
|
+
LOG.debug "Deleting unclean css files"
|
74
|
+
FileUtils.remove unclean_file_path
|
75
|
+
end
|
76
|
+
else
|
77
|
+
File.remove(file_path)
|
78
|
+
LOG.debug "Deleting empty"
|
74
79
|
end
|
75
80
|
end
|
76
81
|
end
|
@@ -1,9 +1,24 @@
|
|
1
1
|
module ImporterHelper
|
2
2
|
|
3
|
+
CSS_PATTERN = /^[a-zA-Z]+/ #only check if a line starts with characters, not comments
|
4
|
+
|
3
5
|
def replace_line!(line, what, with)
|
4
6
|
what = Regexp.new "#{$1}" if what.match(/^r\/(.*)\//)
|
5
7
|
LOG.info "Replacing #{what.to_s} with #{with}"
|
6
8
|
line.gsub! what, with
|
7
9
|
end
|
8
10
|
|
9
|
-
|
11
|
+
def file_contains_valid_css?(file_path)
|
12
|
+
css_valid = false
|
13
|
+
File.open(file_path) do |f|
|
14
|
+
f.each_line do |line|
|
15
|
+
if line =~ CSS_PATTERN
|
16
|
+
css_valid = true
|
17
|
+
break
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
css_valid
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/lib/terrimporter/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
This is the base.js file
|
@@ -0,0 +1 @@
|
|
1
|
+
This is the base.css file
|
@@ -0,0 +1 @@
|
|
1
|
+
/* This file only contains a comment */
|
data/test/unit/test_importer.rb
CHANGED
@@ -50,11 +50,20 @@ class TestImporter < Test::Unit::TestCase
|
|
50
50
|
should 'not do any string replacement if not configured' do
|
51
51
|
@importer.config['stylesheets']['replace_strings'] = nil
|
52
52
|
@importer.import_css
|
53
|
-
|
54
53
|
assert true
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
57
|
+
context 'invalid css recognition' do
|
58
|
+
should 'return false if an invalid css file is passed' do
|
59
|
+
assert_equal false, @importer.file_contains_valid_css?(File.expand_path('test/fixtures/css/invalid.css'))
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'return true if a valid css file is passed' do
|
63
|
+
assert_equal true, @importer.file_contains_valid_css?(File.expand_path('test/fixtures/css/base.css'))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
58
67
|
context 'css and js export path construction' do
|
59
68
|
setup do
|
60
69
|
@importer.config['export_path'] = {'css' => 'base.css', 'js' => 'base.js'}
|
@@ -120,8 +129,7 @@ class TestImporter < Test::Unit::TestCase
|
|
120
129
|
end
|
121
130
|
|
122
131
|
should 'import js, css and images, not using the :all statement' do
|
123
|
-
@importer.run
|
124
|
-
#only cherry-pick tests
|
132
|
+
@importer.run #only cherry-pick tests
|
125
133
|
assert exists_in_tmp?('public/images/testimage1.png')
|
126
134
|
assert exists_in_tmp?('public/stylesheets/base.css')
|
127
135
|
assert exists_in_tmp?('public/javascripts/base.js')
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terrimporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 3
|
10
|
+
version: 0.7.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Kummer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-27 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: kwalify
|
@@ -138,9 +138,12 @@ files:
|
|
138
138
|
- lib/terrimporter/options.rb
|
139
139
|
- lib/terrimporter/string_monkeypatch.rb
|
140
140
|
- lib/terrimporter/version.rb
|
141
|
+
- public/javascripts/base.js
|
142
|
+
- public/stylesheets/base.css
|
141
143
|
- terrimporter.gemspec
|
142
144
|
- test/fixtures/css/base.css
|
143
145
|
- test/fixtures/css/ie.css
|
146
|
+
- test/fixtures/css/invalid.css
|
144
147
|
- test/fixtures/html/application_root.html
|
145
148
|
- test/fixtures/html/application_root_css_error.html
|
146
149
|
- test/fixtures/html/application_root_js_error.html
|
@@ -156,10 +159,6 @@ files:
|
|
156
159
|
- test/fixtures/js/dynlib.js
|
157
160
|
- test/fixtures/minimal.test.config.yml
|
158
161
|
- test/fixtures/test.config.yml
|
159
|
-
- test/test/tmp/public/javascripts/base.js
|
160
|
-
- test/test/tmp/public/javascripts/lib/dynlib.js
|
161
|
-
- test/test/tmp/public/stylesheets/base.css
|
162
|
-
- test/test/tmp/public/stylesheets/ie.css
|
163
162
|
- test/test_helper.rb
|
164
163
|
- test/test_terrimporter.rb
|
165
164
|
- test/unit/test_app_logger.rb
|
@@ -208,6 +207,7 @@ summary: Import terrific javascripts, css files and images into a web project
|
|
208
207
|
test_files:
|
209
208
|
- test/fixtures/css/base.css
|
210
209
|
- test/fixtures/css/ie.css
|
210
|
+
- test/fixtures/css/invalid.css
|
211
211
|
- test/fixtures/html/application_root.html
|
212
212
|
- test/fixtures/html/application_root_css_error.html
|
213
213
|
- test/fixtures/html/application_root_js_error.html
|
@@ -223,10 +223,6 @@ test_files:
|
|
223
223
|
- test/fixtures/js/dynlib.js
|
224
224
|
- test/fixtures/minimal.test.config.yml
|
225
225
|
- test/fixtures/test.config.yml
|
226
|
-
- test/test/tmp/public/javascripts/base.js
|
227
|
-
- test/test/tmp/public/javascripts/lib/dynlib.js
|
228
|
-
- test/test/tmp/public/stylesheets/base.css
|
229
|
-
- test/test/tmp/public/stylesheets/ie.css
|
230
226
|
- test/test_helper.rb
|
231
227
|
- test/test_terrimporter.rb
|
232
228
|
- test/unit/test_app_logger.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
/Users/dkummer/_projects/terrimporter/test/test/fixtures/js/base.js
|
@@ -1 +0,0 @@
|
|
1
|
-
/Users/dkummer/_projects/terrimporter/test/test/fixtures/js/dynlib.js
|
@@ -1 +0,0 @@
|
|
1
|
-
/Users/dkummer/_projects/terrimporter/test/test/fixtures/css/base.css
|
@@ -1 +0,0 @@
|
|
1
|
-
/Users/dkummer/_projects/terrimporter/test/test/fixtures/css/ie.css
|