jekyll-less 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1 +1,2 @@
1
- require 'bundler/gem_tasks'
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/lib/jekyll-less.rb CHANGED
@@ -1,37 +1,62 @@
1
1
  require "jekyll-less/version"
2
+ require 'less'
2
3
 
3
4
  module Jekyll
4
5
  module Less
5
- class LessConverter < Converter
6
- pygments_prefix "\n"
7
- pygments_suffix "\n"
8
-
9
- def setup
10
- return if @setup
11
- require 'less'
12
- @setup = true
13
- rescue LoadError
14
- STDERR.puts 'You are missing a library required for less. Please run:'
15
- STDERR.puts ' $ [sudo] gem install less'
16
- raise FatalException.new("Missing dependency: less")
17
- end
18
6
 
19
- def matches(ext)
20
- ext =~ /less/i
21
- end
7
+ class LessCssFile < Jekyll::StaticFile
22
8
 
23
- def output_ext(ext)
24
- ".css"
9
+ # Obtain destination path.
10
+ # +dest+ is the String path to the destination dir
11
+ #
12
+ # Returns destination file path.
13
+ def destination(dest)
14
+ File.join(dest, @dir, @name.sub(/less$/, 'css'))
25
15
  end
26
16
 
27
- def convert(content)
28
- setup
17
+ # Convert the less file into a css file.
18
+ # +dest+ is the String path to the destination dir
19
+ #
20
+ # Returns false if the file was not modified since last time (no-op).
21
+ def write(dest)
22
+ dest_path = destination(dest)
23
+
24
+ return false if File.exist? dest_path and !modified?
25
+ @@mtimes[path] = mtime
26
+
27
+ FileUtils.mkdir_p(File.dirname(dest_path))
29
28
  begin
30
- ::Less::Parser.new().parse(content).to_css
29
+ content = File.read(path)
30
+ content = ::Less::Parser.new().parse(content).to_css
31
+ File.open(dest_path, 'w') do |f|
32
+ f.write(content)
33
+ end
31
34
  rescue => e
32
- puts "Less Exception: #{e.message}"
35
+ STDERR.puts "Less Exception: #{e.message}"
33
36
  end
37
+
38
+ true
34
39
  end
40
+
35
41
  end
42
+
43
+ class LessCssGenerator < Jekyll::Generator
44
+ safe true
45
+
46
+ # Jekyll will have already added the *.less files as Jekyll::StaticFile
47
+ # objects to the static_files array. Here we replace those with a
48
+ # LessCssFile object.
49
+ def generate(site)
50
+ site.static_files.each do |sf|
51
+ if sf.kind_of?(Jekyll::StaticFile) && sf.path =~ /\.less$/
52
+ site.static_files.delete(sf)
53
+ name = File.basename(sf.path)
54
+ destination = File.dirname(sf.path).sub(site.source, '')
55
+ site.static_files << LessCssFile.new(site, site.source, destination, name)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
36
61
  end
37
62
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Less
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/readme.md CHANGED
@@ -22,6 +22,9 @@ css file would end up at _css/my-stuff/styles.css_.
22
22
 
23
23
  Important Note
24
24
  --------------
25
+
26
+ __As of v0.0.2, this is no longer required, and the header must be removed.__
27
+
25
28
  All .less files __MUST__ have a [YAML Front Matter](http://wiki.github.com/mojombo/jekyll/yaml-front-matter)
26
29
  header, even if empty. Jekyll will only convert files that have a valid Front
27
30
  Matter header, so if you do not include this, the files will not be converted.
@@ -42,3 +45,8 @@ of the gems specified in your Gemfile.
42
45
  require "rubygems"
43
46
  require "bundler/setup"
44
47
  Bundler.require(:default)
48
+
49
+ Credit
50
+ ------
51
+ This gem was originally based on this [gist](https://gist.github.com/760265) by
52
+ [joshbrown](https://github.com/joshbrown). As of v0.0.2 it is a complete rewrite.
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Roger L\xC3\xB3pez"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-06-30 00:00:00 -04:00
17
+ date: 2011-07-08 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency