theme_bandit 0.0.7 → 0.0.8

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: 4c1feaabd974b8c53b878efa185272e62cd157d4
4
- data.tar.gz: fdf1c431def302ee0ccafba20e617de569254a5f
3
+ metadata.gz: 0111051d7708ed2501faccdc2dae5c174023a9a3
4
+ data.tar.gz: f9a5c5eb5eaade14121d9e1a9dd8f45616e8dbd4
5
5
  SHA512:
6
- metadata.gz: a96154643d9addc33d62ddb79686713478552784f2c0e37047176492cd15e48683711e07631539b3ca7b2641e3ed207f4760541f1df3bda025173d8daac82b17
7
- data.tar.gz: 7591c424dc88e71b98f53a5a0d71466ad52b6c8831dc491fca558ee606c51894555ea9af461ad0273239f0f9282bdbe48afb4eedd1f1437731c701f85b5019d7
6
+ metadata.gz: e0ffe2ab326ce6e5031f9d739a7162e8c79fa75784c73b8f94f13bc04a22b3cd1d33a3db4a19667174f073deda186708493a5da766565935af083153fcb0f7dd
7
+ data.tar.gz: 554ae507f4c57b8dee9c0270569d122052dd2ecfbe7235c7aee6a064145383c1fb9041030fb6a2de6c62923f81d131d3ffd5b4e2a6584fe7f913fd8267096954
data/README.md CHANGED
@@ -37,7 +37,7 @@ and cause the application to blow up until adjusted.
37
37
 
38
38
  Add this line to your application's Gemfile:
39
39
 
40
- gem 'theme_bandit', '~> 0.0.7'
40
+ gem 'theme_bandit', '~> 0.0.8'
41
41
 
42
42
  And then execute:
43
43
 
data/bin/bandit CHANGED
@@ -46,10 +46,13 @@ end
46
46
  def ask_user_for_domain
47
47
  puts 'Enter the URL of the theme you wish to download (example: http://www.google.com)'
48
48
  url = $stdin.gets.chomp
49
- if url == ''
50
- raise 'Invalid url'
51
- else
52
- url
49
+
50
+ begin
51
+ URI.parse(url)
52
+ return url
53
+ rescue => e
54
+ ThemeBandit::Logger.red e
55
+ exit
53
56
  end
54
57
  end
55
58
 
@@ -58,7 +61,8 @@ def ask_user_for_language
58
61
  answer = $stdin.gets.chomp
59
62
  answer = 'erb' if answer == ''
60
63
  unless match = answer.match(SUPPORTED_ENGINES)
61
- fail "You must select a supported template engine (erb, haml, or slim)"
64
+ ThemeBandit::Logger.red "You must select a supported template engine (erb, haml, or slim)"
65
+ exit
62
66
  end
63
67
  match[0]
64
68
  end
@@ -68,18 +72,17 @@ def ask_user_to_start_rack_app
68
72
  answer = $stdin.gets.chomp
69
73
  if answer == 'y'
70
74
  app_message
71
- puts 'changing directory to ./theme'
72
75
  Dir.chdir 'theme' do
73
76
  Bundler.with_clean_env do
74
- puts "running bundle in #{Dir.pwd}/"
77
+ ThemeBandit::Logger.green "running `bundle` in #{Dir.pwd}/"
75
78
  `bundle install`
76
- puts 'running `bundle exec rackup -p 3000`'
79
+ ThemeBandit::Logger.green 'running `bundle exec rackup -p 3000`'
77
80
  system('bundle exec rackup -p 3000')
78
81
  end
79
82
  end
80
83
  else
81
84
  app_message
82
- puts "Don't forget to bundle before starting!"
85
+ ThemeBandit::Logger.red "Don't forget to bundle before starting!"
83
86
  end
84
87
  end
85
88
 
@@ -94,3 +97,5 @@ rescue LoadError => e
94
97
  require 'rubygems'
95
98
  require 'theme_bandit'
96
99
  end
100
+
101
+
@@ -13,7 +13,7 @@ module ThemeBandit
13
13
  end
14
14
 
15
15
  def self.error
16
- fail 'Invalid configuration, please configure through ./bin wrapper'
16
+ Logger.red 'Invalid configuration, please configure through ./bin wrapper'
17
17
  end
18
18
 
19
19
  attr_reader :url, :options, :document
@@ -25,9 +25,10 @@ module ThemeBandit
25
25
 
26
26
  def get_document(url)
27
27
  begin
28
+ Logger.green "Downloading #{url}"
28
29
  self.class.get(url, options)
29
30
  rescue => e
30
- p "request failed for #{url} #{e}"
31
+ Logger.red "request failed for #{url} #{e}"
31
32
  end
32
33
  end
33
34
  end
@@ -1,6 +1,8 @@
1
1
  require 'uri'
2
2
  require 'nokogiri'
3
3
 
4
+ require_relative 'util/logger'
5
+
4
6
  require_relative 'downloader'
5
7
  require_relative 'url_formatter'
6
8
 
@@ -14,7 +14,9 @@ module ThemeBandit
14
14
 
15
15
  def script_tag_values
16
16
  script_tags.map do |tag|
17
- src = URI.parse(tag.attribute('src'))
17
+ src = tag.attribute('src').to_s
18
+ src = cdn_to_fdq(src)
19
+ src = URI.parse(src)
18
20
  if src.absolute?
19
21
  strip_query_string src.to_s
20
22
  else
@@ -4,6 +4,10 @@ module ThemeBandit
4
4
  str.split('?').first
5
5
  end
6
6
 
7
+ def cdn_to_fdq(src)
8
+ src[/^\/\//] ? "http:#{src}" : src
9
+ end
10
+
7
11
  # returns an aboslute url with dot dot syntax removed
8
12
  def resolve_dot_dots(host, path)
9
13
  number_of_dot_dots = path.split('/').select { |v| v == '..' }.length
@@ -0,0 +1,23 @@
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
@@ -1,3 +1,3 @@
1
1
  module ThemeBandit
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -1,3 +1,5 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
1
3
  require 'pry'
2
4
  require 'rubygems'
3
5
  require 'minitest/autorun'
@@ -65,3 +67,13 @@ def stub_js
65
67
  url = 'http://www.example.com/js/script_2.js'
66
68
  stub_request(:any, url).to_return(body: '')
67
69
  end
70
+
71
+ # supress log output when running tests
72
+ module ThemeBandit
73
+ class Logger
74
+ class << self
75
+ def colorize(text, color_code)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -14,7 +14,8 @@ describe ThemeBandit::Downloader do
14
14
 
15
15
  it 'requires url configuration' do
16
16
  ThemeBandit.configure { |config| config.url = nil }
17
- lambda { @subject.get_theme }.must_raise RuntimeError
17
+ @subject.get_theme
18
+ assert_equal(ThemeBandit::Logger.message, "Invalid configuration, please configure through ./bin wrapper")
18
19
  end
19
20
 
20
21
  describe 'attributes' do
@@ -14,5 +14,11 @@ describe ThemeBandit::URLFormatter do
14
14
  path = '../doc/docs.css'
15
15
  assert_equal(resolve_dot_dots(host, path), 'www.example.com/demo/doc/docs.css')
16
16
  end
17
+ it '#cdn_to_fdq' do
18
+ src = '//cdn.optimizely.com/js/2953003.js'
19
+ assert_equal(cdn_to_fdq(src), "http:#{src}")
20
+ src = 'https://cdn.optimizely.com/js/2953003.js'
21
+ assert_equal(cdn_to_fdq(src), src)
22
+ end
17
23
 
18
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theme_bandit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Fender
@@ -158,6 +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
162
  - lib/theme_bandit/util/version.rb
162
163
  - test/fixtures/css/import.css
163
164
  - test/fixtures/css/style.css