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/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -18,10 +18,14 @@ terrimporter has the following features:
|
|
18
18
|
|
19
19
|
=== Gem Installation
|
20
20
|
|
21
|
+
You need sudo to install terrimporter if you're not using a ruby version manager like rvm for example.
|
22
|
+
It is strongly encouraged to use such a ruby version management tool in order to install the gem without sudo rights.
|
21
23
|
Download and install terrimporter with the following.
|
22
24
|
|
23
25
|
gem install terrimporter
|
24
26
|
|
27
|
+
|
28
|
+
|
25
29
|
== Usage
|
26
30
|
|
27
31
|
=== Simple Example
|
data/Rakefile
CHANGED
@@ -57,7 +57,7 @@ namespace :version do
|
|
57
57
|
when :major
|
58
58
|
version[:major] = version[:major].to_i + 1
|
59
59
|
when :minor
|
60
|
-
version[:minor] = version[:minor].
|
60
|
+
version[:minor] = version[:minor].to_i + 1
|
61
61
|
when :patch
|
62
62
|
version[:patch] = version[:patch].to_i + 1
|
63
63
|
end
|
@@ -91,8 +91,6 @@ end
|
|
91
91
|
}
|
92
92
|
File.open(version_file_path, 'w') { |f| f.write(version_rb) }
|
93
93
|
end
|
94
|
-
|
95
|
-
|
96
94
|
end
|
97
95
|
|
98
96
|
|
data/config/schema.yml
CHANGED
@@ -1,30 +1,20 @@
|
|
1
1
|
type: map
|
2
2
|
mapping:
|
3
|
-
"
|
4
|
-
type: text
|
5
|
-
required: yes
|
6
|
-
"url":
|
7
|
-
type: str
|
8
|
-
required: yes
|
9
|
-
pattern: /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
|
10
|
-
"app_path":
|
11
|
-
type: str
|
12
|
-
required: yes
|
13
|
-
pattern: /\/.*/
|
14
|
-
"export_path":
|
3
|
+
"application_url":
|
15
4
|
type: str
|
16
5
|
required: yes
|
17
|
-
pattern:
|
18
|
-
"
|
6
|
+
pattern: /^(http|https):\/\/.*$/
|
7
|
+
"libraries_server_path":
|
19
8
|
type: str
|
20
9
|
required: yes
|
21
10
|
pattern: /\/.*/
|
22
|
-
"
|
11
|
+
"image_server_path":
|
23
12
|
type: str
|
24
13
|
required: yes
|
25
14
|
pattern: /\/.*/
|
26
15
|
"export_settings":
|
27
16
|
type: map
|
17
|
+
required: yes
|
28
18
|
mapping:
|
29
19
|
"layout":
|
30
20
|
type: str
|
@@ -37,15 +27,15 @@ mapping:
|
|
37
27
|
default: false
|
38
28
|
"stylesheets":
|
39
29
|
type: map
|
30
|
+
required: yes
|
40
31
|
mapping:
|
41
|
-
"
|
32
|
+
"relative_destination_path":
|
42
33
|
type: str
|
43
34
|
required: yes
|
44
35
|
"styles":
|
45
36
|
type: str
|
46
|
-
name: css
|
47
37
|
required: no
|
48
|
-
"
|
38
|
+
"replace_strings":
|
49
39
|
type: seq
|
50
40
|
required: no
|
51
41
|
sequence:
|
@@ -59,28 +49,29 @@ mapping:
|
|
59
49
|
required: yes
|
60
50
|
"javascripts":
|
61
51
|
type: map
|
52
|
+
required: yes
|
62
53
|
mapping:
|
63
|
-
"
|
54
|
+
"relative_destination_path":
|
64
55
|
type: str
|
65
56
|
required: yes
|
66
57
|
"dynamic_libraries":
|
67
58
|
type: str
|
68
|
-
name: js
|
69
59
|
required: no
|
70
|
-
"
|
60
|
+
"libraries_relative_destination_path":
|
71
61
|
type: str
|
72
|
-
required:
|
62
|
+
required: no
|
73
63
|
"images":
|
74
64
|
type: seq
|
65
|
+
required: no
|
75
66
|
sequence:
|
76
67
|
- type: map
|
77
68
|
mapping:
|
78
|
-
"
|
69
|
+
"server_path":
|
79
70
|
type: str
|
80
71
|
required: yes
|
81
|
-
"
|
72
|
+
"relative_destination_path":
|
82
73
|
type: str
|
83
74
|
required: yes
|
84
|
-
"
|
75
|
+
"file_types":
|
85
76
|
type: str
|
86
77
|
required: no
|
@@ -1,66 +1,47 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
#
|
20
|
-
|
21
|
-
#
|
22
|
-
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
|
28
|
-
#
|
29
|
-
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
dest: public/stylesheets/
|
49
|
-
styles: ie
|
50
|
-
replace:
|
51
|
-
- what: /img/
|
52
|
-
with: /images/
|
53
|
-
javascripts:
|
54
|
-
dest: public/javascripts/
|
55
|
-
dynamic_libraries: dynlib
|
56
|
-
libraries_dest: /
|
57
|
-
images:
|
58
|
-
- src: /
|
59
|
-
dest: public/images/
|
60
|
-
types: jpg png gif
|
61
|
-
- src: /
|
62
|
-
dest: public/
|
63
|
-
types: ico
|
64
|
-
- src: /backgrounds/
|
65
|
-
dest: public/images/backgrounds/
|
66
|
-
types: jpg
|
1
|
+
#-------------------------------------------------------------------------------
|
2
|
+
# terrimporter configuration, adjust as needed. Don't mess with indentation!
|
3
|
+
#-------------------------------------------------------------------------------
|
4
|
+
# url: Terrific base url
|
5
|
+
application_url: http://terrific.project.url
|
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
|
data/lib/terrimporter.rb
CHANGED
@@ -4,9 +4,10 @@ require 'terrimporter/app_logger'
|
|
4
4
|
require 'terrimporter/options'
|
5
5
|
require 'terrimporter/importer'
|
6
6
|
require 'terrimporter/config_helper'
|
7
|
-
require 'terrimporter/config_validator'
|
8
7
|
require 'terrimporter/configuration'
|
9
8
|
require 'terrimporter/downloader'
|
9
|
+
require 'terrimporter/string_monkeypatch'
|
10
|
+
require 'terrimporter/array_monkeypatch'
|
10
11
|
require 'etc'
|
11
12
|
require 'kwalify'
|
12
13
|
require 'fileutils'
|
@@ -23,11 +24,11 @@ module TerrImporter
|
|
23
24
|
options = build_options(arguments)
|
24
25
|
|
25
26
|
begin
|
26
|
-
|
27
|
+
if !options[:init].nil?
|
27
28
|
if config_working_directory_exists? and options[:init] != :backup and options[:init] != :replace
|
28
29
|
raise TerrImporter::ConfigurationError, "Configuration already exists, use the override or backup option"
|
29
30
|
end
|
30
|
-
create_config_file
|
31
|
+
create_config_file(options[:init], options[:application_url])
|
31
32
|
return 0
|
32
33
|
end
|
33
34
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module ConfigHelper
|
3
2
|
|
4
3
|
def config_default_name
|
@@ -25,7 +24,7 @@ module ConfigHelper
|
|
25
24
|
File.join(base_config_path, schema_default_name)
|
26
25
|
end
|
27
26
|
|
28
|
-
def create_config_file(backup_or_replace = nil)
|
27
|
+
def create_config_file(backup_or_replace = nil, application_url = nil)
|
29
28
|
puts "Creating configuration file..."
|
30
29
|
case backup_or_replace
|
31
30
|
when :backup
|
@@ -36,6 +35,13 @@ module ConfigHelper
|
|
36
35
|
FileUtils.rm_f(config_working_directory_path) if File.exists? config_working_directory_path
|
37
36
|
end
|
38
37
|
FileUtils.cp(config_example_path, config_working_directory_path)
|
38
|
+
|
39
|
+
unless application_url.nil?
|
40
|
+
configuration = File.read(config_working_directory_path)
|
41
|
+
configuration.gsub!(/application_url:.*$/, "application_url: #{application_url}")
|
42
|
+
File.open(config_working_directory_path, 'w') { |f| f.write(configuration) }
|
43
|
+
end
|
44
|
+
|
39
45
|
puts "done! You should take a look an edit it to your needs..."
|
40
46
|
end
|
41
47
|
|
@@ -61,7 +61,54 @@ module TerrImporter
|
|
61
61
|
def load_validator
|
62
62
|
puts "Loading validator from #{schema_file_path}"
|
63
63
|
schema = Kwalify::Yaml.load_file(schema_file_path)
|
64
|
-
|
64
|
+
Kwalify::Validator.new(schema)
|
65
|
+
end
|
66
|
+
|
67
|
+
def required_present?
|
68
|
+
if self['export_path'].nil? or self['export_settings']['application'].nil? or self['application_url'].nil?
|
69
|
+
false
|
70
|
+
else
|
71
|
+
true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def stylesheets
|
76
|
+
stylesheets = ["base.css"]
|
77
|
+
if additional_stylesheets?
|
78
|
+
stylesheets = stylesheets + self['stylesheets']['styles'].to_s.robust_split
|
79
|
+
else
|
80
|
+
puts "No additional stylesheets defined."
|
81
|
+
end
|
82
|
+
stylesheets.add_if_missing!('.css')
|
83
|
+
end
|
84
|
+
|
85
|
+
def dynamic_libraries
|
86
|
+
libraries = self['javascripts']['dynamic_libraries'].robust_split
|
87
|
+
libraries.add_if_missing!('.js')
|
88
|
+
end
|
89
|
+
|
90
|
+
def replace_style_strings?
|
91
|
+
!self['stylesheets'].nil? and !self['stylesheets']['replace_strings'].nil?
|
92
|
+
end
|
93
|
+
|
94
|
+
def libraries_destination_path
|
95
|
+
if !self['javascripts']['libraries_relative_destination_path'].nil?
|
96
|
+
File.join(self['javascripts']['libraries_relative_destination_path'])
|
97
|
+
else
|
98
|
+
File.join(self['javascripts']['relative_destination_path'])
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def additional_stylesheets?
|
103
|
+
!self['stylesheets'].nil? and !self['stylesheets']['styles'].nil?
|
104
|
+
end
|
105
|
+
|
106
|
+
def additional_dynamic_javascripts?
|
107
|
+
!self['javascripts'].nil? and !self['javascripts']['dynamic_libraries'].nil?
|
108
|
+
end
|
109
|
+
|
110
|
+
def images?
|
111
|
+
!self['images'].nil?
|
65
112
|
end
|
66
113
|
|
67
114
|
end
|
@@ -12,19 +12,23 @@ module TerrImporter
|
|
12
12
|
|
13
13
|
def download(remote_path, local_path=nil)
|
14
14
|
absolute_uri = absolute_path(remote_path)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
begin
|
16
|
+
if local_path.nil? #download to buffer
|
17
|
+
data = StringIO.new
|
18
|
+
|
19
|
+
puts "Downloading #{absolute_uri} to buffer"
|
20
|
+
|
21
|
+
absolute_uri.open { |io| data = io.read }
|
22
|
+
data.to_s
|
23
|
+
else
|
24
|
+
puts "Downloading #{absolute_uri} to local path #{local_path}"
|
25
|
+
|
26
|
+
open(local_path, "wb") { |file|
|
27
|
+
file.write(absolute_uri.open.read)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
rescue SocketError => e
|
31
|
+
raise DefaultError, "Error opening url #{absolute_uri}: \n #{e.message}"
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module TerrImporter
|
4
2
|
|
5
3
|
class DefaultError < StandardError
|
@@ -21,10 +19,12 @@ module TerrImporter
|
|
21
19
|
self.options = options
|
22
20
|
self.config = Configuration.new options[:config_file]
|
23
21
|
self.config.load_configuration
|
24
|
-
@downloader = Downloader.new config['
|
22
|
+
@downloader = Downloader.new config['application_url']
|
25
23
|
end
|
26
24
|
|
27
25
|
def run
|
26
|
+
|
27
|
+
|
28
28
|
if options[:all] != nil and options[:all] == true
|
29
29
|
puts "Import of everything started"
|
30
30
|
import_js
|
@@ -40,65 +40,116 @@ module TerrImporter
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
def determine_configuration_values_from_uri
|
44
|
+
result = @downloader.download('')
|
45
|
+
#result =~ /\/terrific\/base\/(.*?)\/public\/.*application=(.*?)(&|&)/
|
46
|
+
#result =~ /(\/terrific\/base\/(.*?)\/public\/.*base.(css|js).php).*application=(.*?)(&|&)/
|
47
|
+
|
48
|
+
css_result, js_result = result.scan(/(\/terrific\/base\/(.*?)\/public\/.*base.(css|js).php)\?.*application=(.*?)(&|&)/)
|
49
|
+
|
50
|
+
|
51
|
+
if css_result.nil? or css_result.size < 5
|
52
|
+
raise ConfigurationError, "Unable to extract css information from application url, content is: #{result}"
|
53
|
+
end
|
54
|
+
if js_result.nil? or js_result.size < 5
|
55
|
+
raise ConfigurationError, "Unable to extract javascript information from application url, content is: #{result}"
|
56
|
+
end
|
57
|
+
|
58
|
+
css_export_path = css_result[0]
|
59
|
+
js_export_path = js_result[0]
|
60
|
+
terrific_version = css_result[1]
|
61
|
+
application = css_result[3]
|
62
|
+
|
63
|
+
raise ConfigurationError, "Unable to determine css export path from application url" if css_export_path.nil?
|
64
|
+
raise ConfigurationError, "Unable to determine js export path from application url" if js_export_path.nil?
|
65
|
+
|
66
|
+
puts "Determined the following configuration values from #{config['application_url']}:\n" +
|
67
|
+
"terrific version: #{terrific_version} \n" +
|
68
|
+
"application path: #{application}"
|
69
|
+
|
70
|
+
config['version'] = terrific_version
|
71
|
+
config['export_settings']['application'] = application
|
72
|
+
config['export_path'] = {'css' => css_export_path, 'js' => js_export_path}
|
73
|
+
end
|
74
|
+
|
43
75
|
def import_css
|
76
|
+
check_and_complete_config!
|
44
77
|
unclean_suffix = "_unclean"
|
45
78
|
|
46
|
-
check_and_create_dir config['stylesheets']['
|
79
|
+
check_and_create_dir config['stylesheets']['relative_destination_path']
|
47
80
|
|
48
|
-
|
49
|
-
styles = config['stylesheets']['styles'].split(" ")
|
50
|
-
styles << "base"
|
81
|
+
styles = config.stylesheets
|
51
82
|
|
52
83
|
styles.each do |css|
|
53
|
-
|
84
|
+
relative_destination_path = File.join(config['stylesheets']['relative_destination_path'], css)
|
54
85
|
options = {}
|
55
|
-
options[:suffix] =
|
86
|
+
options[:suffix] = $1 if css =~ /(ie.*).css$/ #add ie option if in array
|
56
87
|
|
57
88
|
source_url = construct_export_path(:css, options)
|
58
89
|
|
59
|
-
@downloader.download(source_url,
|
90
|
+
@downloader.download(source_url, relative_destination_path + unclean_suffix)
|
60
91
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
92
|
+
if config.replace_style_strings?
|
93
|
+
puts "Start css line replacements..."
|
94
|
+
File.open(relative_destination_path, 'w') do |d|
|
95
|
+
File.open(relative_destination_path + unclean_suffix, 'r') do |s|
|
96
|
+
lines = s.readlines
|
97
|
+
lines.each do |line|
|
98
|
+
d.print stylesheet_replace_strings!(line)
|
99
|
+
end
|
68
100
|
end
|
69
101
|
end
|
102
|
+
else
|
103
|
+
puts "No css line replacements defined; skipping..."
|
70
104
|
end
|
71
105
|
puts "Deleting unclean css files"
|
72
|
-
FileUtils.remove
|
106
|
+
FileUtils.remove relative_destination_path + unclean_suffix
|
73
107
|
end
|
74
108
|
end
|
75
109
|
|
76
110
|
def import_js
|
77
|
-
|
78
|
-
|
111
|
+
check_and_complete_config!
|
112
|
+
check_and_create_dir config['javascripts']['relative_destination_path']
|
113
|
+
relative_destination_path = File.join(config['javascripts']['relative_destination_path'], "base.js")
|
79
114
|
js_source_url = construct_export_path :js
|
80
115
|
|
81
|
-
puts "Importing base.js from #{js_source_url} to #{
|
116
|
+
puts "Importing base.js from #{js_source_url} to #{relative_destination_path}"
|
117
|
+
|
118
|
+
@downloader.download(js_source_url, relative_destination_path)
|
119
|
+
|
82
120
|
|
83
|
-
|
121
|
+
if config.additional_dynamic_javascripts?
|
84
122
|
|
123
|
+
libraries_destination_path = config.libraries_destination_path
|
124
|
+
check_and_create_dir libraries_destination_path
|
125
|
+
js_libraries = config.dynamic_libraries
|
85
126
|
|
86
|
-
|
87
|
-
check_and_create_dir libraries_destination_path
|
88
|
-
js_libraries = config['javascripts']['dynamic_libraries'].split(" ")
|
127
|
+
puts "Importing libraries from #{config['libraries_server_path']} to #{libraries_destination_path}"
|
89
128
|
|
90
|
-
|
129
|
+
if config['libraries_server_path'].nil?
|
130
|
+
puts "Please define 'libraries_server_path' in configuration file"
|
131
|
+
else
|
132
|
+
js_libraries.each do |lib|
|
133
|
+
@downloader.download(File.join(config['libraries_server_path'], lib), File.join(libraries_destination_path, lib))
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
91
137
|
|
92
|
-
js_libraries.each do |lib|
|
93
|
-
@downloader.download(File.join(config['libraries_source_path'], lib+ ".js"), File.join(libraries_destination_path, lib + ".js"))
|
94
138
|
end
|
95
139
|
end
|
96
140
|
|
97
141
|
def import_images
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
142
|
+
check_and_complete_config!
|
143
|
+
if config.images?
|
144
|
+
puts "Start importing images..."
|
145
|
+
|
146
|
+
config['images'].each do |image|
|
147
|
+
check_and_create_dir image['relative_destination_path']
|
148
|
+
image_source_path = File.join(config['image_server_path'], image['server_path'])
|
149
|
+
batch_download(image_source_path, image['relative_destination_path'], image['file_types'])
|
150
|
+
end
|
151
|
+
else
|
152
|
+
puts "No image configuration found, skipping image import..."
|
102
153
|
end
|
103
154
|
end
|
104
155
|
|
@@ -107,19 +158,19 @@ module TerrImporter
|
|
107
158
|
def batch_download(relative_source_path, relative_dest_path, type_filter = "")
|
108
159
|
source_path = relative_source_path
|
109
160
|
|
110
|
-
puts "Downloading multiple files from #{config['
|
161
|
+
puts "Downloading multiple files from #{config['application_url']}#{source_path} to #{relative_dest_path} #{"allowed extensions: " + type_filter unless type_filter.empty?}"
|
111
162
|
|
112
163
|
files = html_directory_content_list(source_path)
|
113
164
|
|
114
165
|
unless type_filter.empty?
|
115
166
|
puts "Appling type filter: #{type_filter}"
|
116
|
-
files = files.find_all { |file| file =~ Regexp.new(".*" + type_filter.
|
167
|
+
files = files.find_all { |file| file =~ Regexp.new(".*" + type_filter.robust_split.join("|") + "$") }
|
117
168
|
end
|
118
169
|
|
119
170
|
puts "Downloading #{files.size} files..."
|
120
171
|
files.each do |file|
|
121
|
-
|
122
|
-
@downloader.download(File.join(source_path,file),
|
172
|
+
relative_destination_path = File.join(relative_dest_path, file)
|
173
|
+
@downloader.download(File.join(source_path, file), relative_destination_path)
|
123
174
|
end
|
124
175
|
end
|
125
176
|
|
@@ -139,15 +190,10 @@ module TerrImporter
|
|
139
190
|
raise DefaultError, "Specify js or css url" unless for_what == :js or for_what == :css
|
140
191
|
export_settings = config['export_settings'].clone
|
141
192
|
|
142
|
-
export_settings['application'] = config['app_path']
|
143
193
|
export_settings.merge!(options)
|
144
194
|
export_settings['appbaseurl'] = "" if for_what == :css
|
145
195
|
|
146
|
-
|
147
|
-
export_path = config['export_path']
|
148
|
-
export_path.insert(0, "/") unless export_path.match(/^\//)
|
149
|
-
|
150
|
-
export_path = export_path % [for_what.to_s, config['version']] #replace placeholders
|
196
|
+
export_path = config['export_path'][for_what.to_s].clone
|
151
197
|
export_path << '?' << export_settings.map { |k, v| "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}" }.join("&")
|
152
198
|
export_path
|
153
199
|
end
|
@@ -166,8 +212,9 @@ module TerrImporter
|
|
166
212
|
created_or_exists
|
167
213
|
end
|
168
214
|
|
215
|
+
#todo refactor config access away
|
169
216
|
def stylesheet_replace_strings!(line)
|
170
|
-
config['stylesheets']['
|
217
|
+
config['stylesheets']['replace_strings'].each do |replace|
|
171
218
|
what = replace['what']
|
172
219
|
with = replace['with']
|
173
220
|
what = Regexp.new "#{$1}" if what.match(/^r\/(.*)\//)
|
@@ -178,6 +225,12 @@ module TerrImporter
|
|
178
225
|
end
|
179
226
|
line
|
180
227
|
end
|
228
|
+
|
229
|
+
def check_and_complete_config!
|
230
|
+
unless config.required_present?
|
231
|
+
determine_configuration_values_from_uri
|
232
|
+
end
|
233
|
+
end
|
181
234
|
end
|
182
235
|
end
|
183
236
|
end
|