smallvictories 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -3
- data/bin/sv +5 -7
- data/lib/smallvictories.rb +8 -184
- data/lib/smallvictories/compiler.rb +31 -0
- data/lib/smallvictories/configuration.rb +96 -0
- data/lib/smallvictories/constants.rb +9 -0
- data/lib/smallvictories/logger.rb +11 -0
- data/lib/smallvictories/version.rb +1 -1
- data/lib/smallvictories/watcher.rb +53 -0
- data/spec/compiler_spec.rb +27 -0
- data/spec/configuration_spec.rb +61 -0
- data/spec/fixtures/_config.yml +3 -1
- data/spec/fixtures/_stylesheets/_sv_custom.css +5 -0
- data/spec/fixtures/_stylesheets/bootstrap.scss +3 -0
- data/spec/fixtures/{_sass/_extra.scss → _stylesheets/extra.scss} +0 -0
- data/spec/fixtures/{_sass → _stylesheets}/stylesheet.scss +0 -2
- data/src/javascript.js +14 -0
- data/src/stylesheet.css +8 -2
- metadata +19 -13
- data/spec/fixtures/_css/.gitkeep +0 -0
- data/spec/fixtures/_css/_sv_custom.css +0 -3
- data/spec/fixtures/_css/bootstrap.css +0 -1
- data/spec/smallvictories_spec.rb +0 -100
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 305cf251d788e9e1d865ed14affc8df4eba8dba7
|
4
|
+
data.tar.gz: 3f5aa5da6a816bcfd06d7de06e405e3cf162b98d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07899a9f1e18d45b4d513e569d9956d9de9e27d9d4dda5a98a98347e606a4cd242c4aee1941a3631f4c3780e5b02d75704cad5b220c02eda978fb5a517cea1ac
|
7
|
+
data.tar.gz: ceb4600d91812a6b4ec7fbf2b61b8614b343cc7994466d95d3a738dd17128870520f2252b0813aa162992a5bf42a352f5dc6c931decdc3c69ab861de5b23bd48
|
data/README.md
CHANGED
@@ -2,19 +2,47 @@
|
|
2
2
|
|
3
3
|
A command line utility for building websites.
|
4
4
|
|
5
|
+
## What does it do?
|
6
|
+
|
7
|
+
The Small Victories gem packages Sass/CSS and JS/CoffeeScript files into a single Stylesheet and
|
8
|
+
Javascript file using [Sprockets](https://github.com/rails/sprockets).
|
9
|
+
|
5
10
|
## Installation
|
6
11
|
|
7
12
|
```
|
8
13
|
gem install smallvictories
|
9
14
|
```
|
10
15
|
|
16
|
+
## Config
|
17
|
+
|
18
|
+
Small Victories looks for a `_config.yml` file in the directory where `sv` is
|
19
|
+
run from.
|
20
|
+
|
21
|
+
+ `source`: Relative path to find and watch files for compiling and packaging.
|
22
|
+
+ `destination`: Relative path for where to save final files.
|
23
|
+
+ `stylesheets_dir`: Folder within source to compiles Sass and Css from.
|
24
|
+
+ `javascripts_dir`: Folder within source to package JS and CoffeeScript from.
|
25
|
+
+ `stylesheet`: Filename for packaged CSS file that is saved in destination.
|
26
|
+
+ `javascript`: Filename for packaged JS file that is saved in destination.
|
27
|
+
|
28
|
+
### Default Configuration
|
29
|
+
|
30
|
+
```
|
31
|
+
source: ''
|
32
|
+
destination: '_site'
|
33
|
+
stylesheets_dir: '_stylesheets'
|
34
|
+
javascripts_dir: '_javascripts'
|
35
|
+
stylesheet: '_sv_custom.css'
|
36
|
+
javascript: '_sv_custom.js'
|
37
|
+
```
|
38
|
+
|
11
39
|
## Commands
|
12
40
|
|
13
|
-
###
|
41
|
+
### Watch
|
14
42
|
|
15
|
-
|
43
|
+
Watch for changes and compile and package files.
|
16
44
|
|
17
|
-
Command: `sv
|
45
|
+
Command: `sv watch`
|
18
46
|
|
19
47
|
## Building Locally
|
20
48
|
|
data/bin/sv
CHANGED
@@ -7,7 +7,6 @@ def help
|
|
7
7
|
Usage: sv [COMMAND] [OPTIONS]
|
8
8
|
Commands:
|
9
9
|
watch Watch for changes and compile files
|
10
|
-
hello Puts Hello World!
|
11
10
|
help Prints this help document
|
12
11
|
version Prints the small victories gem version
|
13
12
|
Options:
|
@@ -17,13 +16,12 @@ def help
|
|
17
16
|
)
|
18
17
|
end
|
19
18
|
|
20
|
-
def hello
|
21
|
-
puts SmallVictories.hello
|
22
|
-
end
|
23
|
-
|
24
19
|
def watch
|
25
|
-
SmallVictories.
|
26
|
-
|
20
|
+
config = SmallVictories::Configuration.new
|
21
|
+
config.setup
|
22
|
+
compiler = SmallVictories::Compiler.new(config: config)
|
23
|
+
watcher = SmallVictories::Watcher.new(compiler: compiler)
|
24
|
+
watcher.watch
|
27
25
|
end
|
28
26
|
|
29
27
|
case ARGV[0]
|
data/lib/smallvictories.rb
CHANGED
@@ -1,189 +1,13 @@
|
|
1
|
+
libdir = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
3
|
+
|
1
4
|
require "smallvictories/version"
|
5
|
+
require "smallvictories/constants"
|
6
|
+
require "smallvictories/logger"
|
7
|
+
require "smallvictories/configuration"
|
8
|
+
require "smallvictories/compiler"
|
9
|
+
require "smallvictories/watcher"
|
2
10
|
require 'yaml'
|
3
11
|
require 'sassc'
|
4
12
|
require 'sprockets'
|
5
13
|
require 'listen'
|
6
|
-
|
7
|
-
module SmallVictories
|
8
|
-
extend self
|
9
|
-
DEFAULT_SASS_DIR = '_sass'
|
10
|
-
DEFAULT_STYLESHEET = '_sv_custom.css'
|
11
|
-
DEFAULT_CSS_DIR = '_css'
|
12
|
-
DEFAULT_SOURCE = ''
|
13
|
-
DEFAULT_DESTINATION = '_site'
|
14
|
-
ROOT = Dir.pwd
|
15
|
-
|
16
|
-
def hello
|
17
|
-
"Hello World!"
|
18
|
-
end
|
19
|
-
|
20
|
-
def config
|
21
|
-
if File.exists?('_config.yml')
|
22
|
-
YAML.load(File.read('_config.yml')) || {}
|
23
|
-
else
|
24
|
-
{}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def config_folder key
|
29
|
-
config[key.to_s].chomp("/").reverse.chomp("/").reverse if config.has_key?(key.to_s)
|
30
|
-
end
|
31
|
-
|
32
|
-
def source
|
33
|
-
config_folder(:source) || DEFAULT_SOURCE
|
34
|
-
end
|
35
|
-
|
36
|
-
def full_source_path
|
37
|
-
"#{ROOT}/#{source}"
|
38
|
-
end
|
39
|
-
|
40
|
-
def destination
|
41
|
-
config_folder(:destination) || DEFAULT_DESTINATION
|
42
|
-
end
|
43
|
-
|
44
|
-
def full_destination_path
|
45
|
-
"#{ROOT}/#{destination}/"
|
46
|
-
end
|
47
|
-
|
48
|
-
def css_dir
|
49
|
-
config_folder(:css_dir) || DEFAULT_CSS_DIR
|
50
|
-
end
|
51
|
-
|
52
|
-
def full_css_path
|
53
|
-
"#{full_source_path}/#{css_dir}/"
|
54
|
-
end
|
55
|
-
|
56
|
-
def stylesheet
|
57
|
-
config_folder(:stylesheet) || DEFAULT_STYLESHEET
|
58
|
-
end
|
59
|
-
|
60
|
-
def full_stylesheet_path
|
61
|
-
"#{full_css_path}/#{stylesheet}"
|
62
|
-
end
|
63
|
-
|
64
|
-
def sass_dir
|
65
|
-
config_folder(:sass_dir) || DEFAULT_SASS_DIR
|
66
|
-
end
|
67
|
-
|
68
|
-
def full_sass_path
|
69
|
-
"#{full_source_path}/#{sass_dir}/"
|
70
|
-
end
|
71
|
-
|
72
|
-
def full_sass_path
|
73
|
-
"#{full_source_path}/#{sass_dir}/"
|
74
|
-
end
|
75
|
-
|
76
|
-
def build_listener
|
77
|
-
Listen.to(
|
78
|
-
full_source_path,
|
79
|
-
force_polling: true,
|
80
|
-
&(listen_handler)
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
def listen_handler
|
85
|
-
proc do |modified, added, removed|
|
86
|
-
paths = modified + added + removed
|
87
|
-
extensions = paths.map{ |path| File.extname(path) }
|
88
|
-
extensions.each do |ext|
|
89
|
-
case ext
|
90
|
-
when '.scss'
|
91
|
-
puts sass
|
92
|
-
puts compile
|
93
|
-
when '.sass'
|
94
|
-
puts sass
|
95
|
-
puts compile
|
96
|
-
else
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def setup
|
103
|
-
setup_stylesheet
|
104
|
-
end
|
105
|
-
|
106
|
-
def watch
|
107
|
-
listener = build_listener
|
108
|
-
listener.start
|
109
|
-
puts "👀"
|
110
|
-
|
111
|
-
trap("INT") do
|
112
|
-
listener.stop
|
113
|
-
puts "🔥 🔥 🔥 Halting auto-regeneration."
|
114
|
-
exit 0
|
115
|
-
end
|
116
|
-
|
117
|
-
sleep_forever
|
118
|
-
rescue ThreadError
|
119
|
-
# Ctrl-C
|
120
|
-
end
|
121
|
-
|
122
|
-
def sass
|
123
|
-
errors, rendered = [], []
|
124
|
-
Dir.glob([full_sass_path.concat('*.scss'), full_sass_path.concat('*.sass')]) do |path|
|
125
|
-
begin
|
126
|
-
file_name = Pathname.new(path).basename.to_s.split('.').first
|
127
|
-
next if file_name =~ /^_/ # do not render partials
|
128
|
-
file = File.open(path).read
|
129
|
-
engine = SassC::Engine.new(file, { style: :compressed, load_paths: [full_sass_path] })
|
130
|
-
css = engine.render
|
131
|
-
output_file_name = file_name.concat('.css')
|
132
|
-
output_path = full_css_path.concat(output_file_name)
|
133
|
-
File.open(output_path, 'w') { |file| file.write(css) }
|
134
|
-
rendered << "👍 rendered #{destination.concat('/').concat(css_dir).concat('/').concat(output_file_name)}\n"
|
135
|
-
rescue => e
|
136
|
-
errors << "🔥 Sass 🔥 #{e}\n"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
rendered.join(', ') + errors.join(', ')
|
140
|
-
end
|
141
|
-
|
142
|
-
def compile
|
143
|
-
sprockets = Sprockets::Environment.new(ROOT) do |environment|
|
144
|
-
environment.js_compressor = :uglify
|
145
|
-
environment.css_compressor = :scss
|
146
|
-
end
|
147
|
-
|
148
|
-
sprockets.append_path(full_css_path)
|
149
|
-
|
150
|
-
errors, compiled = [], []
|
151
|
-
begin
|
152
|
-
[stylesheet].each do |bundle|
|
153
|
-
assets = sprockets.find_asset(bundle)
|
154
|
-
prefix, basename = assets.pathname.to_s.split('/')[-2..-1]
|
155
|
-
FileUtils.mkpath full_destination_path.concat(prefix)
|
156
|
-
|
157
|
-
assets.write_to(full_destination_path.concat(basename))
|
158
|
-
compiled << "👍 compiled #{destination.concat('/').concat(basename)}\n"
|
159
|
-
end
|
160
|
-
rescue => e
|
161
|
-
puts e.class
|
162
|
-
errors << "🔥 Compile 🔥 #{e}\n"
|
163
|
-
end
|
164
|
-
compiled.join(', ') + errors.join(', ')
|
165
|
-
end
|
166
|
-
|
167
|
-
def sleep_forever
|
168
|
-
loop { sleep 1000 }
|
169
|
-
end
|
170
|
-
|
171
|
-
private
|
172
|
-
|
173
|
-
def create_src_file source, destination
|
174
|
-
spec = Gem::Specification.find_by_name("smallvictories")
|
175
|
-
contents = File.open(spec.gem_dir.concat('/src/').concat(source)).read
|
176
|
-
File.open(destination, 'w') { |file| file.write(contents) }
|
177
|
-
end
|
178
|
-
|
179
|
-
def setup_stylesheet
|
180
|
-
setup_directory(full_css_path)
|
181
|
-
unless File.exists?(full_stylesheet_path)
|
182
|
-
create_src_file('stylesheet.css', full_stylesheet_path)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def setup_directory path
|
187
|
-
Dir.mkdir(path) unless File.exists?(path)
|
188
|
-
end
|
189
|
-
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SmallVictories
|
2
|
+
class Compiler
|
3
|
+
attr_accessor :config
|
4
|
+
|
5
|
+
def initialize attributes={}
|
6
|
+
self.config = attributes[:config]
|
7
|
+
end
|
8
|
+
|
9
|
+
def package
|
10
|
+
sprockets = Sprockets::Environment.new(ROOT) do |environment|
|
11
|
+
environment.js_compressor = :uglify
|
12
|
+
environment.css_compressor = :scss
|
13
|
+
end
|
14
|
+
|
15
|
+
sprockets.append_path(config.full_stylesheets_path)
|
16
|
+
sprockets.append_path(config.full_javascripts_path)
|
17
|
+
|
18
|
+
[config.stylesheet, config.javascript].each do |bundle|
|
19
|
+
begin
|
20
|
+
assets = sprockets.find_asset(bundle)
|
21
|
+
prefix, basename = assets.pathname.to_s.split('/')[-2..-1]
|
22
|
+
FileUtils.mkpath config.full_destination_path
|
23
|
+
assets.write_to "#{config.full_destination_path}#{basename}"
|
24
|
+
SmallVictories.logger.info "👍 packaged #{config.destination}/#{basename}"
|
25
|
+
rescue => e
|
26
|
+
SmallVictories.logger.error "🔥 🔥 🔥 \n#{e}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module SmallVictories
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :config
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.config = if File.exists?('_config.yml')
|
7
|
+
YAML.load(File.read('_config.yml')) || {}
|
8
|
+
else
|
9
|
+
{}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def config_folder key
|
14
|
+
config[key.to_s].chomp("/").reverse.chomp("/").reverse if config.has_key?(key.to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
def source
|
18
|
+
config_folder(:source) || DEFAULT_SOURCE
|
19
|
+
end
|
20
|
+
|
21
|
+
def full_source_path
|
22
|
+
"#{ROOT}/#{source}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def destination
|
26
|
+
config_folder(:destination) || DEFAULT_DESTINATION
|
27
|
+
end
|
28
|
+
|
29
|
+
def full_destination_path
|
30
|
+
"#{ROOT}/#{destination}/"
|
31
|
+
end
|
32
|
+
|
33
|
+
def stylesheets_dir
|
34
|
+
config_folder(:stylesheets_dir) || DEFAULT_STYLESHEET_DIR
|
35
|
+
end
|
36
|
+
|
37
|
+
def full_stylesheets_path
|
38
|
+
"#{full_source_path}/#{stylesheets_dir}/"
|
39
|
+
end
|
40
|
+
|
41
|
+
def javascripts_dir
|
42
|
+
config_folder(:javascripts_dir) || DEFAULT_JAVASCRIPT_DIR
|
43
|
+
end
|
44
|
+
|
45
|
+
def full_javascripts_path
|
46
|
+
"#{full_source_path}/#{javascripts_dir}/"
|
47
|
+
end
|
48
|
+
|
49
|
+
def javascript
|
50
|
+
config_folder(:javascript) || DEFAULT_JAVASCRIPT
|
51
|
+
end
|
52
|
+
|
53
|
+
def full_javascript_path
|
54
|
+
"#{full_javascripts_path}/#{javascript}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def stylesheet
|
58
|
+
config_folder(:stylesheet) || DEFAULT_STYLESHEET
|
59
|
+
end
|
60
|
+
|
61
|
+
def full_stylesheet_path
|
62
|
+
"#{full_stylesheets_path}/#{stylesheet}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def setup
|
66
|
+
setup_stylesheet
|
67
|
+
setup_javascript
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def create_src_file source, destination
|
73
|
+
spec = Gem::Specification.find_by_name("smallvictories")
|
74
|
+
contents = File.open("#{spec.gem_dir}/src/#{source}").read
|
75
|
+
File.open(destination, 'w') { |file| file.write(contents) }
|
76
|
+
end
|
77
|
+
|
78
|
+
def setup_directory path
|
79
|
+
Dir.mkdir(path) unless File.exists?(path)
|
80
|
+
end
|
81
|
+
|
82
|
+
def setup_stylesheet
|
83
|
+
setup_directory(full_stylesheets_path)
|
84
|
+
unless File.exists?(full_stylesheet_path)
|
85
|
+
create_src_file('stylesheet.css', full_stylesheet_path)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def setup_javascript
|
90
|
+
setup_directory(full_javascripts_path)
|
91
|
+
unless File.exists?(full_javascript_path)
|
92
|
+
create_src_file('javascript.js', full_javascript_path)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module SmallVictories
|
2
|
+
class Watcher
|
3
|
+
attr_accessor :compiler
|
4
|
+
|
5
|
+
def initialize attributes={}
|
6
|
+
self.compiler = attributes[:compiler]
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_listener
|
10
|
+
Listen.to(
|
11
|
+
compiler.config.full_source_path,
|
12
|
+
force_polling: true,
|
13
|
+
ignore: [/#{compiler.config.destination}/],
|
14
|
+
&(listen_handler)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def listen_handler
|
19
|
+
proc do |modified, added, removed|
|
20
|
+
paths = modified + added + removed
|
21
|
+
extensions = paths.map{ |path| File.extname(path) }
|
22
|
+
extensions.uniq.each do |ext|
|
23
|
+
case ext
|
24
|
+
when '.scss', '.sass', '.css', '.coffee', '.js'
|
25
|
+
compiler.package
|
26
|
+
else
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def watch
|
33
|
+
listener = build_listener
|
34
|
+
listener.start
|
35
|
+
SmallVictories.logger.info "👋"
|
36
|
+
SmallVictories.logger.info "👀"
|
37
|
+
|
38
|
+
trap("INT") do
|
39
|
+
listener.stop
|
40
|
+
SmallVictories.logger.info "✋ Halting auto-regeneration."
|
41
|
+
exit 0
|
42
|
+
end
|
43
|
+
|
44
|
+
sleep_forever
|
45
|
+
rescue ThreadError
|
46
|
+
# Ctrl-C
|
47
|
+
end
|
48
|
+
|
49
|
+
def sleep_forever
|
50
|
+
loop { sleep 1000 }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SmallVictories do
|
4
|
+
let(:compiler) { SmallVictories::Compiler.new(config: SmallVictories::Configuration.new) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
allow_any_instance_of(SmallVictories::Configuration).to receive(:source).and_return('./spec/fixtures')
|
8
|
+
allow_any_instance_of(SmallVictories::Configuration).to receive(:destination).and_return('./spec/fixtures')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#package' do
|
12
|
+
context 'with valid css' do
|
13
|
+
it 'packages the css file' do
|
14
|
+
compiler.package
|
15
|
+
expect(File.open('./fixtures/_sv_custom.css').read).to include 'html{background:white}.bootstrap{color:black}body div{background:red}'
|
16
|
+
FileUtils.rm('./fixtures/_sv_custom.css')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'invalid sass does not generate a file' do
|
21
|
+
allow_any_instance_of(SmallVictories::Configuration).to receive(:source).and_return('./spec/fixtures/invalid')
|
22
|
+
|
23
|
+
compiler.package
|
24
|
+
expect(File.exists?('./fixtures/_sv_custom.css')).to eq false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SmallVictories do
|
4
|
+
let(:configuration) { SmallVictories::Configuration.new }
|
5
|
+
|
6
|
+
context 'with no config file' do
|
7
|
+
it 'defaults to source directory' do
|
8
|
+
expect(configuration.source).to eq ''
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'defaults to destination directory' do
|
12
|
+
expect(configuration.destination).to eq '_site'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'defaults stylesheet file' do
|
16
|
+
expect(configuration.stylesheet).to eq '_sv_custom.css'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'defaults to _stylesheets directory' do
|
20
|
+
expect(configuration.stylesheets_dir).to eq '_stylesheets'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'defaults to _javascripts directory' do
|
24
|
+
expect(configuration.javascripts_dir).to eq '_javascripts'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with config file' do
|
29
|
+
before do
|
30
|
+
FileUtils.cp('fixtures/_config.yml', './')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'reads the source folder' do
|
34
|
+
expect(configuration.source).to eq 'my-source-folder'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'reads the destination folder' do
|
38
|
+
expect(configuration.destination).to eq 'my-site-folder'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'reads the _stylesheets directory' do
|
42
|
+
expect(configuration.stylesheets_dir).to eq 'my-sass-folder'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'reads the output css file' do
|
46
|
+
expect(configuration.stylesheet).to eq 'my-stylesheet.css'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'reads the _javascripts directory' do
|
50
|
+
expect(configuration.javascripts_dir).to eq 'my-js-folder'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'reads the output js file' do
|
54
|
+
expect(configuration.javascript).to eq 'my-javascript.js'
|
55
|
+
end
|
56
|
+
|
57
|
+
after do
|
58
|
+
FileUtils.rm('./_config.yml')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/fixtures/_config.yml
CHANGED
File without changes
|
data/src/javascript.js
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
// Small Victories Sprockets File
|
2
|
+
//
|
3
|
+
// For more details see
|
4
|
+
// https://github.com/rails/sprockets#the-directive-processor
|
5
|
+
// Any JavaScript/Coffee file within this directory
|
6
|
+
// can be referenced here using a relative path.
|
7
|
+
//
|
8
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
9
|
+
// compiled file.
|
10
|
+
//
|
11
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
12
|
+
// about supported directives.
|
13
|
+
//
|
14
|
+
//= require_tree .
|
data/src/stylesheet.css
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
/* Small Victories Sprockets File
|
2
2
|
*
|
3
|
-
*
|
4
|
-
*
|
3
|
+
* Any CSS and SCSS file within this directory and your sass directory
|
4
|
+
* can be referenced here using a relative path.
|
5
5
|
*
|
6
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
7
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
8
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
9
|
+
* file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
6
12
|
*= require_tree .
|
7
13
|
*/
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smallvictories
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Dijkstra
|
@@ -121,17 +121,23 @@ files:
|
|
121
121
|
- Rakefile
|
122
122
|
- bin/sv
|
123
123
|
- lib/smallvictories.rb
|
124
|
+
- lib/smallvictories/compiler.rb
|
125
|
+
- lib/smallvictories/configuration.rb
|
126
|
+
- lib/smallvictories/constants.rb
|
127
|
+
- lib/smallvictories/logger.rb
|
124
128
|
- lib/smallvictories/version.rb
|
129
|
+
- lib/smallvictories/watcher.rb
|
125
130
|
- smallvictories.gemspec
|
131
|
+
- spec/compiler_spec.rb
|
132
|
+
- spec/configuration_spec.rb
|
126
133
|
- spec/fixtures/_config.yml
|
127
|
-
- spec/fixtures/
|
128
|
-
- spec/fixtures/
|
129
|
-
- spec/fixtures/
|
130
|
-
- spec/fixtures/
|
131
|
-
- spec/fixtures/_sass/stylesheet.scss
|
134
|
+
- spec/fixtures/_stylesheets/_sv_custom.css
|
135
|
+
- spec/fixtures/_stylesheets/bootstrap.scss
|
136
|
+
- spec/fixtures/_stylesheets/extra.scss
|
137
|
+
- spec/fixtures/_stylesheets/stylesheet.scss
|
132
138
|
- spec/fixtures/invalid/_sass/stylesheet.scss
|
133
|
-
- spec/smallvictories_spec.rb
|
134
139
|
- spec/spec_helper.rb
|
140
|
+
- src/javascript.js
|
135
141
|
- src/stylesheet.css
|
136
142
|
homepage: https://github.com/xxix/smallvictories-gem
|
137
143
|
licenses:
|
@@ -158,12 +164,12 @@ signing_key:
|
|
158
164
|
specification_version: 4
|
159
165
|
summary: A command line utility for building websites.
|
160
166
|
test_files:
|
167
|
+
- spec/compiler_spec.rb
|
168
|
+
- spec/configuration_spec.rb
|
161
169
|
- spec/fixtures/_config.yml
|
162
|
-
- spec/fixtures/
|
163
|
-
- spec/fixtures/
|
164
|
-
- spec/fixtures/
|
165
|
-
- spec/fixtures/
|
166
|
-
- spec/fixtures/_sass/stylesheet.scss
|
170
|
+
- spec/fixtures/_stylesheets/_sv_custom.css
|
171
|
+
- spec/fixtures/_stylesheets/bootstrap.scss
|
172
|
+
- spec/fixtures/_stylesheets/extra.scss
|
173
|
+
- spec/fixtures/_stylesheets/stylesheet.scss
|
167
174
|
- spec/fixtures/invalid/_sass/stylesheet.scss
|
168
|
-
- spec/smallvictories_spec.rb
|
169
175
|
- spec/spec_helper.rb
|
data/spec/fixtures/_css/.gitkeep
DELETED
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
.bootstrap{color: black}
|
data/spec/smallvictories_spec.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
describe SmallVictories do
|
3
|
-
describe '#hello' do
|
4
|
-
it 'puts hello' do
|
5
|
-
expect(SmallVictories.hello).to eq "Hello World!"
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#config' do
|
10
|
-
context 'with no config file' do
|
11
|
-
it 'defaults to source directory' do
|
12
|
-
expect(SmallVictories.source).to eq ''
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'defaults to destination directory' do
|
16
|
-
expect(SmallVictories.destination).to eq '_site'
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'defaults stylesheet file' do
|
20
|
-
expect(SmallVictories.stylesheet).to eq '_sv_custom.css'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'defaults to _sass directory' do
|
24
|
-
expect(SmallVictories.sass_dir).to eq '_sass'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'with config file' do
|
29
|
-
before do
|
30
|
-
FileUtils.cp('fixtures/_config.yml', './')
|
31
|
-
end
|
32
|
-
|
33
|
-
after do
|
34
|
-
FileUtils.rm('./_config.yml')
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'reads the source folder' do
|
38
|
-
expect(SmallVictories.source).to eq 'my-source-folder'
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'reads the destination folder' do
|
42
|
-
expect(SmallVictories.destination).to eq 'my-site-folder'
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'reads the _sass directory' do
|
46
|
-
expect(SmallVictories.sass_dir).to eq 'my-sass-folder'
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'reads the output css file' do
|
50
|
-
expect(SmallVictories.stylesheet).to eq 'my-stylesheet.css'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe '#sass' do
|
56
|
-
before do
|
57
|
-
allow(SmallVictories).to receive(:source).and_return('./spec/fixtures')
|
58
|
-
allow(SmallVictories).to receive(:destination).and_return('./spec/fixtures')
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'with valid sass' do
|
62
|
-
it 'renders the css from a scss file' do
|
63
|
-
expect(SmallVictories.sass).to include "rendered ./spec/fixtures/_css/stylesheet.css"
|
64
|
-
expect(File.open('./fixtures/_css/stylesheet.css').read).to include 'html{background:white}body div{background:red}'
|
65
|
-
end
|
66
|
-
|
67
|
-
after do
|
68
|
-
FileUtils.rm('./fixtures/_css/stylesheet.css')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'with invalid sass' do
|
73
|
-
before do
|
74
|
-
allow(SmallVictories).to receive(:source).and_return('./spec/fixtures/invalid')
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'returns the error' do
|
78
|
-
expect(SmallVictories.sass).to include "Error"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe '#compile' do
|
84
|
-
before do
|
85
|
-
allow(SmallVictories).to receive(:source).and_return('./spec/fixtures')
|
86
|
-
allow(SmallVictories).to receive(:destination).and_return('./spec/fixtures')
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'with valid css' do
|
90
|
-
it 'compiles the css file' do
|
91
|
-
expect(SmallVictories.compile).to include "compiled ./spec/fixtures/_sv_custom.css"
|
92
|
-
expect(File.open('fixtures/_sv_custom.css').read).to include '.bootstrap{color:black}'
|
93
|
-
end
|
94
|
-
|
95
|
-
after do
|
96
|
-
FileUtils.rm('fixtures/_sv_custom.css')
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|