terrimporter 0.6.0 → 0.6.4
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/Gemfile.lock +1 -1
- data/README.rdoc +4 -0
- data/Rakefile +1 -3
- data/config/schema.yml +16 -25
- data/config/terrimporter.config.yml +47 -66
- data/lib/terrimporter.rb +4 -3
- data/lib/terrimporter/array_monkeypatch.rb +11 -0
- data/lib/terrimporter/config_helper.rb +8 -2
- data/lib/terrimporter/configuration.rb +48 -1
- data/lib/terrimporter/downloader.rb +17 -13
- data/lib/terrimporter/importer.rb +96 -43
- data/lib/terrimporter/options.rb +3 -3
- data/lib/terrimporter/string_monkeypatch.rb +12 -0
- data/lib/terrimporter/version.rb +2 -2
- data/terrimporter.config.yml.bak +47 -0
- data/test/fixtures/html/application_root.html +16 -0
- data/test/fixtures/invalid.config.yml +8 -11
- data/test/fixtures/minimal.test.config.yml +13 -0
- data/test/fixtures/test.config.yml +15 -54
- data/test/test_helper.rb +4 -0
- data/test/test_terrimporter.rb +8 -1
- data/test/unit/test_arraymonkeypatch.rb +12 -0
- data/test/unit/test_config_helper.rb +6 -0
- data/test/unit/test_configuration.rb +67 -5
- data/test/unit/test_downloader.rb +13 -6
- data/test/unit/test_importer.rb +32 -11
- data/test/unit/test_options.rb +11 -22
- data/test/unit/test_stringmonkeypatch.rb +12 -0
- data/test/watch.rb +71 -0
- metadata +17 -13
- data/lib/terrimporter/config_validator.rb +0 -21
- data/tasks/load_tasks.rb +0 -3
- data/tasks/version.rake +0 -2
- data/test/helper.rb +0 -0
- data/test/terrimporter.config.yml +0 -68
- data/test/unit/test_config_validator.rb +0 -20
data/lib/terrimporter/options.rb
CHANGED
@@ -13,7 +13,8 @@ module TerrImporter
|
|
13
13
|
|
14
14
|
require 'optparse'
|
15
15
|
@opts = OptionParser.new do |o|
|
16
|
-
o.banner = "Usage: #{File.basename($0)} [options] \n
|
16
|
+
o.banner = "Usage: #{File.basename($0)} [options] \n" +
|
17
|
+
"Use #{File.basename($0)} [application_url] --init to initialize importer before first usage."
|
17
18
|
|
18
19
|
o.separator ''
|
19
20
|
o.separator 'Common options:'
|
@@ -54,7 +55,7 @@ module TerrImporter
|
|
54
55
|
|
55
56
|
begin
|
56
57
|
@opts.parse!(args)
|
57
|
-
|
58
|
+
self[:application_url] = args.shift
|
58
59
|
rescue OptionParser::InvalidOption => e
|
59
60
|
self[:invalid_argument] = e.message
|
60
61
|
end
|
@@ -63,7 +64,6 @@ module TerrImporter
|
|
63
64
|
def merge(other)
|
64
65
|
self.class.new(@orig_args + other.orig_args)
|
65
66
|
end
|
66
|
-
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
data/lib/terrimporter/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
#-------------------------------------------------------------------------------
|
2
|
+
# terrimporter configuration, adjust as needed. Don't mess with indentation!
|
3
|
+
#-------------------------------------------------------------------------------
|
4
|
+
# url: Terrific base url
|
5
|
+
application_url: test
|
6
|
+
|
7
|
+
# STYLESHEETS
|
8
|
+
stylesheets:
|
9
|
+
# The destination directory, relative from the current running directory
|
10
|
+
relative_destination_path: public/stylesheets/
|
11
|
+
# Additional stylesheets, you can but don't have to add the .css extension
|
12
|
+
# styles: ie, ie6, ie7.css
|
13
|
+
# replace_strings: Define string replacements in css files
|
14
|
+
# (use multiple replacements by repeating the '-what: with:' statements)
|
15
|
+
replace_strings:
|
16
|
+
# - what: /img/ # What to replace, format: [string] or [r/regex/]
|
17
|
+
# with: /images/ # Replace with [string]
|
18
|
+
|
19
|
+
# JAVASCRIPTS
|
20
|
+
javascripts:
|
21
|
+
# Destination path of the javascript base.js file
|
22
|
+
relative_destination_path: public/javascripts/
|
23
|
+
# Dynamic libraries definition, you can but don't have to add the .js extension
|
24
|
+
# dynamic_libraries: foo_lib.js bar_lib.js
|
25
|
+
# Destination path of the dynamic libraries relative
|
26
|
+
# libraries_relative_destination_path: public/javascripts/libraries/
|
27
|
+
|
28
|
+
# IMAGES - multiple entries allowed
|
29
|
+
images:
|
30
|
+
# - server_path: / # The server path is appended to the image_server_path
|
31
|
+
# relative_destination_path: public/images/ # The relative destination path
|
32
|
+
# file_types: jpg, png, gif # Image file endings to be downloaded
|
33
|
+
|
34
|
+
#-------------------------------------------------------------------------------
|
35
|
+
# ADVANCED EDITING - Only edit the following if you know what you're doing...
|
36
|
+
# ------------------------------------------------------------------------------
|
37
|
+
# The settings below are added as query string parameters to the export path
|
38
|
+
export_settings:
|
39
|
+
debug: false # False compacts the base.js and base.css files
|
40
|
+
cache: false # You most probably won't have to change this
|
41
|
+
layout: project # You most probably won't have to change this
|
42
|
+
|
43
|
+
# The server side library source path for the dynamic libraries
|
44
|
+
libraries_server_path: /js/libraries/dynamic
|
45
|
+
|
46
|
+
# The server side image base path
|
47
|
+
image_server_path: /img
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<head>
|
3
|
+
<title>Some title</title>
|
4
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
5
|
+
<meta name="language" content="de-ch, de"/>
|
6
|
+
<link href="/img/favicon.png" rel="apple-touch-icon"/>
|
7
|
+
<link href="/img/favicon.ico" rel="shortcut icon"/>
|
8
|
+
<link href="/terrific/base/0.5/public/css/base/base.css.php?appbaseurl=&application=/terrific/webapp/path&layout=project&debug=true&cache=false&t=1314606536"
|
9
|
+
media="all" rel="stylesheet" type="text/css"/>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
|
13
|
+
<script type="text/javascript"
|
14
|
+
src="/terrific/base/0.5/public/js/base/base.js.php?application=/terrific/webapp/path&layout=project&debug=true&cache=false&t=1314606536"></script>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -1,9 +1,6 @@
|
|
1
|
-
version:
|
2
1
|
url: http://terrific.url
|
3
|
-
|
4
|
-
|
5
|
-
libraries_source_path: /js/libraries/dynamic
|
6
|
-
image_base_path: /img
|
2
|
+
libraries_server_path: /js/libraries/dynamic
|
3
|
+
image_server_path: /img
|
7
4
|
export_settings:
|
8
5
|
layout: project
|
9
6
|
debug: false
|
@@ -11,17 +8,17 @@
|
|
11
8
|
stylesheets:
|
12
9
|
dest: test/tmp/public/stylesheets/
|
13
10
|
styles: ie.css
|
14
|
-
|
11
|
+
replace_strings:
|
15
12
|
- what: /img/
|
16
13
|
with: /images/
|
17
14
|
javascripts:
|
18
15
|
dest: test/tmp/public/javascripts/
|
19
16
|
dynamic_libraries: dynlib.js
|
20
|
-
|
17
|
+
libraries_relative_destination_path: /lib
|
21
18
|
images:
|
22
|
-
-
|
19
|
+
- server_path: /
|
23
20
|
dest: test/tmp/public/images/
|
24
|
-
|
25
|
-
-
|
21
|
+
file_types: jpg png gif
|
22
|
+
- server_path: /backgrounds
|
26
23
|
dest: test/tmp/public/images/backgrounds/
|
27
|
-
|
24
|
+
file_types: jpg
|
@@ -0,0 +1,13 @@
|
|
1
|
+
application_url: http://terrific.url
|
2
|
+
libraries_server_path: /js/libraries/dynamic
|
3
|
+
image_server_path: /img
|
4
|
+
export_settings:
|
5
|
+
layout: project
|
6
|
+
debug: false
|
7
|
+
cache: false
|
8
|
+
stylesheets:
|
9
|
+
relative_destination_path: test/tmp/public/stylesheets/
|
10
|
+
javascripts:
|
11
|
+
relative_destination_path: test/tmp/public/javascripts/
|
12
|
+
images:
|
13
|
+
|
@@ -1,64 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
# version: Define the terrific version in use
|
5
|
-
# url: Terrific base url
|
6
|
-
# app_path Terrific application path (must start with '/')
|
7
|
-
# export_path You most probably won't have to change this
|
8
|
-
# image_base_path: The Terrific image base path. You most probably won't have to change this
|
9
|
-
# libraries_source_path: The library source path. You most probably won't have to change this
|
10
|
-
# downloader: The downloader to use, supported are 'curl' and 'wget'
|
11
|
-
#
|
12
|
-
# export_settings: The settings below are added as query parameters for base.js and base.css
|
13
|
-
# layout: You most probably won't have to change this
|
14
|
-
# debug: False compacts the base.js and base.css files
|
15
|
-
# cache: You most probably won't have to change this
|
16
|
-
#
|
17
|
-
# stylesheets: Define the stylesheets in the following form:
|
18
|
-
# dest: The destination directory, relative from the current running directory
|
19
|
-
# styles: Name of the stylesheets, space separated without the .css extension. ex: ie ie6 ie7 ie8
|
20
|
-
# the main style base.css is included by default and MUST NOT BE SPECIFIED
|
21
|
-
# replace: Define path replacements after the stylesheets have been downloaded
|
22
|
-
# you can define multiple replacements by repeating the '-what: with:' statements
|
23
|
-
# - what: What to replace, default is string. if you want to use regex, use the format r/[regex]/
|
24
|
-
# for help on regular expressions see http://www.rubular.com/ (an online editor/tester)
|
25
|
-
# with: Replace with this (string)
|
26
|
-
#
|
27
|
-
# javascripts: Define the javascript files in the following form
|
28
|
-
# dest: Destination of the javascript base.js file
|
29
|
-
# dynamic_libraries: Dynamic libraries definition, space separated without the .js extension. ex: warning pngfix
|
30
|
-
# libraries_dest: Destination of the dynamic libraries relative to the 'dest' path. '/' means they're included in 'dest'
|
31
|
-
#
|
32
|
-
# images: Define the images to be downloaded, the terrific base path is always "img", so the src root is "img/"
|
33
|
-
# each of the entries describes one path for images to be downloaded
|
34
|
-
# -src: The source path, "/" means "img/"
|
35
|
-
# dest: The destination directory, relative from the current running directory
|
36
|
-
# types: The image endings to be downloaded, specified as a space separated string
|
37
|
-
########################################################################################################################
|
38
|
-
version: 0.5
|
39
|
-
url: http://terrific.url
|
40
|
-
app_path: /terrific/webapp/path
|
41
|
-
export_path: /terrific/base/%2$s/public/%1$s/base/base.%1$s.php
|
42
|
-
libraries_source_path: /js/libraries/dynamic
|
43
|
-
image_base_path: /img
|
1
|
+
application_url: http://terrific.url
|
2
|
+
libraries_server_path: /js/libraries/dynamic
|
3
|
+
image_server_path: /img
|
44
4
|
export_settings:
|
45
5
|
layout: project
|
46
6
|
debug: false
|
47
7
|
cache: false
|
48
8
|
stylesheets:
|
49
|
-
|
50
|
-
styles: ie
|
51
|
-
|
9
|
+
relative_destination_path: test/tmp/public/stylesheets/
|
10
|
+
styles: ie.css
|
11
|
+
replace_strings:
|
52
12
|
- what: /img/
|
53
13
|
with: /images/
|
54
14
|
javascripts:
|
55
|
-
|
15
|
+
relative_destination_path: test/tmp/public/javascripts/
|
56
16
|
dynamic_libraries: dynlib
|
57
|
-
|
17
|
+
libraries_relative_destination_path: test/tmp/public/javascripts/lib
|
58
18
|
images:
|
59
|
-
-
|
60
|
-
|
61
|
-
|
62
|
-
-
|
63
|
-
|
64
|
-
|
19
|
+
- server_path: /
|
20
|
+
relative_destination_path: test/tmp/public/images/
|
21
|
+
file_types: jpg, png, gif
|
22
|
+
- server_path: /backgrounds
|
23
|
+
relative_destination_path: test/tmp/public/images/backgrounds/
|
24
|
+
file_types: jpg
|
25
|
+
|
data/test/test_helper.rb
CHANGED
@@ -30,6 +30,10 @@ class Test::Unit::TestCase
|
|
30
30
|
File.join(File.dirname(__FILE__), 'fixtures', 'test.config.yml')
|
31
31
|
end
|
32
32
|
|
33
|
+
def min_test_config_file_path
|
34
|
+
File.join(File.dirname(__FILE__), 'fixtures', 'minimal.test.config.yml')
|
35
|
+
end
|
36
|
+
|
33
37
|
def tmp_test_directory
|
34
38
|
File.join(File.dirname(__FILE__), 'tmp')
|
35
39
|
end
|
data/test/test_terrimporter.rb
CHANGED
@@ -22,7 +22,8 @@ class TestTerrimporter < Test::Unit::TestCase
|
|
22
22
|
should 'merge environment and argument options' do
|
23
23
|
ENV['TERRIMPORTER_OPTS'] = '-j -c'
|
24
24
|
merged_options = TerrImporter::Application.build_options([''] + ['-i', '--verbose'])
|
25
|
-
expected_options = {:
|
25
|
+
expected_options = {:application_url => "",
|
26
|
+
:import_css => true,
|
26
27
|
:import_js => true,
|
27
28
|
:import_images => true,
|
28
29
|
:show_help => false,
|
@@ -43,6 +44,7 @@ class TestTerrimporter < Test::Unit::TestCase
|
|
43
44
|
end
|
44
45
|
|
45
46
|
should 'run the importer with the init command and a non existing configuration file' do
|
47
|
+
TerrImporter::Application.run!(["test"], '--init')
|
46
48
|
TerrImporter::Application.run!(["test"], '--init','backup')
|
47
49
|
assert File.exists? config_file
|
48
50
|
end
|
@@ -63,6 +65,11 @@ class TestTerrimporter < Test::Unit::TestCase
|
|
63
65
|
assert return_code == 1
|
64
66
|
end
|
65
67
|
|
68
|
+
should 'run the importer show version and return' do
|
69
|
+
return_code = TerrImporter::Application.run!(["test"], '--version')
|
70
|
+
assert return_code == 0
|
71
|
+
end
|
72
|
+
|
66
73
|
def config_file
|
67
74
|
File.join(File.dirname(__FILE__), '..', config_default_name)
|
68
75
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class TestArrayMonkeypatch < Test::Unit::TestCase
|
2
|
+
|
3
|
+
should 'add an ending to each array object if it is missing' do
|
4
|
+
|
5
|
+
testarray = ["file1.css", "file2", "file3", "file4.css"]
|
6
|
+
expected = ["file1.css", "file2.css", "file3.css", "file4.css"]
|
7
|
+
|
8
|
+
assert_equal expected, testarray.add_if_missing!('.css')
|
9
|
+
assert_equal expected, expected.join(" ").robust_split
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -27,6 +27,12 @@ class ConfigValidatorTest < Test::Unit::TestCase
|
|
27
27
|
assert File.exists?(config_working_directory_path)
|
28
28
|
end
|
29
29
|
|
30
|
+
should 'create a configuration file and replace the application url' do
|
31
|
+
application_url = "http://test.url"
|
32
|
+
create_config_file(nil, application_url)
|
33
|
+
configuration = File.read(config_working_directory_path)
|
34
|
+
assert configuration.include?("application_url: #{application_url}")
|
35
|
+
end
|
30
36
|
|
31
37
|
end
|
32
38
|
|
@@ -9,16 +9,28 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
9
9
|
@configuration.load_configuration
|
10
10
|
end
|
11
11
|
|
12
|
-
def teardown
|
13
|
-
puts "Cleaning up configuration files"
|
14
|
-
end
|
15
|
-
|
16
12
|
should 'find a configuration in the local path and not raise an error' do
|
17
13
|
assert_nothing_raised do
|
18
14
|
@configuration.determine_config_file_path
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
18
|
+
should 'have an image configuration' do
|
19
|
+
assert @configuration.images?
|
20
|
+
end
|
21
|
+
|
22
|
+
should 'have dynamic libraries' do
|
23
|
+
assert @configuration.additional_dynamic_javascripts?
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'have style replacement strings' do
|
27
|
+
assert @configuration.replace_style_strings?
|
28
|
+
end
|
29
|
+
|
30
|
+
should 'have additional stylesheets configured' do
|
31
|
+
assert @configuration.additional_stylesheets?
|
32
|
+
end
|
33
|
+
|
22
34
|
context 'no configuration file around' do
|
23
35
|
setup { @invalid_configuration = TerrImporter::Application::Configuration.new }
|
24
36
|
|
@@ -42,7 +54,7 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
42
54
|
end
|
43
55
|
end
|
44
56
|
|
45
|
-
context 'test config file
|
57
|
+
context 'test config file independent functions' do
|
46
58
|
setup {
|
47
59
|
@configuration = TerrImporter::Application::Configuration.new
|
48
60
|
}
|
@@ -59,4 +71,54 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
59
71
|
assert File.exists?(config_path)
|
60
72
|
end
|
61
73
|
end
|
74
|
+
|
75
|
+
context 'required configurations' do
|
76
|
+
should 'test for all the required configurations needed to function properly' do
|
77
|
+
#these values are set by the downloader
|
78
|
+
@configuration['export_path'] = 'present'
|
79
|
+
@configuration['export_settings'] = {'application' => 'present'}
|
80
|
+
@configuration['application_url'] = 'present'
|
81
|
+
|
82
|
+
assert @configuration.required_present?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'minimal working configuration' do
|
87
|
+
setup do
|
88
|
+
@configuration = TerrImporter::Application::Configuration.new min_test_config_file_path
|
89
|
+
end
|
90
|
+
|
91
|
+
should 'not raise an error when loading the minimal configuration' do
|
92
|
+
assert_nothing_raised do
|
93
|
+
@configuration.load_configuration
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
should 'not have an image configuration' do
|
98
|
+
assert !@configuration.images?
|
99
|
+
end
|
100
|
+
|
101
|
+
should 'not have dynamic libraries' do
|
102
|
+
assert !@configuration.additional_dynamic_javascripts?
|
103
|
+
end
|
104
|
+
|
105
|
+
should 'not have style replacement strings' do
|
106
|
+
assert !@configuration.replace_style_strings?
|
107
|
+
end
|
108
|
+
|
109
|
+
should 'not have additional stylesheets configured' do
|
110
|
+
assert !@configuration.additional_stylesheets?
|
111
|
+
end
|
112
|
+
|
113
|
+
should 'only get the base.css file' do
|
114
|
+
assert_equal ["base.css"], @configuration.stylesheets
|
115
|
+
end
|
116
|
+
|
117
|
+
#todo why is this failing?
|
118
|
+
=begin
|
119
|
+
should 'return javascript destination path if libraries destination path is undefined' do
|
120
|
+
assert_equal @configuration['javascripts']['relative_destination_path'], @configuration.libraries_destination_path
|
121
|
+
end
|
122
|
+
=end
|
123
|
+
end
|
62
124
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class DownloaderTest < Test::Unit::TestCase
|
4
|
-
|
4
|
+
def setup
|
5
5
|
@base_uri = 'http://terrific.url'
|
6
6
|
@downloader = TerrImporter::Application::Downloader.new @base_uri
|
7
|
-
|
8
|
-
|
7
|
+
FakeWeb.register_uri(:get, "http://terrific.url/js/libraries/dynamic/dynlib.js", :body => File.expand_path('test/fixtures/js/dynlib.js'), :content_type => 'text/plain')
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def teardown
|
11
|
+
FileUtils.rm_f @target_dir if not @target_dir.nil? and File.exists? @target_dir
|
12
|
+
end
|
13
13
|
|
14
14
|
should 'join relative and base paths to get fully valid uri' do
|
15
15
|
absolute_path = @downloader.send :absolute_path, 'first/test'
|
@@ -34,5 +34,12 @@ class DownloaderTest < Test::Unit::TestCase
|
|
34
34
|
assert File.exists?(@target_dir), "File doesn't exist #{@target_dir}"
|
35
35
|
end
|
36
36
|
|
37
|
+
should 'raise DefaultError, raised by invalid url socket error' do
|
38
|
+
assert_raises TerrImporter::DefaultError do
|
39
|
+
@downloader = TerrImporter::Application::Downloader.new 'http://url.doesntex.ist'
|
40
|
+
@downloader.download('')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
37
44
|
|
38
45
|
end
|