terrimporter 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+
4
+ group :development do
5
+ gem "shoulda", ">= 0"
6
+ gem "bundler", "~> 1.0.0"
7
+ gem "jeweler", "~> 1.6.4"
8
+ gem "rcov", ">= 0"
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.6.4)
19
+ rcov
20
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Daniel Kummer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = terrimporter
2
+
3
+ Description following in one of the next releases
4
+
5
+ == Contributing to terrimporter
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Daniel Kummer. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "terrimporter"
18
+ gem.homepage = "http://github.com/danielkummer/terrimporter"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Import terrific javascripts, css files and images into a web project}
21
+ gem.description = %Q{This is an importer to import files generated from terrific (http://www.terrifically.org/) into any web project.
22
+ This should reduce merging time significantly and improve overall efficiency.}
23
+ gem.email = "daniel.kummer@gmail.com"
24
+ gem.authors = ["Daniel Kummer"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "terrimporter #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/bin/terrimporter ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'rubygems'
4
+ require 'terrimporter'
5
+
6
+ exit TerrImporter::Application.run!(*ARGV)
@@ -0,0 +1,69 @@
1
+ ########################################################################################################################
2
+ # Terrific import configuration file, adjust as needed.
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:' pattern:
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
+ terrific:
39
+ version: 0.5
40
+ url: http://terrific.abochecker
41
+ app_path: /Users/danielkummer/_NAMICS/projekte/mobilezone/mobilezone-abo_optimizer/public/terrific
42
+ export_path: /terrific/base/%2$s/public/%1$s/base/base.%1$s.php
43
+ libraries_source_path: /js/libraries/dynamic/
44
+ image_base_path: /img
45
+ downloader: curl
46
+ export_settings:
47
+ layout: project
48
+ debug: false
49
+ case: false
50
+ stylesheets:
51
+ dest: public/stylesheets/
52
+ styles: ie
53
+ replace:
54
+ - what: /img/
55
+ with: /images/
56
+ javascripts:
57
+ dest: public/javascripts/
58
+ dynamic_libraries: warning pngfix
59
+ libraries_dest: /
60
+ images:
61
+ - src: /
62
+ dest: public/images/
63
+ types: jpg png gif
64
+ - src: /
65
+ dest: public/
66
+ types: ico
67
+ - src: /backgrounds/
68
+ dest: public/images/backgrounds/
69
+ types: jpg
data/lib/app_logger.rb ADDED
@@ -0,0 +1,43 @@
1
+ module Logging
2
+ require 'logger'
3
+
4
+ #logformatter monkeypatch
5
+ class LogFormatter < Logger::Formatter
6
+ CUSTOM_FORMAT = "[%s] %5s %s: %s\n"
7
+
8
+ def call(severity, time, progname, message)
9
+ CUSTOM_FORMAT % [format_datetime(time), severity, progname, msg2str(message)]
10
+ end
11
+
12
+ def format_datetime(time)
13
+ time.strftime("%Y-%m-%d %H:%M:%S")
14
+ end
15
+ end
16
+
17
+
18
+ # @param hash [:info => "message", :debug => "message", :error => "message"]
19
+ def log(hash)
20
+ Logging.log.debug hash[:debug] unless hash[:debug].nil?
21
+ Logging.log.info hash[:info] unless hash[:info].nil?
22
+ Logging.log.warn hash[:warn] unless hash[:warn].nil?
23
+ Logging.log.error hash[:error] unless hash[:error].nil?
24
+ Logging.log.fatal hash[:fatal] unless hash[:fatal].nil?
25
+ end
26
+
27
+ def self.log
28
+ @logger ||= Logger.new $stdout
29
+ @logger.formatter = LogFormatter.new
30
+ @logger
31
+ end
32
+
33
+ def verbose?
34
+ !self.options.nil? && self.options[:verbose] = true
35
+ end
36
+
37
+ def self.initialize_logger
38
+
39
+ end
40
+
41
+ end
42
+
43
+
data/lib/importer.rb ADDED
@@ -0,0 +1,220 @@
1
+ require 'fileutils'
2
+ require 'app_logger'
3
+ require 'yaml'
4
+ require 'uri'
5
+
6
+
7
+ class TerrImporter
8
+
9
+ CONFIG_DEFAULT_NAME = 'terrimporter.config.yml'
10
+
11
+ class DefaultError < StandardError
12
+ end
13
+
14
+ class ConfigurationError < StandardError
15
+ end
16
+
17
+ class Importer
18
+ require 'options'
19
+ include Logging
20
+
21
+ attr_accessor :options, :config
22
+
23
+ def initialize(options = {})
24
+ self.options = options
25
+ end
26
+
27
+ def run
28
+ init_config(config_file_path)
29
+
30
+ if options[:all] != nil and options[:all] == true
31
+ import_js
32
+ import_css
33
+ import_images
34
+ else
35
+
36
+ options.each do |option, value|
37
+ if option.to_s =~ /^import_/ and value == true
38
+ #test this really good!!!
39
+ self.send option.to_s
40
+
41
+ end
42
+
43
+
44
+ end
45
+ end
46
+ end
47
+
48
+ def import_css
49
+ unclean_suffix = "_unclean"
50
+
51
+ check_and_create_dir config['stylesheets']['dest']
52
+
53
+ #create stylesheet array and add base.css
54
+ styles = config['stylesheets']['styles'].split(" ")
55
+ styles << "base"
56
+
57
+ styles.each do |css|
58
+ destination_path = File.join(config['stylesheets']['dest'], css + ".css")
59
+ options = {}
60
+ options[:suffix] = css if css.include?('ie') #add ie option if in array
61
+
62
+ source_url = construct_export_request(:css, options)
63
+ run_download(source_url, destination_path + unclean_suffix)
64
+
65
+ #do line replacement
66
+ File.open(destination_path, 'w') do |d|
67
+ File.open(destination_path + unclean_suffix, 'r') do |s|
68
+ lines = s.readlines
69
+ lines.each do |line|
70
+ d.print stylesheet_replace_strings(line)
71
+ end
72
+ end
73
+ end
74
+ FileUtils.remove destination_path + unclean_suffix
75
+ end
76
+ end
77
+
78
+ def import_js
79
+ destination_path = File.join(config['javascripts']['dest'], "base.js")
80
+ js_source_url = construct_export_request :js
81
+ puts "Importing base.js from #{js_source_url} to #{destination_path}"
82
+ run_download(js_source_url, destination_path)
83
+
84
+ #start library import
85
+
86
+ libraries_destination_path = File.join(config['javascripts']['dest'], config['javascripts']['libraries_dest'])
87
+
88
+ check_and_create_dir libraries_destination_path
89
+
90
+ js_libraries = config['javascripts']['dynamic_libraries'].split(" ")
91
+
92
+ puts "Importing libraries from #{config['libraries_source_path']} to #{libraries_destination_path}"
93
+
94
+ js_libraries.each do |lib|
95
+ run_download(config['libraries_source_path'] + lib + ".js", File.join(libraries_destination_path, lib + ".js"))
96
+ end
97
+
98
+ end
99
+
100
+ def import_images
101
+ config['images'].each do |image|
102
+ check_and_create_dir image['dest']
103
+ image_source_path = File.join(config['image_base_path'], image['src'])
104
+ batch_download_files(image_source_path, image['dest'], image['types'])
105
+ end
106
+ end
107
+
108
+ 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
+
143
+ def batch_download_files(relative_source_path, relative_dest_path, type_filter = "")
144
+ source_path = relative_source_path
145
+
146
+ puts "Downloading files from #{config['url']}#{source_path} to #{relative_dest_path} #{"allowed extensions: " + type_filter unless type_filter.empty?}"
147
+
148
+ files = get_file_list(source_path)
149
+
150
+ unless type_filter.empty?
151
+ puts "Appling type filter: #{type_filter}"
152
+ files = files.find_all { |file| file =~ Regexp.new(".*" + type_filter.strip.gsub(" ", "|") + "$") }
153
+ end
154
+
155
+ puts "Downloading #{files.size} files..."
156
+ files.each do |file|
157
+ destination_path = File.join(relative_dest_path, file)
158
+ run_download(source_path + file, destination_path, :remove_old => false)
159
+ end
160
+ end
161
+
162
+ def get_file_list(source_path)
163
+ output = run_download(source_path)
164
+ files = []
165
+
166
+ output.scan(/<a\shref=\"([^\"]+)\"/) { |res| files << res[0] if not res[0] =~ /^\?/ and res[0].size > 1 }
167
+ files
168
+ end
169
+
170
+ def construct_export_request(for_what = :js, options={})
171
+ raise "Specify js or css url" unless for_what == :js or for_what == :css
172
+ export_settings = config['export_settings'].clone
173
+
174
+ export_settings['application'] = config['app_path']
175
+ export_settings.merge!(options)
176
+ export_settings['appbaseurl'] = "" if for_what == :css
177
+
178
+ #glue everything together
179
+ export_path = config['export_path']
180
+ export_path.insert(0, "/") unless export_path.match(/^\//)
181
+
182
+ export_path = export_path % [for_what.to_s, config['version']] #replace placeholders
183
+ export_path << '?' << export_settings.map { |k, v| "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}" }.join("&")
184
+ export_path
185
+ end
186
+
187
+ def check_and_create_dir(dir, create = true)
188
+ unless File.directory?(dir)
189
+ puts "Directory #{dir} does not exists... it will #{"not" unless true} be created"
190
+ FileUtils.mkpath(dir) if create
191
+ end
192
+ end
193
+
194
+ def stylesheet_replace_strings(line)
195
+ config['stylesheets']['replace'].each do |replace|
196
+ what = replace['what']
197
+ with = replace['with']
198
+ what = Regexp.new "/#{$1}" if what.match(/^r\//)
199
+ line.gsub! what, with
200
+ end
201
+ line
202
+ end
203
+
204
+ #todo use as central download processing
205
+ def run_download(remote_path, local = nil, options = {})
206
+ FileUtils.remove_file(local) if not local.nil? and File.exists?(local) and not File.directory?(local) and not options[:remove_old] == true
207
+ remote_url = config['url'] + remote_path
208
+
209
+ case config['downloader']
210
+ when 'curl'
211
+ output = `curl '#{remote_url}' #{"> #{local}" if local != nil}`
212
+ raise "FATAL: An error orrured downloading from #{remote_url} #{"to #{local}: \n #{output}" if local != nil}" if output.include?('error')
213
+ return output
214
+ when 'wget'
215
+ #todo
216
+ end
217
+
218
+ end
219
+ end
220
+ end
data/lib/options.rb ADDED
@@ -0,0 +1,67 @@
1
+ class TerrImporter
2
+ class Application
3
+ class Options < Hash
4
+ attr_reader :opts, :orig_args
5
+
6
+ def initialize(args)
7
+ super()
8
+
9
+ @orig_args = args.clone
10
+
11
+ self[:verbose] = true
12
+
13
+ require 'optparse'
14
+ @opts = OptionParser.new do |o|
15
+ o.banner = "Usage: #{File.basename($0)} [options] \n e.g. #{File.basename($0)} -a, use --init for first time use"
16
+
17
+ o.separator ''
18
+ o.separator 'Common options:'
19
+
20
+ o.on('-a', '--all', 'export everything configured; javascripts, css files and images') do
21
+ self[:import_css] = true
22
+ self[:import_js] = true
23
+ self[:import_images] = true
24
+ end
25
+
26
+ o.on('-c', '--css', 'export configured css files') { self[:import_css] = true }
27
+ o.on('-i', '--img', 'export configured image files') { self[:import_images] = true }
28
+ o.on('-j', '--js', 'export configured javascript files') { self[:import_js] = true }
29
+ o.on('--init', 'create configuration file in current working directory') { self[:init] = true }
30
+ #todo add force option to init
31
+
32
+ o.separator ''
33
+ o.separator 'Additional configuration:'
34
+
35
+ #o.on('-v', '--verbose [on, off], default [on]', [true, false], 'Verbose mode') do |v|
36
+ o.on('-v', '--[no-]verbose', 'run verbosely') do |v|
37
+ self[:verbose] = v
38
+ end
39
+
40
+ o.on('--version', 'Show version') do
41
+ puts ::File.open(::File.join(File.dirname(__FILE__), "..", "VERSION"), 'r').gets
42
+ exit
43
+ end
44
+
45
+ o.on_tail('-h', '--help', 'display this help and exit') { self[:show_help] = true }
46
+ end
47
+
48
+ begin
49
+ @opts.parse!(args)
50
+ show_help_on_no_options
51
+ self[:input_file] = args.shift
52
+ rescue OptionParser::InvalidOption => e
53
+ self[:invalid_argument] = e.message
54
+ end
55
+ end
56
+
57
+ def merge(other)
58
+ self.class.new(@orig_args + other.orig_args)
59
+ end
60
+
61
+ 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]
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,69 @@
1
+ require 'shellwords'
2
+ require 'options'
3
+ require 'importer'
4
+
5
+
6
+ class TerrImporter
7
+ class Application
8
+ class << self
9
+ include Shellwords
10
+
11
+ def run!(*arguments)
12
+ options = build_options(arguments)
13
+
14
+
15
+ if options[:init]
16
+ #todo the config path can be differen in importer, extract to special class for loading and managing
17
+ #todo raise error instead of puts and exit
18
+ if File.exists?(File.join(Dir.pwd, CONFIG_DEFAULT_NAME))
19
+ puts "Configuration already existing, use the force option to override"
20
+ return 1
21
+ end
22
+ create_config
23
+ return 0
24
+ end
25
+
26
+ if options[:invalid_argument]
27
+ $stderr.puts options[:invalid_argument]
28
+ options[:show_help] = true
29
+ end
30
+
31
+ if options[:show_help]
32
+ $stderr.puts options.opts
33
+ return 1
34
+ end
35
+
36
+ #if options[:input_file].nil?
37
+ # $stderr.puts options.opts
38
+ # return 1
39
+ #end
40
+
41
+ begin
42
+ importer = TerrImporter::Importer.new(options)
43
+ importer.run
44
+ return 0
45
+ rescue TerrImporter::ConfigurationError
46
+ $stderr.puts %Q{Configuration Error #{ $!.message }}
47
+ rescue TerrImporter::DefaultError
48
+ $stderr.puts %Q{Unspecified Error #{ $!.message }}
49
+ return 1
50
+
51
+ end
52
+ end
53
+
54
+ #todo check force option, only override if not existing, else raise and exit
55
+ def create_config
56
+ FileUtils.cp(File.join(File.dirname(__FILE__), "..", "config", CONFIG_DEFAULT_NAME), File.join(Dir.pwd, CONFIG_DEFAULT_NAME))
57
+ end
58
+
59
+
60
+ def build_options(arguments)
61
+ env_opts_string = ENV['TERRIMPORTER_OPTS'] || ""
62
+ env_opts = TerrImporter::Application::Options.new(shellwords(env_opts_string))
63
+ argument_opts = TerrImporter::Application::Options.new(arguments)
64
+ env_opts.merge(argument_opts)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{terrimporter}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Daniel Kummer}]
12
+ s.date = %q{2011-08-17}
13
+ s.description = %q{This is an importer to import files generated from terrific (http://www.terrifically.org/) into any web project.
14
+ This should reduce merging time significantly and improve overall efficiency.}
15
+ s.email = %q{daniel.kummer@gmail.com}
16
+ s.executables = [%q{terrimporter}]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/terrimporter",
30
+ "config/terrimporter.config.yml",
31
+ "lib/app_logger.rb",
32
+ "lib/importer.rb",
33
+ "lib/options.rb",
34
+ "lib/terrimporter.rb",
35
+ "terrimporter.gemspec",
36
+ "test/helper.rb",
37
+ "test/test_terrimporter.rb",
38
+ "test/unit/test_importer.rb",
39
+ "test/unit/test_options.rb",
40
+ "test/unit/test_terrimporter.rb"
41
+ ]
42
+ s.homepage = %q{http://github.com/danielkummer/terrimporter}
43
+ s.licenses = [%q{MIT}]
44
+ s.require_paths = [%q{lib}]
45
+ s.rubygems_version = %q{1.8.5}
46
+ s.summary = %q{Import terrific javascripts, css files and images into a web project}
47
+
48
+ if s.respond_to? :specification_version then
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
55
+ s.add_development_dependency(%q<rcov>, [">= 0"])
56
+ else
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<shoulda>, [">= 0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
67
+ end
68
+ end
69
+
data/test/helper.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+ require 'terrimporter'
17
+
18
+ class Test::Unit::TestCase
19
+ end
@@ -0,0 +1,8 @@
1
+ require 'helper'
2
+
3
+ class TestTerrimporter < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ #flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,132 @@
1
+ require "helper"
2
+
3
+ class TestImporter < Test::Unit::TestCase
4
+ def setup
5
+ create_test_configuration_file
6
+ @importer = TerrImporter::Importer.new
7
+ #todo mock load config with different path
8
+ end
9
+
10
+ def teardown
11
+ delete_test_configuration_file
12
+ end
13
+
14
+ =begin
15
+ context 'configuration missing' do
16
+ setup {}
17
+ teardown {}
18
+
19
+ should 'raise an error on missing configuration' do
20
+ assert_raise TerrImporter::ConfigurationError do
21
+ TerrImporter::Importer.new
22
+ puts "raised"
23
+ end
24
+ end
25
+ end
26
+ =end
27
+
28
+ context 'configuration loading' do
29
+ should 'get the current working directory as config file path' do
30
+ config_in_cwd = File.join(Dir.pwd, TerrImporter::CONFIG_DEFAULT_NAME)
31
+ assert_equal config_in_cwd, @importer.send(:config_file_path)
32
+ end
33
+
34
+ should 'get a configured directory path with the configuration file included' do
35
+ assert_equal @test_configuration_file, @importer.send(:config_file_path, @tmp_dir_path)
36
+ end
37
+
38
+ should 'throw an exception on non existing config' do
39
+ assert_raise TerrImporter::ConfigurationError do
40
+ @importer.send(:init_config, File.join('does/not/exist'))
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'configuration validation' do
46
+ setup do
47
+ @valid_config = YAML.load_file(@test_configuration_file)['terrific']
48
+ end
49
+
50
+ should 'see the copied original configuration as valid' do
51
+ assert_nothing_raised do
52
+ @importer.send(:validate_config, @valid_config)
53
+ end
54
+ end
55
+
56
+ should 'get a configuration error if trying to do something unsupported' do
57
+ invalid_bits = {
58
+ 'downloader' => 'something',
59
+ 'url' => 'invalidurl', #todo invalid url check not sane!!!!
60
+ 'version' => '',
61
+ 'app_path' => '',
62
+ 'export_path' => '',
63
+ 'image_base_path' => '',
64
+ 'stylesheets' => {'styles' => ['should_t_have_css_ext.css']},
65
+ 'javascripts' => {'dynamic_libraries' => ['should_t_have_js_ext.js'],
66
+ 'libraries_dest' => ''
67
+ }
68
+ }
69
+
70
+ invalid_bits.each do |k, v|
71
+ assert_raise TerrImporter::ConfigurationError do
72
+ puts "Testing invalid configuration: #{k} => #{v}"
73
+ @importer.send(:validate_config, @valid_config.merge({k => v}))
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+
80
+ def create_test_configuration_file
81
+ example_configuration_path = File.join(File.dirname(__FILE__), '..', '..', 'config', TerrImporter::CONFIG_DEFAULT_NAME)
82
+ @tmp_dir_path = File.join(File.dirname(__FILE__), '..', 'tmp')
83
+ @test_configuration_path = File.join(@tmp_dir_path, TerrImporter::CONFIG_DEFAULT_NAME)
84
+ FileUtils.mkdir(@tmp_dir_path) unless File.exist? @tmp_dir_path
85
+ FileUtils.cp example_configuration_path, @test_configuration_path
86
+ @test_configuration_file = @test_configuration_path
87
+ end
88
+
89
+ def delete_test_configuration_file
90
+ FileUtils.rm_rf @test_configuration_file if File.exists? @test_configuration_file
91
+ end
92
+
93
+ end
94
+
95
+
96
+ =begin
97
+ methods to test
98
+
99
+ run_download
100
+
101
+ stylesheet_replace_strings
102
+
103
+ check_and_create_dir
104
+
105
+ construct_export_request
106
+
107
+ get_file_list
108
+
109
+ batch_download_files
110
+
111
+ init_config
112
+
113
+ config_file_path
114
+
115
+ load_config
116
+
117
+ validate_config
118
+
119
+ config_exists?
120
+
121
+
122
+ import_images
123
+
124
+ import_js
125
+
126
+ import_css
127
+
128
+ run
129
+
130
+ initialize
131
+
132
+ =end
@@ -0,0 +1,138 @@
1
+ require "helper"
2
+
3
+ class TestOptions < Test::Unit::TestCase
4
+
5
+ def setup_options(*arguments)
6
+ #@input_file = "dummy.yml"
7
+ @input_file = "testfile"
8
+ @options = TerrImporter::Application::Options.new([@input_file] + arguments)
9
+ end
10
+
11
+ def self.for_options(*options)
12
+ context options.join(' ') do
13
+ setup do
14
+ wrap_out { setup_options *options }
15
+ end
16
+ yield
17
+ end
18
+ end
19
+
20
+ #todo not working
21
+ def wrap_out
22
+ original_stdout = $stdout
23
+ original_stderr = $stderr
24
+
25
+ fake_stdout = StringIO.new
26
+ fake_stderr = StringIO.new
27
+
28
+ $stdout = fake_stdout
29
+ $stderr = fake_stderr
30
+
31
+ begin
32
+ yield if block_given?
33
+ ensure
34
+ $stdout = original_stdout
35
+ $stderr = original_stderr
36
+ end
37
+ @stdout = fake_stdout.string
38
+ @stderr = fake_stderr.string
39
+ end
40
+
41
+ context "default options" do
42
+ setup { setup_options }
43
+
44
+ should "be in verbose mode" do
45
+ assert_equal true, @options[:verbose]
46
+ end
47
+
48
+ should "have no default import statement" do
49
+ assert_nil @options[:import_css]
50
+ assert_nil @options[:import_js]
51
+ assert_nil @options[:import_images]
52
+ end
53
+
54
+ end
55
+
56
+ for_options '--init' do
57
+ should 'initialize project' do
58
+ assert @options[:init]
59
+ end
60
+ end
61
+
62
+ for_options '-c' do
63
+ should 'import css files' do
64
+ assert @options[:import_css]
65
+ end
66
+ end
67
+
68
+ for_options '--css' do
69
+ should 'import css files' do
70
+ assert @options[:import_css]
71
+ end
72
+ end
73
+
74
+ for_options '-j' do
75
+ should 'import js files' do
76
+ assert @options[:import_js]
77
+ end
78
+ end
79
+
80
+ for_options '--js' do
81
+ should 'import js files' do
82
+ assert @options[:import_js]
83
+ end
84
+ end
85
+
86
+ for_options '-i' do
87
+ should 'import image files' do
88
+ assert @options[:import_images]
89
+ end
90
+ end
91
+
92
+ for_options '--img' do
93
+ should 'import image files' do
94
+ assert @options[:import_images]
95
+ end
96
+ end
97
+
98
+ for_options '-a' do
99
+ should 'import all files' do
100
+ assert @options[:import_css]
101
+ assert @options[:import_js]
102
+ assert @options[:import_images]
103
+ end
104
+ end
105
+
106
+ for_options '--all' do
107
+ should 'import all files' do
108
+ assert @options[:import_css]
109
+ assert @options[:import_js]
110
+ assert @options[:import_images]
111
+ end
112
+ end
113
+ for_options '--help' do
114
+ should 'show help' do
115
+ assert @options[:show_help]
116
+ end
117
+ end
118
+
119
+ for_options '-h' do
120
+ should 'show help' do
121
+ assert @options[:show_help]
122
+ end
123
+ end
124
+ for_options '-v' do
125
+ should 'show version' do
126
+ #assert @stdout.include? "0.1.0"
127
+ #todo implement real test
128
+ assert true
129
+ end
130
+ end
131
+
132
+ for_options '' do
133
+ should 'show help if no options supplied' do
134
+ assert @options[:show_help]
135
+ end
136
+ end
137
+
138
+ end
@@ -0,0 +1,27 @@
1
+ require "helper"
2
+ require "FileUtils"
3
+
4
+
5
+ class TerrImporterTest < Test::Unit::TestCase
6
+
7
+ def teardown
8
+ FileUtils.rm_rf File.join(Dir.pwd, TerrImporter::CONFIG_DEFAULT_NAME)
9
+ end
10
+
11
+ should 'merge environment and argument options' do
12
+ ENV['TERRIMPORTER_OPTS'] = '-j -c'
13
+ merged_options = TerrImporter::Application.build_options([''] + ['-i', '--verbose'])
14
+ expected_options = {:import_css => true,
15
+ :import_js => true,
16
+ :import_images => true,
17
+ :verbose => true,
18
+ :input_file => ''}
19
+
20
+ assert_contains merged_options, expected_options
21
+ end
22
+
23
+ should 'create a config file in the current directory' do
24
+ TerrImporter::Application.create_config
25
+ assert File.exists?(File.join(Dir.pwd, TerrImporter::CONFIG_DEFAULT_NAME))
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: terrimporter
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
+ platform: ruby
12
+ authors:
13
+ - Daniel Kummer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-17 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ requirement: *id001
32
+ prerelease: false
33
+ name: shoulda
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ hash: 23
41
+ segments:
42
+ - 1
43
+ - 0
44
+ - 0
45
+ version: 1.0.0
46
+ type: :development
47
+ requirement: *id002
48
+ prerelease: false
49
+ name: bundler
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ hash: 7
57
+ segments:
58
+ - 1
59
+ - 6
60
+ - 4
61
+ version: 1.6.4
62
+ type: :development
63
+ requirement: *id003
64
+ prerelease: false
65
+ name: jeweler
66
+ - !ruby/object:Gem::Dependency
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ requirement: *id004
78
+ prerelease: false
79
+ name: rcov
80
+ description: |-
81
+ This is an importer to import files generated from terrific (http://www.terrifically.org/) into any web project.
82
+ This should reduce merging time significantly and improve overall efficiency.
83
+ email: daniel.kummer@gmail.com
84
+ executables:
85
+ - terrimporter
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ files:
92
+ - .document
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.rdoc
97
+ - Rakefile
98
+ - VERSION
99
+ - bin/terrimporter
100
+ - config/terrimporter.config.yml
101
+ - lib/app_logger.rb
102
+ - lib/importer.rb
103
+ - lib/options.rb
104
+ - lib/terrimporter.rb
105
+ - terrimporter.gemspec
106
+ - test/helper.rb
107
+ - test/test_terrimporter.rb
108
+ - test/unit/test_importer.rb
109
+ - test/unit/test_options.rb
110
+ - test/unit/test_terrimporter.rb
111
+ homepage: http://github.com/danielkummer/terrimporter
112
+ licenses:
113
+ - MIT
114
+ post_install_message:
115
+ rdoc_options: []
116
+
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 3
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 3
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ requirements: []
138
+
139
+ rubyforge_project:
140
+ rubygems_version: 1.8.5
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: Import terrific javascripts, css files and images into a web project
144
+ test_files: []
145
+