theme_bandit 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0111051d7708ed2501faccdc2dae5c174023a9a3
4
- data.tar.gz: f9a5c5eb5eaade14121d9e1a9dd8f45616e8dbd4
3
+ metadata.gz: afe66789b9e5f2f5f5ec9423e12e5014b585891e
4
+ data.tar.gz: 66f473dd65b4fee63cdde94991cdd0a0e9c1b80f
5
5
  SHA512:
6
- metadata.gz: e0ffe2ab326ce6e5031f9d739a7162e8c79fa75784c73b8f94f13bc04a22b3cd1d33a3db4a19667174f073deda186708493a5da766565935af083153fcb0f7dd
7
- data.tar.gz: 554ae507f4c57b8dee9c0270569d122052dd2ecfbe7235c7aee6a064145383c1fb9041030fb6a2de6c62923f81d131d3ffd5b4e2a6584fe7f913fd8267096954
6
+ metadata.gz: 4543e39293d4097d5c338d0e384b1942f7a77348be98f2f4c6d6f7f14086c4eaaff66ad704884a98837d2761230fb4c384a9c322a009d832abdc0d9e76e32e8e
7
+ data.tar.gz: c549898c2f46ba33443d6e885f4a9ad7976114df89fa64d2b52a879afd8d5a9e8ad998005cfa5cc7559962085bbaf82818be8e51e82aea6bb727fdf89f64a624
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  theme
2
+ *.log
2
3
 
3
4
  *.gem
4
5
  *.rbc
data/bin/bandit CHANGED
@@ -1,20 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'pry' if ENV['DEBUG']
4
+
3
5
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
6
 
5
- require 'fileutils'
6
7
  require 'theme_bandit'
7
- require 'uri'
8
8
  require 'bundler'
9
9
 
10
10
  SUPPORTED_ENGINES = /^(erb|haml|slim)$/
11
11
 
12
12
  def get_root
13
- begin
14
- Gem::Specification.find_by_name('theme_bandit').gem_dir
15
- rescue Gem::LoadError
16
- Dir.pwd
17
- end
13
+ Gem::Specification.find_by_name('theme_bandit').gem_dir
14
+ rescue Gem::LoadError
15
+ Dir.pwd
18
16
  end
19
17
 
20
18
  def init
@@ -30,8 +28,14 @@ def init
30
28
  end
31
29
 
32
30
  def start_fresh
33
- `rm -rf theme`
34
- make_a_directory
31
+ if File.directory?('theme')
32
+ ThemeBandit::Log.yellow "Deleting #{Dir.pwd}/theme/* - is this ok? (y/n)"
33
+ answer = $stdin.gets.chomp
34
+ if answer == 'y'
35
+ `rm -rf theme`
36
+ make_a_directory
37
+ end
38
+ end
35
39
  end
36
40
 
37
41
  def generate_app(document)
@@ -46,23 +50,26 @@ end
46
50
  def ask_user_for_domain
47
51
  puts 'Enter the URL of the theme you wish to download (example: http://www.google.com)'
48
52
  url = $stdin.gets.chomp
49
-
50
53
  begin
51
54
  URI.parse(url)
52
- return url
55
+ default_to_http url
53
56
  rescue => e
54
- ThemeBandit::Logger.red e
55
- exit
57
+ ThemeBandit::Log.red e
58
+ exit 0
56
59
  end
57
60
  end
58
61
 
62
+ def default_to_http(url)
63
+ url[/(^http:\/\/|^https:\/\/)/] ? url : "http://#{url}"
64
+ end
65
+
59
66
  def ask_user_for_language
60
67
  puts 'Select your favorite template engine (erb, haml, slim)'
61
68
  answer = $stdin.gets.chomp
62
69
  answer = 'erb' if answer == ''
63
70
  unless match = answer.match(SUPPORTED_ENGINES)
64
- ThemeBandit::Logger.red "You must select a supported template engine (erb, haml, or slim)"
65
- exit
71
+ ThemeBandit::Log.red 'You must select a supported template engine (erb, haml, or slim)'
72
+ exit 0
66
73
  end
67
74
  match[0]
68
75
  end
@@ -74,20 +81,20 @@ def ask_user_to_start_rack_app
74
81
  app_message
75
82
  Dir.chdir 'theme' do
76
83
  Bundler.with_clean_env do
77
- ThemeBandit::Logger.green "running `bundle` in #{Dir.pwd}/"
84
+ ThemeBandit::Log.green "running `bundle` in #{Dir.pwd}/"
78
85
  `bundle install`
79
- ThemeBandit::Logger.green 'running `bundle exec rackup -p 3000`'
86
+ ThemeBandit::Log.green 'running `bundle exec rackup -p 3000`'
80
87
  system('bundle exec rackup -p 3000')
81
88
  end
82
89
  end
83
90
  else
84
91
  app_message
85
- ThemeBandit::Logger.red "Don't forget to bundle before starting!"
92
+ ThemeBandit::Log.yellow "Don't forget to bundle before starting!"
86
93
  end
87
94
  end
88
95
 
89
96
  def app_message
90
- puts "Your rack app can be found at #{Dir.pwd}/theme/"
97
+ ThemeBandit::Log.yellow "Your rack app can be found at #{Dir.pwd}/theme/"
91
98
  end
92
99
 
93
100
  begin
@@ -97,5 +104,3 @@ rescue LoadError => e
97
104
  require 'rubygems'
98
105
  require 'theme_bandit'
99
106
  end
100
-
101
-
@@ -32,7 +32,6 @@ module ThemeBandit
32
32
  write_html_file
33
33
  end
34
34
 
35
-
36
35
  def html
37
36
  document.to_html
38
37
  end
@@ -41,7 +40,7 @@ module ThemeBandit
41
40
  FileUtils.mkdir_p folder
42
41
  end
43
42
 
44
- def download_css(files, these_are_import_files=false)
43
+ def download_css(files, these_are_import_files = false)
45
44
  files.each_with_index do |file, order|
46
45
  if these_are_import_files
47
46
  download_and_replace_import_in_css_file(file, order)
@@ -54,18 +53,22 @@ module ThemeBandit
54
53
  def download_and_replace_import_in_css_file(file, order)
55
54
  destination = file[:destination]
56
55
  rule = file[:rule]
57
- doc = Downloader.fetch(destination, {}).body
58
- new_doc = @doc_with_imports.gsub(rule, doc)
59
- new_file_name = @file_with_imports.split('/').last
60
- File.open("#{CSS_FOLDER}#{order}_#{new_file_name}", 'w') { |f| f.write(new_doc) }
61
- download_css_imports(new_doc, destination) do |imports|
62
- download_css(imports, true) if imports
56
+ doc = Downloader.fetch(destination, {})
57
+ if doc
58
+ new_doc = @doc_with_imports.gsub(rule, doc.body)
59
+ new_file_name = @file_with_imports.split('/').last
60
+ File.open("#{CSS_FOLDER}#{order}_#{new_file_name}", 'w') { |f| f.write(new_doc) }
61
+ download_css_imports(new_doc, destination) do |imports|
62
+ download_css(imports, true) if imports
63
+ end
64
+ else
65
+ log_failure file_name
63
66
  end
64
67
  end
65
68
 
66
69
  def download_single_css_file(file_name, order)
67
- doc = Downloader.fetch(file_name, {}).body
68
- download_css_imports(doc, file_name) do |imports|
70
+ doc = Downloader.fetch(file_name, {})
71
+ download_css_imports(doc.body, file_name) do |imports|
69
72
  if imports
70
73
  download_css(imports, true)
71
74
  else
@@ -89,13 +92,23 @@ module ThemeBandit
89
92
  def download_js(files)
90
93
  files.each_with_index do |file_name, order|
91
94
  doc = Downloader.fetch(file_name, {})
92
- new_file = file_name.split('/').last
93
- File.open("#{JS_FOLDER}#{order}_#{new_file}", 'w') { |file| file.write(doc.body) }
95
+ if doc
96
+ new_file = file_name.split('/').last
97
+ if doc.code != 200
98
+ log_failure(file_name, new_file)
99
+ end
100
+ File.open("#{JS_FOLDER}#{order}_#{new_file}", 'w') { |file| file.write(doc.body) }
101
+ end
94
102
  end
95
103
  end
96
104
 
97
105
  def write_html_file
98
106
  File.open("#{HTML_FOLDER}index.html", 'w') { |file| file.write(html) }
99
107
  end
108
+
109
+ def log_failure(file_name, new_file_name)
110
+ Log.red "Failed to write #{file_name}. Please view error.log for more details"
111
+ Log.patch file_name, new_file_name
112
+ end
100
113
  end
101
114
  end
@@ -13,23 +13,38 @@ module ThemeBandit
13
13
  end
14
14
 
15
15
  def self.error
16
- Logger.red 'Invalid configuration, please configure through ./bin wrapper'
16
+ Log.red 'Invalid configuration, please configure through ./bin wrapper or ThemeBandit::Configure'
17
17
  end
18
18
 
19
- attr_reader :url, :options, :document
19
+ attr_reader :url, :options, :document, :error
20
20
 
21
21
  def initialize(url, options = {})
22
- @url, @options = url, options
22
+ @url, @options = default_to_http(url), options
23
23
  @document = get_document(url)
24
24
  end
25
25
 
26
26
  def get_document(url)
27
- begin
28
- Logger.green "Downloading #{url}"
29
- self.class.get(url, options)
30
- rescue => e
31
- Logger.red "request failed for #{url} #{e}"
27
+ response = self.class.get(url, options)
28
+ log_request(url, response)
29
+ response
30
+ rescue => e
31
+ Log.red "request failed for #{url} #{e}"
32
+ false
33
+ end
34
+
35
+ private
36
+
37
+ def log_request(url, response)
38
+ if response.code != 200
39
+ @error = response.code
40
+ Log.red "Request failure trying to download #{url}, status #{response.code}"
41
+ else
42
+ Log.green "Downloading #{url}"
32
43
  end
33
44
  end
45
+
46
+ def default_to_http(url)
47
+ url[/(^http:\/\/|^https:\/\/)/] ? url : "http://#{url}"
48
+ end
34
49
  end
35
50
  end
@@ -1,7 +1,8 @@
1
+ require 'fileutils'
1
2
  require 'uri'
2
3
  require 'nokogiri'
3
4
 
4
- require_relative 'util/logger'
5
+ require_relative 'util/log'
5
6
 
6
7
  require_relative 'downloader'
7
8
  require_relative 'url_formatter'
@@ -1,7 +1,5 @@
1
- require 'pry'
2
1
  module ThemeBandit
3
2
  module CSSParser
4
-
5
3
  include ThemeBandit::URLFormatter
6
4
 
7
5
  RE_IMPORT = /\@import\s*(?:url\s*)?(?:\()?(?:\s*)["']?([^'"\s\)]*)["']?\)?([\w\s\,^\]\(\))]*)\)?[;\n]?/
@@ -18,20 +16,22 @@ module ThemeBandit
18
16
 
19
17
  def link_tag_values
20
18
  link_tags.map do |tag|
21
- href = URI.parse(tag.attribute('href'))
19
+ href = tag.attribute('href').to_s
20
+ href = cdn_to_fqd(href)
21
+ href = URI.parse(href)
22
22
  if href.absolute?
23
23
  strip_query_string href.to_s
24
24
  else
25
- # strip_query_string "#{url.scheme}://#{url.host}#{href}"
26
25
  new_href = strip_query_string(href.to_s)
27
- absolute = resolve_dot_dots "#{@url.host}#{@url.path}", new_href
28
- "#{url.scheme}://#{absolute}"
26
+ absolute_path = get_absolute_path "#{@url.path}", new_href
27
+ absolute = "#{@url.host}#{absolute_path}"
28
+ "#{@url.scheme}://#{absolute}"
29
29
  end
30
30
  end
31
31
  end
32
32
 
33
33
  def get_import_urls(file, file_name)
34
- imports = file.scan(RE_IMPORT).map { |import| import.first }.select {|import| import[/\.css/] }
34
+ imports = file.scan(RE_IMPORT).map(&:first).select { |import| import[/\.css/] }
35
35
  imports_arr = []
36
36
  imports.each do |import|
37
37
  dot_dots_length = import.split('/').select { |x| x[/\.\./] }.length
@@ -51,6 +51,5 @@ module ThemeBandit
51
51
  end
52
52
  imports_arr.length > 0 ? imports_arr : nil
53
53
  end
54
-
55
54
  end
56
55
  end
@@ -1,4 +1,3 @@
1
- require 'pry'
2
1
  module ThemeBandit
3
2
  module HTMLParser
4
3
  def revise_head_tags
@@ -15,13 +15,14 @@ module ThemeBandit
15
15
  def script_tag_values
16
16
  script_tags.map do |tag|
17
17
  src = tag.attribute('src').to_s
18
- src = cdn_to_fdq(src)
18
+ src = cdn_to_fqd(src)
19
19
  src = URI.parse(src)
20
20
  if src.absolute?
21
21
  strip_query_string src.to_s
22
22
  else
23
23
  new_src = strip_query_string(src.to_s)
24
- absolute = resolve_dot_dots "#{@url.host}#{@url.path}", new_src
24
+ absolute_path = get_absolute_path "#{@url.path}", new_src
25
+ absolute = "#{@url.host}#{absolute_path}"
25
26
  "#{url.scheme}://#{absolute}"
26
27
  end
27
28
  end
@@ -33,7 +33,6 @@ module ThemeBandit
33
33
  absolute_to_relative(File.read(index_html))
34
34
  end
35
35
 
36
-
37
36
  def absolute_to_relative(contents)
38
37
  contents.gsub("#{Dir.pwd}/theme/public", '')
39
38
  end
@@ -4,21 +4,28 @@ module ThemeBandit
4
4
  str.split('?').first
5
5
  end
6
6
 
7
- def cdn_to_fdq(src)
7
+ def cdn_to_fqd(src)
8
8
  src[/^\/\//] ? "http:#{src}" : src
9
9
  end
10
10
 
11
- # returns an aboslute url with dot dot syntax removed
12
- def resolve_dot_dots(host, path)
13
- number_of_dot_dots = path.split('/').select { |v| v == '..' }.length
11
+ # returns resolved path, ready for use with host
12
+ def get_absolute_path(old_path, new_path)
13
+ number_of_dot_dots = new_path.split('/').select { |v| v == '..' }.length
14
14
  if number_of_dot_dots > 0
15
- new_path = path.gsub('../', '')
16
- new_host = host.split('/')
17
- new_host.pop(number_of_dot_dots + 1)
18
- new_host.push(new_path).join('/')
15
+ # TODO: should be separate method
16
+ new_path = new_path.gsub('../', '')
17
+ old_path = old_path.split('/')
18
+ old_path.pop(number_of_dot_dots + 1)
19
+ new_path = old_path.push(new_path).join('/')
20
+ "#{path_with_leading_slash(new_path)}"
19
21
  else
20
- "#{host}#{path}"
22
+ "#{path_with_leading_slash(new_path)}"
21
23
  end
22
24
  end
25
+
26
+ def path_with_leading_slash(str)
27
+ str[/^\//] ? str : "/#{str}"
28
+ end
29
+
23
30
  end
24
31
  end
@@ -0,0 +1,40 @@
1
+ require 'logger'
2
+ module ThemeBandit
3
+ class Log < Logger
4
+ class << self
5
+ attr_accessor :message
6
+
7
+ def colorize(text, color_code)
8
+ $stdout.write "\e[#{color_code}m#{text}\e[0m\n"
9
+ end
10
+
11
+ def red(text)
12
+ @message = text
13
+ colorize(text, 31)
14
+ logger.error text
15
+ end
16
+
17
+ def patch(old_file_name, new_file_name)
18
+ @message = "#{old_file_name} failed to download. Manually patch .theme/public/*/#{new_file_name} in its place"
19
+ logger.error @message
20
+ end
21
+
22
+ def yellow(text)
23
+ @message = text
24
+ colorize(text, 33)
25
+ end
26
+
27
+ def green(text)
28
+ @message = text
29
+ colorize(text, 32)
30
+ end
31
+
32
+ private
33
+
34
+ def logger
35
+ @logger ||= new 'error.log'
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module ThemeBandit
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
@@ -1,79 +1,24 @@
1
1
  ENV['RACK_ENV'] = 'test'
2
2
 
3
3
  require 'pry'
4
+
4
5
  require 'rubygems'
5
6
  require 'minitest/autorun'
6
7
  require 'webmock/minitest'
7
8
 
8
9
  require_relative '../lib/theme_bandit'
9
10
 
10
- MiniTest.autorun
11
-
12
- def load_html_fixture
13
- @fixture ||= File.read(File.open("#{Dir.pwd}/test/fixtures/index.html", 'r'))
14
- end
15
-
16
- def load_css_fixture
17
- File.read(File.open("#{Dir.pwd}/test/fixtures/css/style.css", 'r'))
18
- end
19
-
20
- def load_import_fixture
21
- File.read(File.open("#{Dir.pwd}/test/fixtures/css/import.css", 'r'))
22
- end
23
-
24
- def load_style_with_import_fixture
25
- File.read(File.open("#{Dir.pwd}/test/fixtures/css/style_with_import.css", 'r'))
26
- end
27
-
28
- def test_url
29
- 'http://www.example.com'
30
- end
31
-
32
- def stub_request_stack
33
- stub_request(:any, test_url).to_return(body: load_html_fixture)
34
- stub_css
35
- stub_import_css
36
- stub_style_with_import_css
37
- stub_js
38
- end
11
+ require_relative 'support/common'
39
12
 
40
- def prep_config
41
- ThemeBandit.configure do |config|
42
- config.template_engine = 'erb'
43
- config.url = test_url
44
- config.gem_root = Dir.pwd
45
- end
46
- end
47
-
48
- def stub_css
49
- url = 'http://www.example.com/css/style.css'
50
- stub_request(:any, url).to_return(body: load_css_fixture)
51
- end
52
-
53
- def stub_import_css
54
- url = 'http://www.example.com/css/import.css'
55
- stub_request(:any, url).to_return(body: load_import_fixture)
56
- end
57
-
58
- def stub_style_with_import_css
59
- url = 'http://www.example.com/css/style_with_import.css'
60
- stub_request(:any, url).to_return(body: load_style_with_import_fixture)
61
- end
62
-
63
-
64
- def stub_js
65
- url = 'http://www.example.com/js/script.js'
66
- stub_request(:any, url).to_return(body: '')
67
- url = 'http://www.example.com/js/script_2.js'
68
- stub_request(:any, url).to_return(body: '')
69
- end
13
+ MiniTest.autorun
70
14
 
71
15
  # supress log output when running tests
72
16
  module ThemeBandit
73
- class Logger
17
+ class Log
74
18
  class << self
75
- def colorize(text, color_code)
19
+ def colorize(_text, _color_code)
76
20
  end
77
21
  end
78
22
  end
79
23
  end
24
+
@@ -0,0 +1,30 @@
1
+ # Bulk check of random urls
2
+
3
+ require_relative '../lib/theme_bandit'
4
+ require 'rubygems'
5
+
6
+ urls = [
7
+ 'https://wp-themes.com/crawford/',
8
+ 'http://yootheme.com/demo/themes/joomla/2014/peak/index.php?style=default',
9
+ 'http://ign.com',
10
+ 'http://gamespot.com',
11
+ 'http://news.ycombinator.com',
12
+ 'http://reddit.com'
13
+ ]
14
+
15
+ def get_root
16
+ Gem::Specification.find_by_name('theme_bandit').gem_dir
17
+ rescue Gem::LoadError
18
+ Dir.pwd
19
+ end
20
+
21
+ urls.each do |url|
22
+ ThemeBandit.configure do |config|
23
+ config.url = url
24
+ config.template_engine = 'erb'
25
+ config.gem_root = get_root
26
+ end
27
+ document = ThemeBandit::Downloader.get_theme
28
+ ThemeBandit::DocumentWriter.new(document).write
29
+ ThemeBandit::RackGenerator.build
30
+ end
@@ -0,0 +1,58 @@
1
+ def load_html_fixture
2
+ @fixture ||= File.read(File.open("#{Dir.pwd}/test/fixtures/index.html", 'r'))
3
+ end
4
+
5
+ def load_css_fixture
6
+ File.read(File.open("#{Dir.pwd}/test/fixtures/css/style.css", 'r'))
7
+ end
8
+
9
+ def load_import_fixture
10
+ File.read(File.open("#{Dir.pwd}/test/fixtures/css/import.css", 'r'))
11
+ end
12
+
13
+ def load_style_with_import_fixture
14
+ File.read(File.open("#{Dir.pwd}/test/fixtures/css/style_with_import.css", 'r'))
15
+ end
16
+
17
+ def test_url
18
+ 'http://www.example.com'
19
+ end
20
+
21
+ def stub_request_stack
22
+ stub_request(:any, test_url).to_return(body: load_html_fixture)
23
+ stub_css
24
+ stub_import_css
25
+ stub_style_with_import_css
26
+ stub_js
27
+ end
28
+
29
+ def prep_config
30
+ ThemeBandit.configure do |config|
31
+ config.template_engine = 'erb'
32
+ config.url = test_url
33
+ config.gem_root = Dir.pwd
34
+ end
35
+ end
36
+
37
+ def stub_css
38
+ url = 'http://www.example.com/css/style.css'
39
+ stub_request(:any, url).to_return(body: load_css_fixture)
40
+ end
41
+
42
+ def stub_import_css
43
+ url = 'http://www.example.com/css/import.css'
44
+ stub_request(:any, url).to_return(body: load_import_fixture)
45
+ end
46
+
47
+ def stub_style_with_import_css
48
+ url = 'http://www.example.com/css/style_with_import.css'
49
+ stub_request(:any, url).to_return(body: load_style_with_import_fixture)
50
+ end
51
+
52
+ def stub_js
53
+ url = 'http://www.example.com/js/script.js'
54
+ stub_request(:any, url).to_return(body: '')
55
+ url = 'http://www.example.com/js/script_2.js'
56
+ stub_request(:any, url).to_return(body: '')
57
+ end
58
+
@@ -65,15 +65,15 @@ describe ThemeBandit::DocumentWriter do
65
65
 
66
66
  describe ThemeBandit::CSSParser do
67
67
  it '#get_css_files' do
68
- assert_equal(@subject.get_css_files, ["http://www.example.com#{Dir.pwd}/theme/public/css/0_style.css", "http://www.example.com#{Dir.pwd}/theme/public/css/0_style_with_import.css" ])
68
+ assert_equal(@subject.get_css_files, ["http://www.example.com#{Dir.pwd}/theme/public/css/0_style.css", "http://www.example.com#{Dir.pwd}/theme/public/css/0_style_with_import.css"])
69
69
  end
70
70
 
71
71
  describe '#get_import_urls' do
72
72
  it 'returns false if none found' do
73
- assert_equal(@subject.get_import_urls(load_css_fixture, 'import.css'), nil )
73
+ assert_equal(@subject.get_import_urls(load_css_fixture, 'import.css'), nil)
74
74
  end
75
75
  it 'returns import urls' do
76
- expected = [{:destination=>"import.css", :rule=>"@import url('import.css');"}]
76
+ expected = [{ destination: 'import.css', rule: "@import url('import.css');" }]
77
77
  assert_equal(@subject.get_import_urls(load_style_with_import_fixture, 'style_with_import.css'), expected)
78
78
  end
79
79
  end
@@ -15,7 +15,7 @@ describe ThemeBandit::Downloader do
15
15
  it 'requires url configuration' do
16
16
  ThemeBandit.configure { |config| config.url = nil }
17
17
  @subject.get_theme
18
- assert_equal(ThemeBandit::Logger.message, "Invalid configuration, please configure through ./bin wrapper")
18
+ refute_empty(ThemeBandit::Log.message, 'Invalid configuration, please configure through ./bin wrapper')
19
19
  end
20
20
 
21
21
  describe 'attributes' do
@@ -23,8 +23,21 @@ describe ThemeBandit::Downloader do
23
23
  @instance = @subject.new(@url)
24
24
  end
25
25
 
26
- it '#url' do
27
- assert_equal(@instance.url, @url)
26
+ describe '#url' do
27
+ describe 'with scheme' do
28
+ it 'returns url' do
29
+ assert_equal(@instance.url, @url)
30
+ end
31
+ end
32
+
33
+ describe 'without scheme' do
34
+ before do
35
+ @instance = @subject.new('reddit.com')
36
+ end
37
+ it 'defaults to http' do
38
+ assert_equal(@instance.url, "http://reddit.com")
39
+ end
40
+ end
28
41
  end
29
42
 
30
43
  it '#options' do
@@ -9,16 +9,34 @@ describe ThemeBandit::URLFormatter do
9
9
  assert_equal(strip_query_string(url), 'http://www.example.com')
10
10
  end
11
11
 
12
- it '#resolve_dot_dots' do
13
- host = 'www.example.com/demo/abc/test.html'
14
- path = '../doc/docs.css'
15
- assert_equal(resolve_dot_dots(host, path), 'www.example.com/demo/doc/docs.css')
12
+ describe '#get_absolute_path' do
13
+ it 'it plays nicely with dot dots' do
14
+ host = '/demo/abc/test.html'
15
+ path = '../doc/docs.css'
16
+ assert_equal(get_absolute_path(host, path), '/demo/doc/docs.css')
17
+ end
18
+
19
+ describe 'non root-domain themes' do
20
+ before do
21
+ ThemeBandit.configure do |config|
22
+ config.template_engine = 'erb'
23
+ config.url = 'http://yootheme.com/demo/themes/joomla/2014/peak/index.php?style=default'
24
+ config.gem_root = Dir.pwd
25
+ end
26
+ end
27
+ it 'plays nice with non trailing slashes' do
28
+ old_path = '/demo/themes/joomla/2014/peak/index.php'
29
+ new_path = '/demo/themes/joomla/2014/peak/cache/template/widgetkit-627a3380-4ea1c88a.css'
30
+ assert_equal(get_absolute_path(old_path, new_path), '/demo/themes/joomla/2014/peak/cache/template/widgetkit-627a3380-4ea1c88a.css')
31
+ end
32
+ end
16
33
  end
17
- it '#cdn_to_fdq' do
34
+
35
+ it '#cdn_to_fqd' do
18
36
  src = '//cdn.optimizely.com/js/2953003.js'
19
- assert_equal(cdn_to_fdq(src), "http:#{src}")
37
+ assert_equal(cdn_to_fqd(src), "http:#{src}")
20
38
  src = 'https://cdn.optimizely.com/js/2953003.js'
21
- assert_equal(cdn_to_fdq(src), src)
39
+ assert_equal(cdn_to_fqd(src), src)
22
40
  end
23
41
 
24
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theme_bandit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Fender
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-26 00:00:00.000000000 Z
11
+ date: 2014-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -158,7 +158,7 @@ files:
158
158
  - lib/theme_bandit/recipes/sinatra/slim/config.ru
159
159
  - lib/theme_bandit/url_formatter.rb
160
160
  - lib/theme_bandit/util/configure.rb
161
- - lib/theme_bandit/util/logger.rb
161
+ - lib/theme_bandit/util/log.rb
162
162
  - lib/theme_bandit/util/version.rb
163
163
  - test/fixtures/css/import.css
164
164
  - test/fixtures/css/style.css
@@ -167,6 +167,8 @@ files:
167
167
  - test/fixtures/js/script.js
168
168
  - test/fixtures/js/script_2.js
169
169
  - test/helper.rb
170
+ - test/sanity_check.rb
171
+ - test/support/common.rb
170
172
  - test/test_configure.rb
171
173
  - test/test_document_writer.rb
172
174
  - test/test_downloader.rb
@@ -205,6 +207,8 @@ test_files:
205
207
  - test/fixtures/js/script.js
206
208
  - test/fixtures/js/script_2.js
207
209
  - test/helper.rb
210
+ - test/sanity_check.rb
211
+ - test/support/common.rb
208
212
  - test/test_configure.rb
209
213
  - test/test_document_writer.rb
210
214
  - test/test_downloader.rb
@@ -1,23 +0,0 @@
1
- module ThemeBandit
2
- class Logger
3
- class << self
4
-
5
- attr_accessor :message
6
-
7
- def colorize(text, color_code)
8
- $stdout.write "\e[#{color_code}m#{text}\e[0m\n"
9
- end
10
-
11
- def red text
12
- @message = text
13
- colorize(text, 31)
14
- end
15
-
16
- def green text
17
- @message = text
18
- colorize(text, 32)
19
- end
20
- end
21
-
22
- end
23
- end