dimples 1.0.0 → 1.1.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: 9af69955701e46818367fbe965f4bb1071427319
4
- data.tar.gz: 2d2c2861d73eef0348bb98f7d06ec6e94c3b007e
3
+ metadata.gz: 8087737e6b6cd32e6ce78ac923d25fb81fea3ee1
4
+ data.tar.gz: 9115b1916e6d5e68aba8d0d72eee3e5467f8c3b9
5
5
  SHA512:
6
- metadata.gz: 422c790ef28519c67b634dffe74515cf52f6941e62bff67180822f26cb95c6f89be25608a9c73761a65812d4efbb4e0e80c1e34976bad0dac20d5dbc3d39442e
7
- data.tar.gz: d30324038e2fad5432ca578ba84f7936fe961c2e30885a473893dfa2844bb012a9b055ede5bf8d48958de458e20fbe3ff089d1adbed049637774db0a216183a0
6
+ metadata.gz: 75bf70ae2806048bec78a8289e0f8fe97f30ddadd5eb2ea4fb9a6419398d356089fd29af2814f1391fd115d516cd3a10792cca28ce1167663932d4802c5e9b6e
7
+ data.tar.gz: 62750172f7d2a54c770321ce28e7fd0ad43f66684d6dd52f242de058accf99d26abb0799572913007419968cb46539af3a6dcd5775490f1af7229589f04c22ad
@@ -2,8 +2,7 @@ $LOAD_PATH.unshift(__dir__)
2
2
 
3
3
  require 'fileutils'
4
4
  require 'yaml'
5
- require 'erubis'
6
- require 'redcarpet'
5
+ require 'tilt'
7
6
 
8
7
  require 'dimples/frontable'
9
8
  require 'dimples/publishable'
@@ -1,7 +1,7 @@
1
1
  module Dimples
2
2
  module Frontable
3
3
  def read_with_yaml(path)
4
- if path =~ /.yml$/
4
+ if File.extname(path) == '.yml'
5
5
  contents = ''
6
6
  metadata = YAML.load_file(path)
7
7
  else
@@ -10,7 +10,7 @@ module Dimples
10
10
 
11
11
  if matches
12
12
  metadata = YAML.load(matches[1])
13
- contents = matches.post_match.strip!
13
+ contents = matches.post_match.strip
14
14
  end
15
15
  end
16
16
 
@@ -9,6 +9,7 @@ module Dimples
9
9
  attr_accessor :filename
10
10
  attr_accessor :extension
11
11
  attr_accessor :layout
12
+ attr_accessor :rendered_contents
12
13
 
13
14
  attr_writer :contents
14
15
 
@@ -24,7 +25,6 @@ module Dimples
24
25
  end
25
26
 
26
27
  @extension = @site.config['file_extensions']['pages']
27
- @layout ||= @site.config['layouts']['page']
28
28
  end
29
29
 
30
30
  def type
@@ -15,9 +15,9 @@ module Dimples
15
15
  attr_accessor :year
16
16
  attr_accessor :month
17
17
  attr_accessor :day
18
+ attr_accessor :rendered_contents
18
19
 
19
20
  attr_writer :contents
20
- attr_writer :markdown
21
21
 
22
22
  def initialize(site, path)
23
23
  @site = site
@@ -49,10 +49,6 @@ module Dimples
49
49
  @contents
50
50
  end
51
51
 
52
- def markdown
53
- @markdown ||= @site.markdown_engine.render(contents())
54
- end
55
-
56
52
  def output_file_path(parent_path)
57
53
  parts = [parent_path]
58
54
 
@@ -1,7 +1,7 @@
1
1
  module Dimples
2
2
  module Publishable
3
- def write(path, context = false)
4
- output = context ? render(contents(), {this: self}.merge(context)) : contents()
3
+ def write(path, context = {})
4
+ output = render(context)
5
5
 
6
6
  publish_path = output_file_path(path)
7
7
  parent_path = File.dirname(publish_path)
@@ -13,17 +13,22 @@ module Dimples
13
13
  end
14
14
  end
15
15
 
16
- def render(body, context = {}, use_layout = true)
17
- context[:site] ||= @site
16
+ def render(context = {}, body = nil, use_layout = true)
17
+ context[:site] = @site unless context[:site]
18
+ context[:this] = self unless context[:this]
18
19
 
19
20
  begin
20
- output = Erubis::Eruby.new(contents()).evaluate(context) { body }
21
- rescue SyntaxError => e
22
- raise "Syntax error in #{path.gsub(site.source_paths[:root], '')}"
21
+ proc = Proc.new { |template| contents() }
22
+ renderer = @path ? Tilt.new(@path, &proc) : Tilt::StringTemplate.new(&proc)
23
+ output = renderer.render(nil, context) { body }.strip
24
+
25
+ @rendered_contents = output
26
+ rescue RuntimeError, TypeError, NoMethodError => e
27
+ raise "Failed to render #{path ? path.gsub(@site.source_paths[:root], '') : type} - #{e}"
23
28
  end
24
29
 
25
30
  if use_layout && @layout && @site.templates[@layout]
26
- output = @site.templates[@layout].render(output, context)
31
+ output = @site.templates[@layout].render(context, output)
27
32
  end
28
33
 
29
34
  output
@@ -9,7 +9,6 @@ module Dimples
9
9
  attr_accessor :pages
10
10
  attr_accessor :posts
11
11
  attr_accessor :latest_post
12
- attr_accessor :markdown_engine
13
12
  attr_accessor :page_class
14
13
  attr_accessor :post_class
15
14
 
@@ -38,12 +37,6 @@ module Dimples
38
37
  end
39
38
 
40
39
  @output_paths[:posts] = File.join(@output_paths[:site], @config['paths']['posts'])
41
-
42
- @markdown_engine = if @config['markdown']['enabled']
43
- Redcarpet::Markdown.new(Redcarpet::Render::HTML, @config['markdown']['options'])
44
- else
45
- false
46
- end
47
40
  end
48
41
 
49
42
  def scan_files
@@ -85,7 +78,7 @@ module Dimples
85
78
 
86
79
  def generate
87
80
  scan_files
88
-
81
+
89
82
  begin
90
83
  FileUtils.remove_dir(@output_paths[:site]) if Dir.exist?(@output_paths[:site])
91
84
  Dir.mkdir(@output_paths[:site])
@@ -95,7 +88,7 @@ module Dimples
95
88
 
96
89
  @posts.each do |post|
97
90
  begin
98
- post.write(@output_paths[:posts], {})
91
+ post.write(@output_paths[:posts])
99
92
  rescue => e
100
93
  raise "Failed to render post #{File.basename(post.path)} (#{e})"
101
94
  end
@@ -103,7 +96,7 @@ module Dimples
103
96
 
104
97
  @pages.each do |page|
105
98
  begin
106
- page.write(@output_paths[:site], {})
99
+ page.write(@output_paths[:site])
107
100
  rescue => e
108
101
  raise "Failed to render page from #{page.path.gsub(@source_paths[:root], '')} (#{e})"
109
102
  end
@@ -206,14 +199,14 @@ module Dimples
206
199
  end
207
200
  end
208
201
 
209
- def generate_feed(path, params)
202
+ def generate_feed(path, options)
210
203
  feed = @page_class.new(self)
211
204
 
212
205
  feed.filename = 'feed'
213
206
  feed.extension = 'atom'
214
207
  feed.layout = 'feed'
215
208
 
216
- feed.write(path, params)
209
+ feed.write(path, options)
217
210
  end
218
211
 
219
212
  def paginate(posts, title, per_page, paths, layout, params = {})
@@ -262,17 +255,5 @@ module Dimples
262
255
  page.write(File.join(page_paths), {posts: range, pagination: pagination}.merge(params))
263
256
  end
264
257
  end
265
-
266
- def render(template_slug, content, layout = true)
267
- return '' unless @templates[template_slug]
268
-
269
- if content.is_a? String
270
- @templates[template_slug].render(content, {}, layout)
271
- elsif content.is_a? Hash
272
- @templates[template_slug].render('', content, layout)
273
- else
274
- ''
275
- end
276
- end
277
258
  end
278
259
  end
@@ -7,6 +7,7 @@ module Dimples
7
7
  attr_accessor :title
8
8
  attr_accessor :path
9
9
  attr_accessor :contents
10
+ attr_accessor :rendered_contents
10
11
 
11
12
  def initialize(site, path)
12
13
  @site = site
@@ -15,5 +16,9 @@ module Dimples
15
16
 
16
17
  @contents = read_with_yaml(path)
17
18
  end
19
+
20
+ def type
21
+ :template
22
+ end
18
23
  end
19
24
  end
@@ -1,3 +1,3 @@
1
1
  module Dimples
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dimples
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis