jekyll-slim 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e7d4235a49301422ec2482bc64a43b5c0b01b13
4
- data.tar.gz: 1709e4b9a0fc7971dbe41cfc8949a2de79df1131
3
+ metadata.gz: 3636386147b7f495d491744828c52ff23d66f856
4
+ data.tar.gz: d2821b227136f82fbe7cefb16b3c57f1e1694c5b
5
5
  SHA512:
6
- metadata.gz: dbb329a6cc989816940abe55a655079cc5928d716f7b7d9554afabde17c5fd746ab1106547a4f7332294f36f5fae3fbfb0d25b22f588a986c33fa2b777b9e247
7
- data.tar.gz: 23e09c32c68123e9e18ea3d7c8de0dc88787e11889d2140f635b8214178c2c567ded3948e123c79f72597834becc82a835b533cdff27e9d158dac19896cb1b7b
6
+ metadata.gz: 6a4d62aeba3d64840abdc4028757f786ebbdefabf14acc3f5be95ad8c95f27bc417e06169cc31b71d98225871553b295556598a94144f5c0fbe468d5f8803097
7
+ data.tar.gz: db620117af430c661f7f647fe25528c109d9a9edaaebf4cfd74509252415bdc0a5fd9eecc21ba0ba91181a343d877c34ea5cebfe69d5d683259b77f996b9504a
data/History.md CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ 0.8.2 / 2013-05-06
3
+ ==================
4
+
5
+ * Fix `layout.rb` import path
6
+
2
7
  0.8.1 / 2013-05-05
3
8
  ==================
4
9
 
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Jekyll-slim
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/jekyll-slim.png)](http://badge.fury.io/rb/jekyll-slim) [![Dependency Status](https://gemnasium.com/kaishin/jekyll-slim.png)](https://gemnasium.com/kaishin/jekyll-slim) [![Code Climate](https://codeclimate.com/github/kaishin/jekyll-slim.png)](https://codeclimate.com/github/kaishin/jekyll-slim) [![Build Status](https://travis-ci.org/kaishin/jekyll-slim.png)](https://travis-ci.org/kaishin/jekyll-slim)
3
+ [![Gem Version](http://img.shields.io/gem/v/jekyll-slim.svg?style=flat)](#)
4
+ [![Dependency
5
+ Status](http://img.shields.io/gemnasium/kaishin/jekyll-slim.svg?style=flat)](https://gemnasium.com/kaishin/jekyll-slim)
6
+ [![Code
7
+ Climate](http://img.shields.io/codeclimate/github/kaishin/jekyll-slim.svg?style=flat)](https://codeclimate.com/github/kaishin/jekyll-slim)
8
+ [![Build Status](http://img.shields.io/travis/kaishin/jekyll-slim.svg?style=flat)](https://travis-ci.org/kaishin/jekyll-slim)
4
9
 
5
10
  A gem that adds [slim-lang](http://slim-lang.com) support to [Jekyll](http://github.com/mojombo/jekyll). Works for for pages, includes and layouts.
6
11
 
@@ -29,7 +34,7 @@ In your Jekyll project's `_plugins` directory:
29
34
 
30
35
  The gem will convert all the `.slim` files in your project's directory into HTML. That includes files in sub-directories, includes and layouts. Example:
31
36
 
32
- ```haml
37
+ ```slim
33
38
  # _layouts/default.slim
34
39
  html
35
40
  head
@@ -39,7 +44,7 @@ html
39
44
  ```
40
45
  To include a partial, use the `slim` liquid tag instead of `include`:
41
46
 
42
- ```haml
47
+ ```slim
43
48
  # index.slim
44
49
  ---
45
50
  layout: default
@@ -50,7 +55,46 @@ section.content Content goes here.
50
55
 
51
56
  ```
52
57
 
58
+ ### Options
59
+
60
+ Is possible to set options available for Slim engine through the `slim` key in `_config.yml`. Example:
61
+
62
+ ```yaml
63
+ # _config.yml
64
+ slim:
65
+ pretty: true
66
+ format: html5
67
+ ```
68
+
69
+ ### Context
70
+
71
+ The slim context is set to acess a `SlimContext` object which has a `site` method, used to access `config`. Be careful because this is a breaking change.
72
+
73
+ This allows you to access configuration information in your slim file. Example:
74
+
75
+ ```slim
76
+ html
77
+ head
78
+ body
79
+ .content-wrapper
80
+ = "slim pretty mode: #{ site.config['slim']['pretty'].to_s }"
81
+ ```
82
+
83
+ The `SlimContext` object will be kept across calls, allowing you to easily set
84
+ `@instance_variables` that can be accessed by **all slim files** even those included with the `slim`
85
+ liquid tag. Those are more or less global variables in slim templates, so be careful when you use them.
86
+
87
+ ## TODO
88
+
89
+ - Per-page slim context?
90
+ - Improve code and try to avoid patches as much as possible
91
+ - Parsing Liquid tags before slim so you have access to everything? Can create a lot of problems with Ruby
92
+ - Slim context must be the same as liquid, with paginator, site, page and content variables. See these links:
93
+ - https://github.com/mojombo/jekyll/blob/a9e2a74ea619a01a9d169da2240ce91b43362c9f/lib/jekyll/tags/include.rb
94
+ - https://github.com/mojombo/jekyll/blob/a9e2a74ea619a01a9d169da2240ce91b43362c9f/lib/jekyll/page.rb
95
+ - http://jekyllrb.com/docs/plugins/
96
+ - http://jekyllrb.com/docs/variables/
97
+
53
98
  ## Credit
54
99
 
55
100
  Jekyll-slim was heavily inspired by [jekyll-haml](https://github.com/samvincent/jekyll-haml). It is free software, and may be redistributed under the terms specified in the LICENSE file.
56
-
@@ -4,21 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'jekyll-slim/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "jekyll-slim"
7
+ gem.name = 'jekyll-slim'
8
8
  gem.version = Jekyll::Slim::VERSION
9
- gem.authors = ["Reda Lemeden"]
10
- gem.email = ["reda@thoughtbot.com"]
9
+ gem.authors = ['Reda Lemeden', 'Francesco Belladonna']
10
+ gem.email = ['reda@thoughtbot.com', 'francesco.belladonna@gmail.com']
11
11
  gem.description = %q{Slim html converter for Jekyll}
12
12
  gem.summary = %q{Slim-lang support for Jekyll. Handles includes and layouts as well.}
13
- gem.homepage = ""
13
+ gem.homepage = ''
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
18
+ gem.require_paths = ['lib']
19
19
 
20
- gem.add_runtime_dependency 'jekyll', ">= 0.10.0"
21
- gem.add_runtime_dependency 'slim'
20
+ gem.add_runtime_dependency 'jekyll', '~> 1.2.1'
21
+ gem.add_runtime_dependency 'activesupport', '~> 4.0'
22
+ gem.add_runtime_dependency 'slim', '~> 2.0.2'
22
23
 
23
24
  gem.add_development_dependency('rake')
24
25
  gem.add_development_dependency('bundler')
@@ -1,27 +1,8 @@
1
1
  require 'slim'
2
2
  require 'jekyll-slim/version'
3
+ require 'jekyll-slim/extensions/layout'
4
+ require 'jekyll-slim/extensions/site'
5
+ require 'jekyll-slim/extensions/converter'
6
+ require 'jekyll-slim/slim_converter'
7
+ require 'jekyll-slim/slim_context'
3
8
  require 'jekyll-slim/tags/slim_partial'
4
- require 'jekyll-slim/ext/layout'
5
-
6
- module Jekyll
7
- class SlimConverter < Converter
8
- safe true
9
- priority :low
10
-
11
- def matches(ext)
12
- ext =~ /slim/i
13
- end
14
-
15
- def output_ext(ext)
16
- ".html"
17
- end
18
-
19
- def convert(content)
20
- begin
21
- ::Slim::Template.new { content }.render
22
- rescue StandardError => e
23
- puts "(!) SLIM ERROR: " + e.message
24
- end
25
- end
26
- end
27
- end
@@ -0,0 +1,10 @@
1
+ module Jekyll
2
+ class Converter < Plugin
3
+
4
+ # Patch used to export site variable to converters
5
+ def locals(locals=nil)
6
+ @locals = locals if locals
7
+ @locals
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,9 @@
1
1
  module Jekyll
2
2
  class Layout
3
+
4
+ # Allows layouts to be transformed by slim until this is fixed (1.4)
5
+ # https://github.com/mojombo/jekyll/issues/225
6
+ # https://github.com/mojombo/jekyll/blob/master/lib/jekyll/layout.rb
3
7
  def initialize(site, base, name)
4
8
  @site = site
5
9
  @base = base
@@ -0,0 +1,26 @@
1
+ require 'jekyll-slim/slim_context'
2
+
3
+ module Jekyll
4
+ class Site
5
+
6
+ attr_reader :slim_context
7
+
8
+ # Patch to allow usage of site variable in Slim/Haml
9
+ # https://blog.darmasoft.net/2012/02/29/haml-processing-in-jekyll.html
10
+ # https://github.com/mojombo/jekyll/blob/master/lib/jekyll/site.rb
11
+ def instantiate_subclasses(klass)
12
+ klass.subclasses.select do |c|
13
+ !self.safe || c.safe
14
+ end.sort.map do |c|
15
+ conv = c.new(self.config)
16
+ # XXX: Hotfix to allow access site variable in slim/haml templates
17
+ if conv.respond_to?(:locals)
18
+ @slim_context ||= SlimContext.new(self)
19
+ conv.locals({ slim_context: @slim_context })
20
+ end
21
+
22
+ conv
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ class SlimContext
2
+ attr_accessor :params
3
+
4
+ def initialize(site_context)
5
+ # XXX: Hopefully user won't overwrite this instance variable
6
+ @__site = site_context
7
+ end
8
+
9
+ def site
10
+ @__site
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ require 'slim'
2
+
3
+ module Jekyll
4
+ class SlimConverter < Converter
5
+ safe false
6
+ priority :low
7
+
8
+ def initialize(config)
9
+ super
10
+ self.ensure_config_integrity
11
+ end
12
+
13
+ def matches(ext)
14
+ ext =~ /slim/i
15
+ end
16
+
17
+ def output_ext(ext)
18
+ ".html"
19
+ end
20
+
21
+ def convert(content)
22
+ begin
23
+ ::Slim::Template.new(@symbolized_config) { content }.render(locals[:slim_context])
24
+ rescue StandardError => e
25
+ puts "(!) SLIM ERROR: " + e.message
26
+ end
27
+ end
28
+
29
+ def ensure_config_integrity
30
+ @config['slim'] ||= {}
31
+ @symbolized_config = @config['slim'].deep_symbolize_keys
32
+ end
33
+ end
34
+ end
@@ -2,9 +2,48 @@ require 'slim'
2
2
 
3
3
  module Jekyll
4
4
  class SlimPartialTag < Liquid::Tag
5
- def initialize(tag_name, file, tokens)
5
+
6
+ SYNTAX_EXAMPLE = "{% slim file.slim param='value' param2='value' %}"
7
+
8
+ VALID_SYNTAX = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
9
+
10
+ def initialize(tag_name, markup, tokens)
6
11
  super
7
- @file = file.strip
12
+ @file, @params = markup.strip.split(' ', 2)
13
+ validate_params if @params
14
+ end
15
+
16
+ def validate_params
17
+ full_valid_syntax = Regexp.compile('\A\s*(?:' + VALID_SYNTAX.to_s + '(?=\s|\z)\s*)*\z')
18
+ unless @params =~ full_valid_syntax
19
+ raise ArgumentError.new <<-eos
20
+ Invalid syntax for include tag:
21
+ #{@params}
22
+
23
+ Valid syntax:
24
+ #{SYNTAX_EXAMPLE}
25
+ eos
26
+ end
27
+ end
28
+
29
+ def parse_params(context)
30
+ params = {}
31
+ markup = @params
32
+
33
+ while match = VALID_SYNTAX.match(markup) do
34
+ markup = markup[match.end(0)..-1]
35
+
36
+ value = if match[2]
37
+ match[2].gsub(/\\"/, '"')
38
+ elsif match[3]
39
+ match[3].gsub(/\\'/, "'")
40
+ elsif match[4]
41
+ slim_context[match[4]]
42
+ end
43
+
44
+ params[match[1]] = value
45
+ end
46
+ params
8
47
  end
9
48
 
10
49
  def render(context)
@@ -24,12 +63,17 @@ module Jekyll
24
63
  choices = Dir['**/*'].reject { |x| File.symlink?(x) }
25
64
  if choices.include?(@file)
26
65
  source = File.read(@file)
27
- conversion = ::Slim::Template.new{ source }.render
66
+ context.registers[:site].slim_context.params = parse_params(context.registers[:site].slim_context)
67
+ conversion = ::Slim::Template.new(context.registers[:site].config['slim'].deep_symbolize_keys) { source }.render(context.registers[:site].slim_context)
28
68
  partial = Liquid::Template.parse(conversion)
29
69
  begin
30
70
  return partial.render!(context)
31
71
  rescue => e
32
- puts "Liquid Exception: #{e.message} in #{self.data["layout"]}"
72
+ if self.respond_to?(:data)
73
+ puts "Liquid Exception: #{e.message} in #{self.data["layout"]}"
74
+ else
75
+ puts "Liquid Exception: #{e.message} in (Unknown layout)"
76
+ end
33
77
  e.backtrace.each do |backtrace|
34
78
  puts backtrace
35
79
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Slim
3
- VERSION = "0.8.2"
3
+ VERSION = "0.9.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,95 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-slim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reda Lemeden
8
+ - Francesco Belladonna
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2014-06-07 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: jekyll
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - '>='
18
+ - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: 0.10.0
20
+ version: 1.2.1
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - '>='
25
+ - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: 0.10.0
27
+ version: 1.2.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '4.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '4.0'
27
42
  - !ruby/object:Gem::Dependency
28
43
  name: slim
29
44
  requirement: !ruby/object:Gem::Requirement
30
45
  requirements:
31
- - - '>='
46
+ - - "~>"
32
47
  - !ruby/object:Gem::Version
33
- version: '0'
48
+ version: 2.0.2
34
49
  type: :runtime
35
50
  prerelease: false
36
51
  version_requirements: !ruby/object:Gem::Requirement
37
52
  requirements:
38
- - - '>='
53
+ - - "~>"
39
54
  - !ruby/object:Gem::Version
40
- version: '0'
55
+ version: 2.0.2
41
56
  - !ruby/object:Gem::Dependency
42
57
  name: rake
43
58
  requirement: !ruby/object:Gem::Requirement
44
59
  requirements:
45
- - - '>='
60
+ - - ">="
46
61
  - !ruby/object:Gem::Version
47
62
  version: '0'
48
63
  type: :development
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
52
- - - '>='
67
+ - - ">="
53
68
  - !ruby/object:Gem::Version
54
69
  version: '0'
55
70
  - !ruby/object:Gem::Dependency
56
71
  name: bundler
57
72
  requirement: !ruby/object:Gem::Requirement
58
73
  requirements:
59
- - - '>='
74
+ - - ">="
60
75
  - !ruby/object:Gem::Version
61
76
  version: '0'
62
77
  type: :development
63
78
  prerelease: false
64
79
  version_requirements: !ruby/object:Gem::Requirement
65
80
  requirements:
66
- - - '>='
81
+ - - ">="
67
82
  - !ruby/object:Gem::Version
68
83
  version: '0'
69
84
  - !ruby/object:Gem::Dependency
70
85
  name: rspec
71
86
  requirement: !ruby/object:Gem::Requirement
72
87
  requirements:
73
- - - '>='
88
+ - - ">="
74
89
  - !ruby/object:Gem::Version
75
90
  version: '0'
76
91
  type: :development
77
92
  prerelease: false
78
93
  version_requirements: !ruby/object:Gem::Requirement
79
94
  requirements:
80
- - - '>='
95
+ - - ">="
81
96
  - !ruby/object:Gem::Version
82
97
  version: '0'
83
98
  description: Slim html converter for Jekyll
84
99
  email:
85
100
  - reda@thoughtbot.com
101
+ - francesco.belladonna@gmail.com
86
102
  executables: []
87
103
  extensions: []
88
104
  extra_rdoc_files: []
89
105
  files:
90
- - .gitignore
91
- - .rspec
92
- - .travis.yml
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
93
109
  - Gemfile
94
110
  - History.md
95
111
  - LICENSE.txt
@@ -97,7 +113,11 @@ files:
97
113
  - Rakefile
98
114
  - jekyll-slim.gemspec
99
115
  - lib/jekyll-slim.rb
100
- - lib/jekyll-slim/ext/layout.rb
116
+ - lib/jekyll-slim/extensions/converter.rb
117
+ - lib/jekyll-slim/extensions/layout.rb
118
+ - lib/jekyll-slim/extensions/site.rb
119
+ - lib/jekyll-slim/slim_context.rb
120
+ - lib/jekyll-slim/slim_converter.rb
101
121
  - lib/jekyll-slim/tags/slim_partial.rb
102
122
  - lib/jekyll-slim/version.rb
103
123
  - spec/spec_helper.rb
@@ -110,17 +130,17 @@ require_paths:
110
130
  - lib
111
131
  required_ruby_version: !ruby/object:Gem::Requirement
112
132
  requirements:
113
- - - '>='
133
+ - - ">="
114
134
  - !ruby/object:Gem::Version
115
135
  version: '0'
116
136
  required_rubygems_version: !ruby/object:Gem::Requirement
117
137
  requirements:
118
- - - '>='
138
+ - - ">="
119
139
  - !ruby/object:Gem::Version
120
140
  version: '0'
121
141
  requirements: []
122
142
  rubyforge_project:
123
- rubygems_version: 2.0.3
143
+ rubygems_version: 2.2.2
124
144
  signing_key:
125
145
  specification_version: 4
126
146
  summary: Slim-lang support for Jekyll. Handles includes and layouts as well.