terrimporter 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile.lock +3 -1
- data/Rakefile +27 -0
- data/config/schema.yml +89 -0
- data/config/terrimporter.config.yml +5 -5
- data/lib/config_validator.rb +21 -0
- data/lib/configuration.rb +93 -0
- data/lib/importer.rb +6 -36
- data/lib/options.rb +4 -1
- data/lib/terrimporter.rb +0 -7
- data/lib/terrimporter/version.rb +1 -1
- data/public/javascripts/base.js +0 -0
- data/public/javascripts/pngfix.js +0 -0
- data/public/javascripts/warning.js +0 -0
- data/terrimporter.gemspec +3 -1
- data/test/unit/test_configuration.rb +58 -0
- data/test/unit/test_importer.rb +2 -78
- data/test/unit/test_options.rb +10 -23
- data/test/unit/test_terrimporter.rb +1 -5
- metadata +34 -24
- data/coverage/index.html +0 -186
- data/coverage/jquery-1.3.2.min.js +0 -19
- data/coverage/jquery.tablesorter.min.js +0 -15
- data/coverage/lib-app_logger_rb.html +0 -321
- data/coverage/lib-config_validator_rb.html +0 -189
- data/coverage/lib-configuration_rb.html +0 -633
- data/coverage/lib-importer_rb.html +0 -1203
- data/coverage/lib-options_rb.html +0 -483
- data/coverage/lib-terrimporter_rb.html +0 -435
- data/coverage/print.css +0 -12
- data/coverage/rcov.js +0 -42
- data/coverage/screen.css +0 -270
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
terrimporter (0.
|
4
|
+
terrimporter (0.4.0)
|
5
|
+
kwalify
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: http://rubygems.org/
|
@@ -11,6 +12,7 @@ GEM
|
|
11
12
|
bundler (~> 1.0)
|
12
13
|
git (>= 1.2.5)
|
13
14
|
rake
|
15
|
+
kwalify (0.7.2)
|
14
16
|
rake (0.9.2)
|
15
17
|
rcov (0.9.9)
|
16
18
|
shoulda (2.11.3)
|
data/Rakefile
CHANGED
@@ -1,2 +1,29 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
Rake::TestTask.new(:test) do |test|
|
6
|
+
test.libs << 'lib' << 'test'
|
7
|
+
test.pattern = 'test/**/test_*.rb'
|
8
|
+
test.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rcov/rcovtask'
|
12
|
+
Rcov::RcovTask.new do |test|
|
13
|
+
test.libs << 'test'
|
14
|
+
test.pattern = 'test/**/test_*.rb'
|
15
|
+
test.verbose = true
|
16
|
+
test.rcov_opts << '--exclude "gems/*"'
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => :test
|
20
|
+
|
21
|
+
require 'rake/rdoctask'
|
22
|
+
Rake::RDocTask.new do |rdoc|
|
23
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
24
|
+
|
25
|
+
rdoc.rdoc_dir = 'rdoc'
|
26
|
+
rdoc.title = "terrimporter #{version}"
|
27
|
+
rdoc.rdoc_files.include('README*')
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
end
|
data/config/schema.yml
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
type: map
|
2
|
+
mapping:
|
3
|
+
"version":
|
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":
|
15
|
+
type: str
|
16
|
+
required: yes
|
17
|
+
pattern: /^\/terrific.*\%2\$s.*\%1\$s.*\%1\$s.*\.php$/
|
18
|
+
"libraries_source_path":
|
19
|
+
type: str
|
20
|
+
required: yes
|
21
|
+
pattern: /\/.*/
|
22
|
+
"image_base_path":
|
23
|
+
type: str
|
24
|
+
required: yes
|
25
|
+
pattern: /\/.*/
|
26
|
+
"downloader":
|
27
|
+
type: str
|
28
|
+
enum: [curl, wget]
|
29
|
+
"export_settings":
|
30
|
+
type: map
|
31
|
+
mapping:
|
32
|
+
"layout":
|
33
|
+
type: str
|
34
|
+
required: yes
|
35
|
+
"debug":
|
36
|
+
type: bool
|
37
|
+
default: false
|
38
|
+
"cache":
|
39
|
+
type: bool
|
40
|
+
default: false
|
41
|
+
"stylesheets":
|
42
|
+
type: map
|
43
|
+
mapping:
|
44
|
+
"dest":
|
45
|
+
type: str
|
46
|
+
required: yes
|
47
|
+
"styles":
|
48
|
+
type: str
|
49
|
+
name: css
|
50
|
+
required: no
|
51
|
+
"replace":
|
52
|
+
type: seq
|
53
|
+
required: no
|
54
|
+
sequence:
|
55
|
+
- type: map
|
56
|
+
mapping:
|
57
|
+
"what":
|
58
|
+
type: str
|
59
|
+
required: yes
|
60
|
+
"with":
|
61
|
+
type: str
|
62
|
+
required: yes
|
63
|
+
"javascripts":
|
64
|
+
type: map
|
65
|
+
mapping:
|
66
|
+
"dest":
|
67
|
+
type: str
|
68
|
+
required: yes
|
69
|
+
"dynamic_libraries":
|
70
|
+
type: str
|
71
|
+
name: js
|
72
|
+
required: no
|
73
|
+
"libraries_dest":
|
74
|
+
type: str
|
75
|
+
required: yes
|
76
|
+
"images":
|
77
|
+
type: seq
|
78
|
+
sequence:
|
79
|
+
- type: map
|
80
|
+
mapping:
|
81
|
+
"src":
|
82
|
+
type: str
|
83
|
+
required: yes
|
84
|
+
"dest":
|
85
|
+
type: str
|
86
|
+
required: yes
|
87
|
+
"types":
|
88
|
+
type: str
|
89
|
+
required: no
|
@@ -35,24 +35,24 @@
|
|
35
35
|
# dest: The destination directory, relative from the current running directory
|
36
36
|
# types: The image endings to be downloaded, specified as a space separated string
|
37
37
|
########################################################################################################################
|
38
|
-
terrific:
|
39
38
|
version: 0.5
|
40
|
-
url: http://terrific.
|
39
|
+
url: http://terrific.url
|
41
40
|
app_path: /Users/danielkummer/_NAMICS/projekte/mobilezone/mobilezone-abo_optimizer/public/terrific
|
42
41
|
export_path: /terrific/base/%2$s/public/%1$s/base/base.%1$s.php
|
43
42
|
libraries_source_path: /js/libraries/dynamic/
|
43
|
+
#todo remove backslash
|
44
44
|
image_base_path: /img
|
45
45
|
downloader: curl
|
46
46
|
export_settings:
|
47
47
|
layout: project
|
48
48
|
debug: false
|
49
|
-
|
49
|
+
cache: false
|
50
50
|
stylesheets:
|
51
51
|
dest: public/stylesheets/
|
52
52
|
styles: ie
|
53
53
|
replace:
|
54
|
-
|
55
|
-
|
54
|
+
- what: /img/
|
55
|
+
with: /images/
|
56
56
|
javascripts:
|
57
57
|
dest: public/javascripts/
|
58
58
|
dynamic_libraries: warning pngfix
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'kwalify'
|
2
|
+
|
3
|
+
class ConfigValidator < Kwalify::Validator
|
4
|
+
## hook method called by Validator#validate()
|
5
|
+
def validate_hook(value, rule, path, errors)
|
6
|
+
case rule.name
|
7
|
+
when 'css'
|
8
|
+
#todo split space separated values and check for .css
|
9
|
+
if value =~ /\.css/
|
10
|
+
msg = "no .css extension allowed, use filename only."
|
11
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
12
|
+
end
|
13
|
+
when 'js'
|
14
|
+
if value =~ /\.js/
|
15
|
+
msg = "no .js extension allowed, use filename only."
|
16
|
+
errors << Kwalify::ValidationError.new(msg, path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'etc'
|
2
|
+
require 'kwalify'
|
3
|
+
require 'config_validator'
|
4
|
+
|
5
|
+
module TerrImporter
|
6
|
+
class Application
|
7
|
+
class Configuration < Hash
|
8
|
+
|
9
|
+
CONFIG_DEFAULT_NAME = 'terrimporter.config.yml'
|
10
|
+
SCHEMA_DEFAULT_NAME = 'schema.yml'
|
11
|
+
|
12
|
+
attr_accessor :validations, :config_file
|
13
|
+
|
14
|
+
def initialize(config_file = nil)
|
15
|
+
self.config_file = config_file unless config_file.nil?
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_configuration
|
20
|
+
config_file_path = determine_config_file_path
|
21
|
+
validate_and_load_config(config_file_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def determine_config_file_path
|
25
|
+
unless self.config_file.nil?
|
26
|
+
return self.config_file
|
27
|
+
end
|
28
|
+
|
29
|
+
valid_config_paths.each do |path|
|
30
|
+
file_path = File.join path, CONFIG_DEFAULT_NAME
|
31
|
+
return file_path if File.exists?(file_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
raise ConfigurationError, %Q{config file #{CONFIG_DEFAULT_NAME} not found in search paths. Search paths are:
|
35
|
+
#{valid_config_paths.join "\n"} \n If this is a new project, run with the option --init}
|
36
|
+
end
|
37
|
+
|
38
|
+
def valid_config_paths
|
39
|
+
[
|
40
|
+
Dir.pwd,
|
41
|
+
File.join(Dir.pwd, 'config'),
|
42
|
+
File.join(Dir.pwd, '.config'),
|
43
|
+
Etc.getpwuid.dir
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
#todo split!
|
48
|
+
def validate_and_load_config(file)
|
49
|
+
puts "Load configuration "
|
50
|
+
|
51
|
+
schema = Kwalify::Yaml.load_file(schema_file_path)
|
52
|
+
#validator = Kwalify::Validator.new(schema)
|
53
|
+
validator = ConfigValidator.new(schema)
|
54
|
+
|
55
|
+
parser = Kwalify::Yaml::Parser.new(validator)
|
56
|
+
document = parser.parse_file(file)
|
57
|
+
## show errors if exist
|
58
|
+
errors = parser.errors()
|
59
|
+
##todo convert to single statement, map for example
|
60
|
+
if errors && !errors.empty?
|
61
|
+
error_message = ""
|
62
|
+
for e in errors
|
63
|
+
error_message << "#{e.linenum}:#{e.column} [#{e.path}] #{e.message}\n"
|
64
|
+
end
|
65
|
+
raise ConfigurationError, error_message
|
66
|
+
end
|
67
|
+
|
68
|
+
self.merge! document
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
def schema_file_path
|
73
|
+
File.join(File.dirname(__FILE__), '..', 'config', SCHEMA_DEFAULT_NAME)
|
74
|
+
end
|
75
|
+
|
76
|
+
#todo
|
77
|
+
def validate_schema
|
78
|
+
meta_validator = Kwalify::MetaValidator.instance
|
79
|
+
|
80
|
+
## validate schema definition
|
81
|
+
parser = Kwalify::Yaml::Parser.new(meta_validator)
|
82
|
+
errors = parser.parse_file(schema_file_path)
|
83
|
+
for e in errors
|
84
|
+
puts "#{e.linenum}:#{e.column} [#{e.path}] #{e.message}"
|
85
|
+
end if errors && !errors.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_config
|
89
|
+
FileUtils.cp(File.join(File.dirname(__FILE__), "..", "config", CONFIG_DEFAULT_NAME), File.join(Dir.pwd, CONFIG_DEFAULT_NAME))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/importer.rb
CHANGED
@@ -4,9 +4,8 @@ require 'yaml'
|
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
|
7
|
-
module TerrImporter
|
8
7
|
|
9
|
-
|
8
|
+
module TerrImporter
|
10
9
|
|
11
10
|
class DefaultError < StandardError
|
12
11
|
end
|
@@ -16,16 +15,20 @@ module TerrImporter
|
|
16
15
|
|
17
16
|
class Importer
|
18
17
|
require 'options'
|
18
|
+
require 'configuration'
|
19
19
|
include Logging
|
20
20
|
|
21
|
+
#todo remove
|
21
22
|
attr_accessor :options, :config
|
22
23
|
|
23
24
|
def initialize(options = {})
|
24
25
|
self.options = options
|
26
|
+
self.config = TerrImporter::Application::Configuration.new options[:config_file]
|
27
|
+
|
25
28
|
end
|
26
29
|
|
27
30
|
def run
|
28
|
-
|
31
|
+
self.config.load_configuration
|
29
32
|
|
30
33
|
if options[:all] != nil and options[:all] == true
|
31
34
|
import_js
|
@@ -106,39 +109,6 @@ module TerrImporter
|
|
106
109
|
end
|
107
110
|
|
108
111
|
private
|
109
|
-
def init_config (config_file)
|
110
|
-
raise ConfigurationError, "config file #{config_file} doesn't exist, if this is a new project, run with the option -i'" unless File.exists?(config_file)
|
111
|
-
load_config(config_file)
|
112
|
-
validate_config(self.config)
|
113
|
-
end
|
114
|
-
|
115
|
-
def config_file_path(config_directory = nil)
|
116
|
-
config_directory = Dir.pwd if config_directory.nil?
|
117
|
-
File.join(config_directory, CONFIG_DEFAULT_NAME)
|
118
|
-
end
|
119
|
-
|
120
|
-
|
121
|
-
def validate_config(config)
|
122
|
-
raise ConfigurationError, "specify downloader (curl or wget)" unless config['downloader'] =~ /curl|wget/
|
123
|
-
raise ConfigurationError, "url format invalid" unless config['url'] =~ URI::regexp
|
124
|
-
raise ConfigurationError, "version invalid" if config['version'].to_s.empty?
|
125
|
-
raise ConfigurationError, "app path invalid" if config['app_path'].to_s.empty?
|
126
|
-
raise ConfigurationError, "export path invalid" if config['export_path'].to_s.empty?
|
127
|
-
raise ConfigurationError, "image base path invalid" if config['image_base_path'].to_s.empty?
|
128
|
-
config['stylesheets']['styles'].each do |css|
|
129
|
-
raise ConfigurationError, ".css extension not allowed on style definition: #{css}" if css =~ /\.css$/
|
130
|
-
end
|
131
|
-
config['javascripts']['dynamic_libraries'].each do |js|
|
132
|
-
raise ConfigurationError, ".js extension not allowed on javascript dynamic library definition: #{js}" if js =~ /\.js$/
|
133
|
-
end
|
134
|
-
raise ConfigurationError, "dynamic javascript libraries path invalid" if config['javascripts']['libraries_dest'].to_s.empty?
|
135
|
-
end
|
136
|
-
|
137
|
-
def load_config(file)
|
138
|
-
puts "Load configuration "
|
139
|
-
self.config = YAML.load_file(file)['terrific']
|
140
|
-
end
|
141
|
-
|
142
112
|
|
143
113
|
def batch_download_files(relative_source_path, relative_dest_path, type_filter = "")
|
144
114
|
source_path = relative_source_path
|
data/lib/options.rb
CHANGED
@@ -28,6 +28,9 @@ module TerrImporter
|
|
28
28
|
o.on('-j', '--js', 'export configured javascript files') { self[:import_js] = true }
|
29
29
|
o.on('--init', 'create configuration file in current working directory') { self[:init] = true }
|
30
30
|
#todo add force option to init
|
31
|
+
o.on('-f', '--config CONFIG_FILE', 'use alternative configuration file') do |config_file|
|
32
|
+
self[:config_file] = config_file
|
33
|
+
end
|
31
34
|
|
32
35
|
o.separator ''
|
33
36
|
o.separator 'Additional configuration:'
|
@@ -59,7 +62,7 @@ module TerrImporter
|
|
59
62
|
end
|
60
63
|
|
61
64
|
def show_help_on_no_options
|
62
|
-
self[:show_help] = true unless self[:import_css] or self[:import_js] or self[:import_images] or self[:init]
|
65
|
+
self[:show_help] = true unless self[:import_css] or self[:import_js] or self[:import_images] or self[:init] or self[:version]
|
63
66
|
end
|
64
67
|
|
65
68
|
end
|
data/lib/terrimporter.rb
CHANGED
@@ -10,7 +10,6 @@ module TerrImporter
|
|
10
10
|
def run!(*arguments)
|
11
11
|
options = build_options(arguments)
|
12
12
|
|
13
|
-
|
14
13
|
if options[:init]
|
15
14
|
#todo the config path can be differen in importer, extract to special class for loading and managing
|
16
15
|
#todo raise error instead of puts and exit
|
@@ -50,12 +49,6 @@ module TerrImporter
|
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
|
-
#todo check force option, only override if not existing, else raise and exit
|
54
|
-
def create_config
|
55
|
-
FileUtils.cp(File.join(File.dirname(__FILE__), "..", "config", CONFIG_DEFAULT_NAME), File.join(Dir.pwd, CONFIG_DEFAULT_NAME))
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
52
|
def build_options(arguments)
|
60
53
|
env_opts_string = ENV['TERRIMPORTER_OPTS'] || ""
|
61
54
|
env_opts = TerrImporter::Application::Options.new(shellwords(env_opts_string))
|
data/lib/terrimporter/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/terrimporter.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["daniel.kummer@gmail.com"]
|
11
11
|
s.homepage = ""
|
12
12
|
s.summary = %q{Import terrific javascripts, css files and images into a web project}
|
13
|
-
s.description = %q{This gem allows terrific(http://terrifically.org/) project import of css, javascript and image files based on a command line tool and a configuration file.}
|
13
|
+
s.description = %q{This gem allows terrific(http://terrifically.org/ ) project import of css, javascript and image files based on a command line tool and a configuration file.}
|
14
14
|
|
15
15
|
s.rubyforge_project = "terrimporter"
|
16
16
|
|
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
+
s.add_dependency "kwalify"
|
23
|
+
|
22
24
|
s.add_development_dependency "shoulda", [">= 0"]
|
23
25
|
s.add_development_dependency "bundler", ["~> 1.0.0"]
|
24
26
|
s.add_development_dependency "jeweler", ["~> 1.6.4"]
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "kwalify"
|
3
|
+
|
4
|
+
class ConfigurationTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
create_test_configuration_file
|
8
|
+
@configuration = TerrImporter::Application::Configuration.new @test_configuration_file
|
9
|
+
@configuration.load_configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
puts "Cleaning up configuration files"
|
14
|
+
delete_test_configuration_file
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'find a configuration in the local path and not raise an error' do
|
18
|
+
assert_nothing_raised do
|
19
|
+
@configuration.determine_config_file_path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'test config file independed functions' do
|
24
|
+
setup {
|
25
|
+
@configuration = TerrImporter::Application::Configuration.new
|
26
|
+
}
|
27
|
+
|
28
|
+
should 'get the current working directory as config file path' do
|
29
|
+
config_in_cwd = File.join(Dir.pwd, TerrImporter::Application::Configuration::CONFIG_DEFAULT_NAME)
|
30
|
+
assert_equal config_in_cwd, @configuration.determine_config_file_path
|
31
|
+
end
|
32
|
+
|
33
|
+
should 'create a config file in the current directory' do
|
34
|
+
config_path = File.join(Dir.pwd, TerrImporter::Application::Configuration::CONFIG_DEFAULT_NAME)
|
35
|
+
FileUtils.rm_f config_path if File.exists? config_path
|
36
|
+
@configuration.create_config
|
37
|
+
assert File.exists?(config_path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def schema_file_path
|
42
|
+
File.join(File.dirname(__FILE__), '..', '..', 'config', TerrImporter::Application::Configuration::SCHEMA_DEFAULT_NAME)
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_test_configuration_file
|
46
|
+
example_configuration_path = File.join(File.dirname(__FILE__), '..', '..', 'config', TerrImporter::Application::Configuration::CONFIG_DEFAULT_NAME)
|
47
|
+
tmp_dir_path = File.join(File.dirname(__FILE__), '..', 'tmp')
|
48
|
+
test_configuration_path = File.join(tmp_dir_path, TerrImporter::Application::Configuration::CONFIG_DEFAULT_NAME)
|
49
|
+
FileUtils.mkdir(tmp_dir_path) unless File.exist? tmp_dir_path
|
50
|
+
FileUtils.cp example_configuration_path, test_configuration_path
|
51
|
+
@test_configuration_file = test_configuration_path
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete_test_configuration_file
|
55
|
+
FileUtils.rm_rf @test_configuration_file if File.exists? @test_configuration_file
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|