smallvictories 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +69 -10
  3. data/bin/sv +28 -8
  4. data/lib/smallvictories.rb +1 -4
  5. data/lib/smallvictories/builder.rb +73 -0
  6. data/lib/smallvictories/compiler.rb +82 -11
  7. data/lib/smallvictories/configuration.rb +11 -56
  8. data/lib/smallvictories/constants.rb +3 -2
  9. data/lib/smallvictories/logger.rb +10 -0
  10. data/lib/smallvictories/version.rb +1 -1
  11. data/lib/smallvictories/watcher.rb +11 -5
  12. data/smallvictories.gemspec +6 -2
  13. data/spec/builder_spec.rb +21 -0
  14. data/spec/compiler_spec.rb +74 -8
  15. data/spec/configuration_spec.rb +15 -15
  16. data/spec/fixtures/_sv_custom.css +4 -0
  17. data/spec/fixtures/destination/.gitkeep +0 -0
  18. data/spec/fixtures/invalid/_layout.liquid +3 -0
  19. data/spec/fixtures/invalid/index.html +2 -0
  20. data/spec/fixtures/{_config.yml → source/_config.yml} +2 -2
  21. data/spec/fixtures/source/_includes/_snippet.liquid +1 -0
  22. data/spec/fixtures/source/_javascripts/scripts.coffee +1 -0
  23. data/spec/fixtures/source/_javascripts/scripts.js +1 -0
  24. data/spec/fixtures/source/_layout.liquid +3 -0
  25. data/spec/fixtures/{_stylesheets → source/_stylesheets}/bootstrap.scss +1 -0
  26. data/spec/fixtures/{_stylesheets → source/_stylesheets}/extra.scss +0 -0
  27. data/spec/fixtures/{_stylesheets → source/_stylesheets}/stylesheet.scss +0 -0
  28. data/spec/fixtures/source/_sv_custom.css +19 -0
  29. data/spec/fixtures/source/_sv_custom.js +14 -0
  30. data/spec/fixtures/source/index.html +2 -0
  31. data/spec/spec_helper.rb +8 -0
  32. data/src/config.yml +6 -0
  33. data/src/head.liquid +20 -0
  34. data/src/index.liquid +1 -0
  35. data/src/layout.liquid +8 -0
  36. data/src/stylesheet.css +3 -1
  37. metadata +93 -22
  38. data/spec/fixtures/_stylesheets/_sv_custom.css +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 305cf251d788e9e1d865ed14affc8df4eba8dba7
4
- data.tar.gz: 3f5aa5da6a816bcfd06d7de06e405e3cf162b98d
3
+ metadata.gz: 7ec4b9886a3ede16fc3d173852d14e53fd762a38
4
+ data.tar.gz: 925234d3af8439d6f45381a4701f7c0331192ea9
5
5
  SHA512:
6
- metadata.gz: 07899a9f1e18d45b4d513e569d9956d9de9e27d9d4dda5a98a98347e606a4cd242c4aee1941a3631f4c3780e5b02d75704cad5b220c02eda978fb5a517cea1ac
7
- data.tar.gz: ceb4600d91812a6b4ec7fbf2b61b8614b343cc7994466d95d3a738dd17128870520f2252b0813aa162992a5bf42a352f5dc6c931decdc3c69ab861de5b23bd48
6
+ metadata.gz: 43e26f3eec4ca433f45e629dddb541e1a39cbfeadb87187d1c3628b886d92260018c6f0b15d8077d9bad0886b832b1d6a94476b46163cd02c62120ed7b83b23b
7
+ data.tar.gz: a91f54da2046b2cff5dff279ad4c644354e801a2ff4cf0e900c060186fd9feadab22adb3ebfb4519cdba4b0d90caf459b4a02a546858d6252806b01c62de9ba2
data/README.md CHANGED
@@ -4,8 +4,44 @@ A command line utility for building websites.
4
4
 
5
5
  ## What does it do?
6
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).
7
+ The Small Victories gem compiles Sass/CSS and JS/CoffeeScript files into a single Stylesheet and
8
+ Javascript file and renders HTML and Liquid files into a destination folder.
9
+
10
+ [Sprockets](https://github.com/rails/sprockets) looks for main Sass/CSS and JS/CoffeeScript files and compiles
11
+ multiple Sass/CSS and JS/CoffeeScript files into a single CSS and JS file.
12
+
13
+ You can structure your folder however you want, Sprockets will find the files
14
+ you reference and compile them in the order you require them.
15
+
16
+ [Liquid](https://github.com/Shopify/liquid/) looks for a single layout file and
17
+ renders all HTML and Liquid files through this, including snippets from the
18
+ includes folder.
19
+
20
+ You don't have to use a layout file if you don't want to, the files will still
21
+ be copied over to the destination folder.
22
+
23
+ ### Basic Folder Structure
24
+
25
+ ```text
26
+ project
27
+ ├── _includes
28
+ ├── _layout.liquid
29
+ ├── _sv_custom.css
30
+ ├── _sv_custom.js
31
+
32
+ └── index.html
33
+ ```
34
+
35
+ ## How does it work with Small Victories?
36
+
37
+ This gem allows you to build a site using the tools you're used to and compile a
38
+ version directly into a Small Victories folder.
39
+
40
+ To do this, create a `_config.yml` file and set the destination to your Small
41
+ Victories site folder e.g. `~/Dropbox/Small Victories/liberal coyote`.
42
+
43
+ Now when you watch or build your site it will output the files into your Dropbox
44
+ folder, which in turn will trigger Small Victories to rebuild your site.
9
45
 
10
46
  ## Installation
11
47
 
@@ -18,29 +54,52 @@ gem install smallvictories
18
54
  Small Victories looks for a `_config.yml` file in the directory where `sv` is
19
55
  run from.
20
56
 
21
- + `source`: Relative path to find and watch files for compiling and packaging.
57
+ + `source`: Relative path to find and watch files for compiling and compiling.
22
58
  + `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.
59
+ + `stylesheet`: Main stylesheet (Sass or CSS) to be compiled into destination.
60
+ + `javascript`: Main javascript file (JS or CoffeeScript) to be compiled into destination.
61
+ + `layout`: Liquid layout file to render all other html and liquid files through.
62
+ + `includes`: Directory where liquid rendered should expect to find snippets.
27
63
 
28
64
  ### Default Configuration
29
65
 
30
66
  ```
31
67
  source: ''
32
68
  destination: '_site'
33
- stylesheets_dir: '_stylesheets'
34
- javascripts_dir: '_javascripts'
35
69
  stylesheet: '_sv_custom.css'
36
70
  javascript: '_sv_custom.js'
71
+ layout: '_layout.liquid'
72
+ includes: '_includes'
37
73
  ```
38
74
 
39
75
  ## Commands
40
76
 
77
+ ### Bootstrap
78
+
79
+ Sets up default files in a folder.
80
+
81
+
82
+ Pass no name to setup in the current folder:
83
+
84
+ Command: `sv bootstrap`
85
+
86
+ Pass a folder name to setup in a new/existing folder:
87
+
88
+ Command: `sv bootstrap my-folder`
89
+
90
+
91
+ ### Compile
92
+
93
+ Compile files.
94
+
95
+ Renders Sass/CSS, JavaScript/CoffeeScript, HTML/Liquid in the destination
96
+ folder.
97
+
98
+ Command: `sv compile`
99
+
41
100
  ### Watch
42
101
 
43
- Watch for changes and compile and package files.
102
+ Watch for changes and compile files.
44
103
 
45
104
  Command: `sv watch`
46
105
 
data/bin/sv CHANGED
@@ -5,20 +5,38 @@ require 'smallvictories'
5
5
  def help
6
6
  %Q(
7
7
  Usage: sv [COMMAND] [OPTIONS]
8
+
8
9
  Commands:
9
- watch Watch for changes and compile files
10
- help Prints this help document
11
- version Prints the small victories gem version
10
+ bootstrap, bootstrap FOLDER Setup folder with default files
11
+ compile Compile files
12
+ watch Watch for changes and compile files
13
+ help Prints this help document
14
+ version Prints the small victories gem version
15
+
12
16
  Options:
13
- -h, --help Prints this help document
14
- -v, --version Prints the siteleaf gem version
17
+ -h, --help Prints this help document
18
+ -v, --version Prints the siteleaf gem version
19
+
15
20
  See https://github.com/xxix/smallvictories-gem for additional documentation.
16
21
  )
17
22
  end
18
23
 
24
+ def bootstrap folder=nil
25
+ config = SmallVictories::Configuration.new
26
+ builder = SmallVictories::Builder.new(config: config)
27
+ builder.setup folder
28
+ end
29
+
30
+ def compile
31
+ config = SmallVictories::Configuration.new
32
+ compiler = SmallVictories::Compiler.new(config: config)
33
+ compiler.compile_css
34
+ compiler.compile_js
35
+ compiler.compile_html
36
+ end
37
+
19
38
  def watch
20
39
  config = SmallVictories::Configuration.new
21
- config.setup
22
40
  compiler = SmallVictories::Compiler.new(config: config)
23
41
  watcher = SmallVictories::Watcher.new(compiler: compiler)
24
42
  watcher.watch
@@ -29,8 +47,10 @@ when '-v', '--version', 'version'
29
47
  puts SmallVictories::VERSION
30
48
  when '-h', '--help', 'help'
31
49
  puts help
32
- when 'hello'
33
- hello
50
+ when 'bootstrap'
51
+ bootstrap ARGV[1]
52
+ when 'compile'
53
+ compile
34
54
  when 'watch'
35
55
  watch
36
56
  else
@@ -5,9 +5,6 @@ require "smallvictories/version"
5
5
  require "smallvictories/constants"
6
6
  require "smallvictories/logger"
7
7
  require "smallvictories/configuration"
8
+ require "smallvictories/builder"
8
9
  require "smallvictories/compiler"
9
10
  require "smallvictories/watcher"
10
- require 'yaml'
11
- require 'sassc'
12
- require 'sprockets'
13
- require 'listen'
@@ -0,0 +1,73 @@
1
+ require 'yaml'
2
+
3
+ module SmallVictories
4
+ class Builder
5
+ attr_accessor :config
6
+ attr_accessor :folder
7
+
8
+ def initialize attributes={}
9
+ self.config = attributes[:config]
10
+ end
11
+
12
+ def setup folder=nil
13
+ self.folder = "#{folder.chomp("/").reverse.chomp("/").reverse}/" if folder
14
+ setup_directory folder_path
15
+ setup_config
16
+ setup_stylesheet
17
+ setup_javascript
18
+ setup_html
19
+ end
20
+
21
+ def folder_path
22
+ "#{config.full_source_path}#{folder}"
23
+ end
24
+
25
+ private
26
+
27
+ def src_directory
28
+ spec = Gem::Specification.find_by_name("smallvictories")
29
+ "#{spec.gem_dir}/src/"
30
+ end
31
+
32
+ def create_src_file source, destination
33
+ unless File.exists?(destination)
34
+ contents = File.open("#{src_directory}#{source}").read
35
+ File.open(destination, 'w') { |file| file.write(contents) }
36
+ SmallVictories.logger.info "created #{destination}"
37
+ end
38
+ end
39
+
40
+ def setup_directory path
41
+ unless File.exists?(path)
42
+ Dir.mkdir(path)
43
+ SmallVictories.logger.info "created #{path}"
44
+ end
45
+ end
46
+
47
+ def setup_config
48
+ d = YAML::load_file("#{src_directory}config.yml")
49
+ d['source'] = DEFAULT_SOURCE
50
+ d['destination'] = DEFAULT_DESTINATION
51
+ d['stylesheet'] = DEFAULT_STYLESHEET
52
+ d['javascript'] = DEFAULT_JAVASCRIPT
53
+ d['layout'] = DEFAULT_LAYOUT
54
+ d['includes'] = DEFAULT_INCLUDES
55
+ File.open("#{folder_path}#{CONFIG_FILE}", 'w') {|f| f.write d.to_yaml }
56
+ end
57
+
58
+ def setup_stylesheet
59
+ create_src_file('stylesheet.css', "#{folder_path}#{config.stylesheet}")
60
+ end
61
+
62
+ def setup_javascript
63
+ create_src_file('javascript.js', "#{folder_path}#{config.javascript}")
64
+ end
65
+
66
+ def setup_html
67
+ setup_directory("#{folder_path}#{config.includes}")
68
+ create_src_file('layout.liquid', "#{folder_path}#{config.layout}")
69
+ create_src_file('index.liquid', "#{folder_path}/index.liquid")
70
+ create_src_file('head.liquid', "#{folder_path}#{config.includes}/_head.liquid")
71
+ end
72
+ end
73
+ end
@@ -1,3 +1,7 @@
1
+ require 'sprockets'
2
+ require 'autoprefixer-rails'
3
+ require 'liquid'
4
+
1
5
  module SmallVictories
2
6
  class Compiler
3
7
  attr_accessor :config
@@ -6,26 +10,93 @@ module SmallVictories
6
10
  self.config = attributes[:config]
7
11
  end
8
12
 
9
- def package
13
+ def compile_css
14
+ package [config.stylesheet]
15
+ prefix_css
16
+ end
17
+
18
+ def compile_js
19
+ package [config.javascript]
20
+ end
21
+
22
+ def compile_html
23
+ liquid
24
+ end
25
+
26
+ def liquid
27
+ begin
28
+ Liquid::Template.file_system = Liquid::LocalFileSystem.new("#{config.full_source_path}/#{config.includes}")
29
+ layout_path = "#{config.full_source_path}/#{config.layout}"
30
+ if File.exists?(layout_path)
31
+ layout_file = File.open(layout_path).read
32
+ layout = Liquid::Template.parse(layout_file)
33
+ end
34
+ rescue => e
35
+ SmallVictories.logger.error "Liquid Error\n#{e}"
36
+ return
37
+ end
38
+
39
+ Dir.glob(["#{config.full_source_path}/*.html", "#{config.full_source_path}/*.liquid"]) do |path|
40
+ begin
41
+ file_name = Pathname.new(path).basename.to_s.split('.').first
42
+ next if file_name =~ /^_/ # do not render partials
43
+
44
+ file = File.open(path).read
45
+ liquid = Liquid::Template.parse(file)
46
+ content = liquid.render('config' => { 'stylesheet' => config.stylesheet, 'javascript' => config.javascript })
47
+ output_file_name = file_name.concat('.html')
48
+ output_path = "#{config.full_destination_path}#{output_file_name}"
49
+ if layout
50
+ html = layout.render('content_for_layout' => liquid.render, 'config' => { 'stylesheet' => config.stylesheet, 'javascript' => config.javascript })
51
+ else
52
+ html = liquid.render('config' => { 'stylesheet' => config.stylesheet, 'javascript' => config.javascript })
53
+ end
54
+ File.open("#{config.full_destination_path}#{output_file_name}", 'w') { |file| file.write(html) }
55
+ SmallVictories.logger.info "compiled #{config.destination}/#{output_file_name}"
56
+ rescue => e
57
+ SmallVictories.logger.error "#{path}\n#{e}"
58
+ end
59
+ end
60
+ end
61
+ def package bundles=[config.stylesheet, config.javascript]
10
62
  sprockets = Sprockets::Environment.new(ROOT) do |environment|
11
63
  environment.js_compressor = :uglify
12
64
  environment.css_compressor = :scss
13
65
  end
14
66
 
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|
67
+ sprockets.append_path(config.full_source_path)
68
+ bundles.each do |bundle|
19
69
  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}"
70
+ if assets = sprockets.find_asset(bundle)
71
+ prefix, basename = assets.pathname.to_s.split('/')[-2..-1]
72
+ FileUtils.mkpath config.full_destination_path
73
+ assets.write_to "#{config.full_destination_path}#{basename}"
74
+ SmallVictories.logger.info "compiled #{config.destination}/#{basename}"
75
+ end
25
76
  rescue => e
26
- SmallVictories.logger.error "🔥 🔥 🔥 \n#{e}"
77
+ SmallVictories.logger.error "#{bundle}\n#{e}"
27
78
  end
28
79
  end
29
80
  end
81
+
82
+ def prefix_css
83
+ begin
84
+ path = "#{config.full_destination_path}#{config.stylesheet}"
85
+ css = File.open(path).read
86
+ prefixed = AutoprefixerRails.process(css, browsers: ['last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'], cascade: false)
87
+ File.open(path, 'w') { |file| file.write(prefixed.css) }
88
+
89
+ sprockets = Sprockets::Environment.new(ROOT) do |environment|
90
+ environment.css_compressor = :scss
91
+ end
92
+ sprockets.append_path(config.full_destination_path)
93
+ assets = sprockets.find_asset(config.stylesheet)
94
+ assets.write_to "#{config.full_destination_path}#{config.stylesheet}"
95
+
96
+ SmallVictories.logger.info "prefixed #{config.destination}/#{config.stylesheet}"
97
+ rescue => e
98
+ SmallVictories.logger.error "#{path}\n#{e}"
99
+ end
100
+ end
30
101
  end
31
102
  end
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  module SmallVictories
2
4
  class Configuration
3
5
  attr_accessor :config
@@ -10,12 +12,12 @@ module SmallVictories
10
12
  end
11
13
  end
12
14
 
13
- def config_folder key
15
+ def config_file key
14
16
  config[key.to_s].chomp("/").reverse.chomp("/").reverse if config.has_key?(key.to_s)
15
17
  end
16
18
 
17
19
  def source
18
- config_folder(:source) || DEFAULT_SOURCE
20
+ config_file(:source) || DEFAULT_SOURCE
19
21
  end
20
22
 
21
23
  def full_source_path
@@ -23,74 +25,27 @@ module SmallVictories
23
25
  end
24
26
 
25
27
  def destination
26
- config_folder(:destination) || DEFAULT_DESTINATION
28
+ config_file(:destination) || DEFAULT_DESTINATION
27
29
  end
28
30
 
29
31
  def full_destination_path
30
32
  "#{ROOT}/#{destination}/"
31
33
  end
32
34
 
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
35
  def javascript
50
- config_folder(:javascript) || DEFAULT_JAVASCRIPT
51
- end
52
-
53
- def full_javascript_path
54
- "#{full_javascripts_path}/#{javascript}"
36
+ config_file(:javascript) || DEFAULT_JAVASCRIPT
55
37
  end
56
38
 
57
39
  def stylesheet
58
- config_folder(:stylesheet) || DEFAULT_STYLESHEET
40
+ config_file(:stylesheet) || DEFAULT_STYLESHEET
59
41
  end
60
42
 
61
- def full_stylesheet_path
62
- "#{full_stylesheets_path}/#{stylesheet}"
43
+ def layout
44
+ config_file(:layout) || DEFAULT_LAYOUT
63
45
  end
64
46
 
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
47
+ def includes
48
+ config_file(:includes) || DEFAULT_INCLUDES
94
49
  end
95
50
  end
96
51
  end
@@ -1,9 +1,10 @@
1
1
  module SmallVictories
2
+ CONFIG_FILE = '_config.yml'
2
3
  DEFAULT_SOURCE = ''
3
4
  DEFAULT_DESTINATION = '_site'
4
5
  DEFAULT_STYLESHEET = '_sv_custom.css'
5
- DEFAULT_STYLESHEET_DIR = '_stylesheets'
6
6
  DEFAULT_JAVASCRIPT = '_sv_custom.js'
7
- DEFAULT_JAVASCRIPT_DIR = '_javascripts'
7
+ DEFAULT_LAYOUT = '_layout.liquid'
8
+ DEFAULT_INCLUDES = '_includes'
8
9
  ROOT = Dir.pwd
9
10
  end
@@ -5,6 +5,16 @@ module SmallVictories
5
5
  def logger
6
6
  @logger ||= Logger.new($stdout).tap do |log|
7
7
  log.progname = self.name
8
+ log.formatter = proc do |severity, datetime, progname, msg|
9
+ string = "Small Victories: "
10
+ case severity
11
+ when 'INFO'
12
+ string.concat("👍 ")
13
+ when 'ERROR'
14
+ string.concat("🔥 ")
15
+ end
16
+ string.concat("#{msg}\n")
17
+ end
8
18
  end
9
19
  end
10
20
  end
@@ -1,3 +1,3 @@
1
1
  module SmallVictories
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'listen'
2
+
1
3
  module SmallVictories
2
4
  class Watcher
3
5
  attr_accessor :compiler
@@ -21,8 +23,12 @@ module SmallVictories
21
23
  extensions = paths.map{ |path| File.extname(path) }
22
24
  extensions.uniq.each do |ext|
23
25
  case ext
24
- when '.scss', '.sass', '.css', '.coffee', '.js'
25
- compiler.package
26
+ when '.scss', '.sass', '.css'
27
+ compiler.compile_css
28
+ when '.coffee', '.js'
29
+ compiler.compile_js
30
+ when '.liquid', '.html'
31
+ compiler.compile_html
26
32
  else
27
33
  end
28
34
  end
@@ -32,12 +38,12 @@ module SmallVictories
32
38
  def watch
33
39
  listener = build_listener
34
40
  listener.start
35
- SmallVictories.logger.info "👋"
36
- SmallVictories.logger.info "👀"
41
+ SmallVictories.logger.debug "👋"
42
+ SmallVictories.logger.debug "👀"
37
43
 
38
44
  trap("INT") do
39
45
  listener.stop
40
- SmallVictories.logger.info "✋ Halting auto-regeneration."
46
+ SmallVictories.logger.warn "✋ Halting auto-regeneration."
41
47
  exit 0
42
48
  end
43
49
 
@@ -19,8 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency 'sassc', "~> 1.6"
22
- spec.add_runtime_dependency 'sprockets', '~> 3.4', '>= 3.4.0'
23
- spec.add_runtime_dependency 'listen', '~> 3.0', '>= 3.0.3'
22
+ spec.add_runtime_dependency 'sprockets', '~> 3.4'
23
+ spec.add_runtime_dependency 'listen', '~> 3.0'
24
+ spec.add_runtime_dependency 'uglifier', '~> 2.7'
25
+ spec.add_runtime_dependency 'coffee-script', '~> 2.4'
26
+ spec.add_runtime_dependency 'liquid', "~> 3.0"
27
+ spec.add_runtime_dependency 'autoprefixer-rails', "~> 6.0"
24
28
 
25
29
  spec.add_development_dependency "bundler", "~> 1.7"
26
30
  spec.add_development_dependency "rake", "~> 10.0"
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe SmallVictories do
4
+ let(:builder) { SmallVictories::Builder.new(config: SmallVictories::Configuration.new) }
5
+
6
+ context 'with no folder' do
7
+ it 'sets up default files' do
8
+ builder.setup 'spec/fixtures/new'
9
+ expect(File.exists?('fixtures/new/_config.yml')).to eq true
10
+ expect(File.exists?('fixtures/new/_layout.liquid')).to eq true
11
+ expect(File.exists?('fixtures/new/index.liquid')).to eq true
12
+ expect(File.exists?('fixtures/new/_includes/_head.liquid')).to eq true
13
+ expect(File.exists?('fixtures/new/_sv_custom.js')).to eq true
14
+ expect(File.exists?('fixtures/new/_sv_custom.css')).to eq true
15
+ end
16
+
17
+ after do
18
+ %w(fixtures/new/_config.yml fixtures/new/index.liquid fixtures/new/_sv_custom.css fixtures/new/_sv_custom.js fixtures/new/_includes/_head.liquid fixtures/new/_layout.liquid).each { |path| clean_file(path) }
19
+ end
20
+ end
21
+ end
@@ -1,27 +1,93 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SmallVictories do
4
+ let(:destination_css) { './fixtures/destination/_sv_custom.css' }
5
+ let(:destination_js) { './fixtures/destination/_sv_custom.js' }
6
+ let(:destination_html) { './fixtures/destination/index.html' }
4
7
  let(:compiler) { SmallVictories::Compiler.new(config: SmallVictories::Configuration.new) }
5
8
 
6
9
  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')
10
+ allow_any_instance_of(SmallVictories::Configuration).to receive(:source).and_return('./spec/fixtures/source')
11
+ allow_any_instance_of(SmallVictories::Configuration).to receive(:destination).and_return('./spec/fixtures/destination')
9
12
  end
10
13
 
11
14
  describe '#package' do
12
15
  context 'with valid css' do
13
- it 'packages the css file' do
16
+ it 'package the css file' do
14
17
  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')
18
+ expect(File.open(destination_css).read).to include '.bootstrap{color:black;box-sizing:content-box}html{background:white}body div{background:red}p{font-size:30px}'
17
19
  end
18
20
  end
19
21
 
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
+ context 'with valid js' do
23
+ it 'package the js file' do
24
+ compiler.package
25
+ expect(File.open(destination_js).read).to include '(function(){alert("hi")}).call(this),console.log("hi");'
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#prefix' do
31
+ before do
32
+ FileUtils.cp('fixtures/_sv_custom.css', 'fixtures/destination')
33
+ end
34
+
35
+ it 'prefixes the css file' do
36
+ compiler.prefix_css
37
+ expect(File.open(destination_css).read).to include 'html{background:red;-webkit-box-sizing:content-box;box-sizing:content-box}'
38
+ end
39
+ end
40
+
41
+ describe '#compile_css' do
42
+ it 'compules and prefixes the css file' do
43
+ compiler.compile_css
44
+ expect(File.open(destination_css).read).to include '.bootstrap{color:black;-webkit-box-sizing:content-box;box-sizing:content-box}html{background:white}body div{background:red}p{font-size:30px}'
45
+ end
46
+ end
47
+
48
+ describe '#compile_js' do
49
+ it 'compules the js file' do
50
+ compiler.compile_js
51
+ expect(File.open(destination_js).read).to include '(function(){alert("hi")}).call(this),console.log("hi");'
52
+ end
53
+ end
22
54
 
55
+ describe '#compile_html' do
56
+ it 'compiles the liquid files' do
57
+ compiler.compile_html
58
+ expect(File.open(destination_html).read).to include "<html>\n<h1>Index</h1>\n<p>My snippet</p>\n\n\n</html>"
59
+ end
60
+
61
+ context 'with no layout' do
62
+ before do
63
+ allow_any_instance_of(SmallVictories::Configuration).to receive(:layout).and_return('no-file-here')
64
+ end
65
+
66
+ it 'compiles the liquid files' do
67
+ compiler.compile_html
68
+ expect(File.open(destination_html).read).to include "<h1>Index</h1>\n<p>My snippet</p>\n\n"
69
+ end
70
+ end
71
+ end
72
+
73
+ context 'with invalid files' do
74
+ before do
75
+ allow_any_instance_of(SmallVictories::Configuration).to receive(:source).and_return('./spec/fixtures/invalid')
76
+ end
77
+
78
+ it 'does not generate a css file' do
23
79
  compiler.package
24
- expect(File.exists?('./fixtures/_sv_custom.css')).to eq false
80
+ expect(File.exists?(destination_css)).to eq false
81
+ end
82
+
83
+ it 'does not package the js file' do
84
+ compiler.package
85
+ expect(File.exists?(destination_js)).to eq false
86
+ end
87
+
88
+ it 'shows the error in html' do
89
+ compiler.compile_html
90
+ expect(File.open(destination_html).read).to include "<html>\n<h1>Index</h1>\nLiquid error: No such template 'snippet'\n\n</html>"
25
91
  end
26
92
  end
27
93
  end
@@ -16,18 +16,22 @@ describe SmallVictories do
16
16
  expect(configuration.stylesheet).to eq '_sv_custom.css'
17
17
  end
18
18
 
19
- it 'defaults to _stylesheets directory' do
20
- expect(configuration.stylesheets_dir).to eq '_stylesheets'
19
+ it 'defaults javascript file' do
20
+ expect(configuration.javascript).to eq '_sv_custom.js'
21
21
  end
22
22
 
23
- it 'defaults to _javascripts directory' do
24
- expect(configuration.javascripts_dir).to eq '_javascripts'
23
+ it 'defaults layout file' do
24
+ expect(configuration.layout).to eq '_layout.liquid'
25
+ end
26
+
27
+ it 'defaults includes folder' do
28
+ expect(configuration.includes).to eq '_includes'
25
29
  end
26
30
  end
27
31
 
28
32
  context 'with config file' do
29
33
  before do
30
- FileUtils.cp('fixtures/_config.yml', './')
34
+ FileUtils.cp('fixtures/source/_config.yml', './')
31
35
  end
32
36
 
33
37
  it 'reads the source folder' do
@@ -38,24 +42,20 @@ describe SmallVictories do
38
42
  expect(configuration.destination).to eq 'my-site-folder'
39
43
  end
40
44
 
41
- it 'reads the _stylesheets directory' do
42
- expect(configuration.stylesheets_dir).to eq 'my-sass-folder'
43
- end
44
-
45
45
  it 'reads the output css file' do
46
46
  expect(configuration.stylesheet).to eq 'my-stylesheet.css'
47
47
  end
48
48
 
49
- it 'reads the _javascripts directory' do
50
- expect(configuration.javascripts_dir).to eq 'my-js-folder'
51
- end
52
-
53
49
  it 'reads the output js file' do
54
50
  expect(configuration.javascript).to eq 'my-javascript.js'
55
51
  end
56
52
 
57
- after do
58
- FileUtils.rm('./_config.yml')
53
+ it 'reads layout file' do
54
+ expect(configuration.layout).to eq '_my-template.liquid'
55
+ end
56
+
57
+ it 'reads includes folder' do
58
+ expect(configuration.includes).to eq 'snippets'
59
59
  end
60
60
  end
61
61
  end
@@ -0,0 +1,4 @@
1
+ html {
2
+ background: red;
3
+ box-sizing: content-box;
4
+ }
File without changes
@@ -0,0 +1,3 @@
1
+ <html>
2
+ {{content_for_layout}}
3
+ </html>
@@ -0,0 +1,2 @@
1
+ <h1>Index</h1>
2
+ {% include 'snippet' %}
@@ -1,6 +1,6 @@
1
1
  source: '/my-source-folder/'
2
2
  destination: 'my-site-folder/'
3
- stylesheets_dir: 'my-sass-folder/'
4
- javascripts_dir: 'my-js-folder/'
5
3
  stylesheet: 'my-stylesheet.css'
6
4
  javascript: 'my-javascript.js'
5
+ layout: '_my-template.liquid'
6
+ includes: 'snippets'
@@ -0,0 +1 @@
1
+ <p>My snippet</p>
@@ -0,0 +1 @@
1
+ console.log('hi');
@@ -0,0 +1,3 @@
1
+ <html>
2
+ {{content_for_layout}}
3
+ </html>
@@ -1,3 +1,4 @@
1
1
  .bootstrap {
2
2
  color: black;
3
+ box-sizing: content-box;
3
4
  }
@@ -0,0 +1,19 @@
1
+ /* Small Victories Sprockets File
2
+ *
3
+ * Any CSS and SCSS file within this directory and your sass directory
4
+ * can be referenced here using a relative path.
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
+ * Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
12
+ * about supported directives.
13
+ *
14
+ *= require_tree .
15
+ */
16
+
17
+ p {
18
+ font-size: 30px;
19
+ }
@@ -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 .
@@ -0,0 +1,2 @@
1
+ <h1>Index</h1>
2
+ {% include 'snippet' %}
@@ -7,4 +7,12 @@ RSpec.configure do |config|
7
7
  config.before do
8
8
  FileUtils.cd File.dirname(__FILE__)
9
9
  end
10
+
11
+ config.after do
12
+ %w(./fixtures/destination/_sv_custom.css ./fixtures/destination/_sv_custom.js ./fixtures/destination/index.html ./_config.yml).each { |path| clean_file(path) }
13
+ end
14
+ end
15
+
16
+ def clean_file path
17
+ FileUtils.rm(path) if File.exists?(path)
10
18
  end
@@ -0,0 +1,6 @@
1
+ source: ''
2
+ destination: '_site'
3
+ stylesheet: '_sv_custom.css'
4
+ javascript: '_sv_custom.js'
5
+ layout: '_layout.liquid'
6
+ includes: '_includes'
@@ -0,0 +1,20 @@
1
+ <head>
2
+ <title></title>
3
+
4
+ <meta name="author" content="">
5
+ <meta name="description" content="">
6
+
7
+ <meta charset="utf-8">
8
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
9
+ <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
10
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
11
+
12
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
13
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
14
+
15
+ <link rel="stylesheet" href="{{ config.stylesheet }}" />
16
+
17
+ <!--[if lt IE 9]>
18
+ <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
19
+ <![endif]-->
20
+ </head>
@@ -0,0 +1 @@
1
+ <h1>Hello World!</h1>
@@ -0,0 +1,8 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" class="no-js">
3
+ {% include 'head' %}
4
+ <body>
5
+ {{content_for_layout}}
6
+ <script type="text/javascript" src="{{ config.javascript }}"></script>
7
+ </body>
8
+ </html>
@@ -8,6 +8,8 @@
8
8
  * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
9
9
  * file per style scope.
10
10
  *
11
- *= require_self
11
+ * Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
12
+ * about supported directives.
13
+ *
12
14
  *= require_tree .
13
15
  */
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smallvictories
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dijkstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sassc
@@ -31,9 +31,6 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.4'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 3.4.0
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -41,9 +38,6 @@ dependencies:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
40
  version: '3.4'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 3.4.0
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: listen
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -51,19 +45,69 @@ dependencies:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '3.0'
54
- - - ">="
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: uglifier
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coffee-script
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
55
74
  - !ruby/object:Gem::Version
56
- version: 3.0.3
75
+ version: '2.4'
57
76
  type: :runtime
58
77
  prerelease: false
59
78
  version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: liquid
85
+ requirement: !ruby/object:Gem::Requirement
60
86
  requirements:
61
87
  - - "~>"
62
88
  - !ruby/object:Gem::Version
63
89
  version: '3.0'
64
- - - ">="
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: autoprefixer-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '6.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
65
109
  - !ruby/object:Gem::Version
66
- version: 3.0.3
110
+ version: '6.0'
67
111
  - !ruby/object:Gem::Dependency
68
112
  name: bundler
69
113
  requirement: !ruby/object:Gem::Requirement
@@ -121,6 +165,7 @@ files:
121
165
  - Rakefile
122
166
  - bin/sv
123
167
  - lib/smallvictories.rb
168
+ - lib/smallvictories/builder.rb
124
169
  - lib/smallvictories/compiler.rb
125
170
  - lib/smallvictories/configuration.rb
126
171
  - lib/smallvictories/constants.rb
@@ -128,16 +173,31 @@ files:
128
173
  - lib/smallvictories/version.rb
129
174
  - lib/smallvictories/watcher.rb
130
175
  - smallvictories.gemspec
176
+ - spec/builder_spec.rb
131
177
  - spec/compiler_spec.rb
132
178
  - spec/configuration_spec.rb
133
- - spec/fixtures/_config.yml
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
179
+ - spec/fixtures/_sv_custom.css
180
+ - spec/fixtures/destination/.gitkeep
181
+ - spec/fixtures/invalid/_layout.liquid
138
182
  - spec/fixtures/invalid/_sass/stylesheet.scss
183
+ - spec/fixtures/invalid/index.html
184
+ - spec/fixtures/source/_config.yml
185
+ - spec/fixtures/source/_includes/_snippet.liquid
186
+ - spec/fixtures/source/_javascripts/scripts.coffee
187
+ - spec/fixtures/source/_javascripts/scripts.js
188
+ - spec/fixtures/source/_layout.liquid
189
+ - spec/fixtures/source/_stylesheets/bootstrap.scss
190
+ - spec/fixtures/source/_stylesheets/extra.scss
191
+ - spec/fixtures/source/_stylesheets/stylesheet.scss
192
+ - spec/fixtures/source/_sv_custom.css
193
+ - spec/fixtures/source/_sv_custom.js
194
+ - spec/fixtures/source/index.html
139
195
  - spec/spec_helper.rb
196
+ - src/config.yml
197
+ - src/head.liquid
198
+ - src/index.liquid
140
199
  - src/javascript.js
200
+ - src/layout.liquid
141
201
  - src/stylesheet.css
142
202
  homepage: https://github.com/xxix/smallvictories-gem
143
203
  licenses:
@@ -164,12 +224,23 @@ signing_key:
164
224
  specification_version: 4
165
225
  summary: A command line utility for building websites.
166
226
  test_files:
227
+ - spec/builder_spec.rb
167
228
  - spec/compiler_spec.rb
168
229
  - spec/configuration_spec.rb
169
- - spec/fixtures/_config.yml
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
230
+ - spec/fixtures/_sv_custom.css
231
+ - spec/fixtures/destination/.gitkeep
232
+ - spec/fixtures/invalid/_layout.liquid
174
233
  - spec/fixtures/invalid/_sass/stylesheet.scss
234
+ - spec/fixtures/invalid/index.html
235
+ - spec/fixtures/source/_config.yml
236
+ - spec/fixtures/source/_includes/_snippet.liquid
237
+ - spec/fixtures/source/_javascripts/scripts.coffee
238
+ - spec/fixtures/source/_javascripts/scripts.js
239
+ - spec/fixtures/source/_layout.liquid
240
+ - spec/fixtures/source/_stylesheets/bootstrap.scss
241
+ - spec/fixtures/source/_stylesheets/extra.scss
242
+ - spec/fixtures/source/_stylesheets/stylesheet.scss
243
+ - spec/fixtures/source/_sv_custom.css
244
+ - spec/fixtures/source/_sv_custom.js
245
+ - spec/fixtures/source/index.html
175
246
  - spec/spec_helper.rb
@@ -1,5 +0,0 @@
1
- /* Small Victories Sprockets File
2
- *
3
- *= require extra
4
- *= require_tree .
5
- */