opulent 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/Rakefile +3 -3
- data/lib/opulent/context.rb +6 -7
- data/lib/opulent/engine.rb +36 -9
- data/lib/opulent/settings.rb +4 -1
- data/lib/opulent/template.rb +4 -2
- data/lib/opulent/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed644b0ba2857806a88f0da508087a32b31e85cd
|
4
|
+
data.tar.gz: 667cb3bfa83b2ea0786aa9427404ebab524fdb36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55567d695622a6b7c50b45334b851474db72a43b9b7afc2f854125da0b0a6b45f7c06ee2b39f8f3202fba29999b7e36903b9506f6a2fd6b6700e6a0c17ed92cf
|
7
|
+
data.tar.gz: eae525a670999e15c25ac8e7859d5ec7ca934c0c8d2bbcb001c08eb89608f80851aa2a957bf5aa89ef040141b5b37a94dcab8f672e4323440ad6a2fbe56efec6
|
data/README.md
CHANGED
@@ -72,7 +72,16 @@ Using Opulent to render a file is as easy as including it in your application an
|
|
72
72
|
```ruby
|
73
73
|
require 'opulent'
|
74
74
|
|
75
|
-
Opulent.new.render_file
|
75
|
+
Opulent.new.render_file :index
|
76
|
+
```
|
77
|
+
|
78
|
+
For layouts you can simply use the following code. By default, the layout is set to __layouts/application__.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
require 'opulent'
|
82
|
+
|
83
|
+
opulent = Opulent.new layouts: true
|
84
|
+
opulent.render_file :index, layout: :'path/layout'
|
76
85
|
```
|
77
86
|
|
78
87
|
<!--
|
data/Rakefile
CHANGED
data/lib/opulent/context.rb
CHANGED
@@ -13,9 +13,12 @@ module Opulent
|
|
13
13
|
# given as arguments
|
14
14
|
#
|
15
15
|
# @param locals [Hash] Binding extension
|
16
|
-
# @param
|
16
|
+
# @param block [Binding] Call environment block
|
17
|
+
# @param content [Binding] Content yielding
|
17
18
|
#
|
18
|
-
def initialize(locals = {}, &
|
19
|
+
def initialize(locals = {}, block, &content)
|
20
|
+
@content = content
|
21
|
+
|
19
22
|
@block = block
|
20
23
|
@binding = if @block
|
21
24
|
@block.binding.clone
|
@@ -41,7 +44,7 @@ module Opulent
|
|
41
44
|
# Call given input block and return the output
|
42
45
|
#
|
43
46
|
def evaluate_yield
|
44
|
-
@
|
47
|
+
@content.call if @content
|
45
48
|
end
|
46
49
|
|
47
50
|
# Extend the call context with a Hash, String or other Object
|
@@ -71,10 +74,6 @@ module Opulent
|
|
71
74
|
bind.eval('self.class.class_variables').each do |var|
|
72
75
|
@binding.eval('self').class_variable_set var, bind.eval(var.to_s)
|
73
76
|
end
|
74
|
-
#
|
75
|
-
# bind.eval('self.class.constants').each do |var|
|
76
|
-
# @binding.eval('self').const_set var, bind.eval(var.to_s)
|
77
|
-
# end
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
data/lib/opulent/engine.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# @Opulent
|
2
2
|
module Opulent
|
3
|
+
# Debug enable
|
4
|
+
#
|
5
|
+
DEBUG = false
|
6
|
+
|
3
7
|
# Module method wrapper for creating a new engine instance
|
4
8
|
#
|
5
9
|
def Opulent.new(settings = {})
|
@@ -18,7 +22,6 @@ module Opulent
|
|
18
22
|
#
|
19
23
|
def initialize(settings = {})
|
20
24
|
@definitions = {}
|
21
|
-
@overwrite = settings.delete :overwrite
|
22
25
|
|
23
26
|
Settings.update_settings settings unless settings.empty?
|
24
27
|
end
|
@@ -36,6 +39,27 @@ module Opulent
|
|
36
39
|
render file, locals, &block
|
37
40
|
end
|
38
41
|
|
42
|
+
# Avoid code duplication when layouting is set. When we have a layout, look
|
43
|
+
# in layouts/application by default.
|
44
|
+
#
|
45
|
+
# @param file [String] The file that needs to be analyzed
|
46
|
+
# @param locals [Hash] Render call local variables
|
47
|
+
# @param block [Proc] Processing environment data
|
48
|
+
#
|
49
|
+
def render(input, locals = {}, &block)
|
50
|
+
# If a layout is set, get the specific layout, otherwise, set the default
|
51
|
+
# one. If a layout is set to false, the page will be render as it is.
|
52
|
+
if Settings[:layouts]
|
53
|
+
layout = locals.has_key?(:layout) ? locals.delete(:layout) : Settings[:default_layout]
|
54
|
+
|
55
|
+
get layout, locals, block do
|
56
|
+
get input, locals, block
|
57
|
+
end
|
58
|
+
else
|
59
|
+
get input, locals, block
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
39
63
|
# Analyze the input code and check for matching tokens. In case no match was
|
40
64
|
# found, throw an exception. In special cases, modify the token hash.
|
41
65
|
#
|
@@ -43,7 +67,7 @@ module Opulent
|
|
43
67
|
# @param locals [Hash] Render call local variables
|
44
68
|
# @param block [Proc] Processing environment data
|
45
69
|
#
|
46
|
-
def
|
70
|
+
def get(input, locals, block, &content)
|
47
71
|
# Get input code
|
48
72
|
@code = read input
|
49
73
|
|
@@ -55,16 +79,18 @@ module Opulent
|
|
55
79
|
@preamble = @nodes.inspect.inspect
|
56
80
|
|
57
81
|
# Create a new context based on our rendering environment
|
58
|
-
@context = Context.new locals, &
|
82
|
+
@context = Context.new locals, block, &content
|
59
83
|
|
60
84
|
# Compile our syntax tree using input context
|
61
85
|
@output = Compiler.new.compile @nodes, @context
|
62
86
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
87
|
+
if DEBUG
|
88
|
+
#puts "Nodes\n---\n"
|
89
|
+
#pp @nodes
|
90
|
+
|
91
|
+
# puts "\n\nCode\n---\n"
|
92
|
+
# pp @output
|
93
|
+
end
|
68
94
|
|
69
95
|
return @output
|
70
96
|
end
|
@@ -77,7 +103,8 @@ module Opulent
|
|
77
103
|
#
|
78
104
|
def read(input)
|
79
105
|
if @mode == :file
|
80
|
-
@file = File.expand_path input
|
106
|
+
@file = File.expand_path "#{input}.op"
|
107
|
+
@mode = nil unless Settings[:layouts]
|
81
108
|
return File.read @file
|
82
109
|
else
|
83
110
|
@file = File.expand_path __FILE__
|
data/lib/opulent/settings.rb
CHANGED
data/lib/opulent/template.rb
CHANGED
@@ -17,9 +17,11 @@ module Opulent
|
|
17
17
|
# Enable caching for the current rendered file
|
18
18
|
@options[:cache] = true
|
19
19
|
|
20
|
+
# Enable layouts so that we can render with symbols
|
21
|
+
@options[:layouts] = true
|
22
|
+
|
20
23
|
# Set up the rendering engine
|
21
24
|
@engine = ::Opulent.new @options
|
22
|
-
#@engine.update_options @options
|
23
25
|
end
|
24
26
|
|
25
27
|
# Execute the compiled template and return the result string. Template
|
@@ -63,5 +65,5 @@ module Opulent
|
|
63
65
|
end
|
64
66
|
|
65
67
|
# Register Opulent to Tilt
|
66
|
-
::Tilt.register OpulentTemplate, 'op'
|
68
|
+
::Tilt.register OpulentTemplate, 'op'
|
67
69
|
end
|
data/lib/opulent/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opulent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Grozav
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|