opulent 1.3.3 → 1.4.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: 1abeda932886282bd5f9fce009b1fa624a802b12
4
- data.tar.gz: 5123994660042759c670b74489dbb9284238ced1
3
+ metadata.gz: 44c953a9be6c659e56a0c33bc41637d7e1e0730d
4
+ data.tar.gz: 260dd8c631ab34debe0748cc53a27024988246b6
5
5
  SHA512:
6
- metadata.gz: a745a8f4df10a3b22adc5db60f89455a699a92b35d46b7f3da1ab25ae7d92476c9be8e53cf8df0e7fbe561296a8a7bab75b23eb02966442ccb4adb2086308e4b
7
- data.tar.gz: 89e1701db7adf3533dbd0b799f1f7fa599ec8ec6d6b340895da44411c8d882338acac06fde9d66033e33c254016ff00303f1534b4240ebd83f4b2f6aa9743f13
6
+ metadata.gz: 59e7c5c79cca92558ca68f2ab5be229bdd2815e4cb5a488465d3e0d391e548626905e1398327ebdc52746fb70cf688705ef7d6eaf2b696b40f2e717b3f795140
7
+ data.tar.gz: 5d0a8ad12ca13ba645417a1f73b0bfbb46f96b57db9d509976c777a5761feae6dcbfec48fee944c79f8063813116ca5d9d5e7ce08d59a72f912ab29a54dc8ccd
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Opulent is an __Intelligent Web Templating Engine__ created for extremely fast and efficient Web Development. Based on the idea of lightweight and reusable __Web Components__, Opulent greatly increases your development speed for any project.
4
4
 
5
+ [Read the Documentation](docs/reference.md)
6
+
5
7
  ## Syntax
6
8
 
7
9
  Opulent has a beautiful, minimalistic syntax: no tags, indentation based, optional brackets, inline text, inline children and in page definitions.
@@ -75,15 +77,6 @@ require 'opulent'
75
77
  Opulent.new.render_file :index
76
78
  ```
77
79
 
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'
85
- ```
86
-
87
80
  <!--
88
81
  ## Development
89
82
 
@@ -131,7 +131,7 @@ div unescaped=~"<div></div>"
131
131
  Unescaped buffered code can be dangerous. You must be sure to sanitize any user inputs to avoid cross-site scripting.
132
132
 
133
133
  ### Extending Attributes
134
- Attributes can be extended using a '__+__' symbol, followed by an expression which returns a Hash.
134
+ Attributes can be extended using a '__+__' symbol, followed by an expression which provides Hash.
135
135
 
136
136
  __Example__
137
137
  ```html
@@ -0,0 +1,22 @@
1
+ # Opulent Comments
2
+
3
+ Single line comments are marked up with a forward slash character `/`.
4
+
5
+ ```sass
6
+ / This is a comment
7
+ ```
8
+
9
+ ## Block Comments
10
+ Block comments are marked up with two forward slash characters `//`.
11
+
12
+ ```sass
13
+ // This is a block comment.
14
+ It is on multiple lines.
15
+ ```
16
+
17
+ ## Output Comments
18
+ By default, comments are only for reference inside Opulent files. You can output them
19
+ by adding an exclamation character `!`, to resemble HTML.
20
+ ```html
21
+ /! This comment will be outputted
22
+ ```
@@ -0,0 +1,42 @@
1
+ # Opulent Expressions
2
+
3
+ ```html
4
+ doctype html
5
+ <!DOCTYPE html>
6
+ ```
7
+
8
+ ## Doctype Shortcuts
9
+ ```html
10
+ doctype xml
11
+ <?xml version="1.0" encoding="utf-8" ?>
12
+ ```
13
+ ```html
14
+ doctype transitional
15
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
16
+ ```
17
+ ```html
18
+ doctype strict
19
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
20
+ ```
21
+ ```html
22
+ doctype frameset
23
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
24
+ ```
25
+ ```html
26
+ doctype 1.1
27
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
28
+ ```
29
+ ```html
30
+ doctype basic
31
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
32
+ ```
33
+ ```html
34
+ doctype mobile
35
+ <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">
36
+ ```
37
+
38
+ ## Custom Doctypes
39
+ ```html
40
+ doctype html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN"
41
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN">
42
+ ```
@@ -0,0 +1,38 @@
1
+ # Opulent Expressions
2
+
3
+ Opulent makes it possible to write inline Ruby code in your templates. There are a few types of code.
4
+
5
+ ##Unbuffered Code
6
+ Unbuffered code starts with `-` (single line) or `+` (multi line) and does not provide an output directly.
7
+
8
+ ```sass
9
+ - a = 1 + 2 + 3
10
+
11
+ + if a == 6
12
+ a = 3
13
+ end
14
+ ```
15
+
16
+ ## Buffered Code
17
+ Buffered code starts with `=` and it outputs the Ruby expression as plain text. For safety reasons, it will be escaped by default.
18
+
19
+ ```sass
20
+ p = "this is " + "an <escaped> ruby expression"
21
+ ```
22
+
23
+ ```html
24
+ <p>
25
+ this is an &lt;escaped&gt; ruby expression
26
+ </p>
27
+ ```
28
+
29
+ ## Unuffered Code
30
+ Whenever we want to unescape an output in Opulent, we use the tilde character `~` to do so.
31
+
32
+ ```sass
33
+ p =~ "this is " + "an <escaped> ruby expression"
34
+ ```
35
+
36
+ ```html
37
+ <p>this is an <escaped> ruby expression</p>
38
+ ```
@@ -0,0 +1,33 @@
1
+ # Opulent Nodes
2
+
3
+ Opulent has several node features which can be used within your views.
4
+
5
+ ## Syntax
6
+ By default, every identifier can be a node, except the few keywords that Opulent uses for itself (e.g. def, yield, if, else, etc.).
7
+ ```sass
8
+ node-name
9
+ ```
10
+ Will render as:
11
+ ```html
12
+ <node-name></node-name>
13
+ ```
14
+
15
+ The following will render the same output:
16
+ ```sass
17
+ div class="myclass"
18
+ div.myclass
19
+ .myclass
20
+ .("myclass")
21
+ ."myclass"
22
+ ```
23
+ ```html
24
+ <div class="myclass"></div>
25
+ ```
26
+
27
+ ## Inline Child Nodes
28
+ Nodes such as text can be written inline without any identifier. However, when we want to have child nodes written inline we use the `>` character.
29
+
30
+ ```sass
31
+ ul
32
+ li > a href="http://google.com" Google
33
+ ```
@@ -5,5 +5,7 @@ Opulent is an __Intelligent Web Templating Engine__ created for extremely fast a
5
5
 
6
6
  1. [Attributes](attributes.md)
7
7
  2. [Control Structures](control-structures.md)
8
- 3. [Expressions](usage.md)
9
- 4. [Comments](usage.md)
8
+ 3. [Expressions](expressions.md)
9
+ 4. [Comments](comments.md)
10
+ 5. [Doctype](doctype.md)
11
+ 5. [Nodes](nodes.md)
@@ -1,3 +1,30 @@
1
1
  # Opulent Usage
2
2
 
3
- @TODO
3
+ Opulent can be used to render a file by providing a symbol with the name of the file or to render code by providing a string input.
4
+
5
+ ```ruby
6
+ require 'opulent'
7
+
8
+ Opulent.new.render_file :index
9
+ ```
10
+
11
+ Opulent comes with a built in layout system. So if you're not using any web development framework, you'll really appreciate that.
12
+ For layouts you can simply use the following code. By default, the layout is set to __layouts/application__.
13
+
14
+ ```ruby
15
+ require 'opulent'
16
+
17
+ opulent = Opulent.new layouts: true
18
+ opulent.render_file :index, layout: :'path/to/layout'
19
+ ```
20
+
21
+ Here is a list of options you can use with opulent at the moment together with their default values.
22
+
23
+ ```ruby
24
+ options = {
25
+ indent: 2,
26
+ layouts: false,
27
+ default_layout: :'views/layouts/application'
28
+ }
29
+ opulent = Opulent.new options
30
+ ```
@@ -10,7 +10,11 @@ module Opulent
10
10
  #
11
11
  def def_node(node, indent, context)
12
12
  # Create a new definition context
13
- definition_context = Context.new
13
+ #
14
+ # @update: Added &context.block to make sure yield can be called from
15
+ # within a definition (it might be a nice feature)
16
+ #
17
+ definition_context = Context.new &context.block
14
18
  definition_context.extend_nonlocals context.binding
15
19
  definition_context.name = node[@value]
16
20
  definition_context.parent = context
@@ -16,7 +16,7 @@ module Opulent
16
16
  # @param block [Binding] Call environment block
17
17
  # @param content [Binding] Content yielding
18
18
  #
19
- def initialize(locals = {}, block, &content)
19
+ def initialize(locals = {}, block = nil, &content)
20
20
  @content = content
21
21
 
22
22
  @block = block
@@ -20,7 +20,13 @@ module Opulent
20
20
 
21
21
  # Create node
22
22
  definition = [:def, name, {parameters: attributes}, [], indent]
23
+
24
+ # Set definition as root node and let the parser know that we're inside
25
+ # a definition. This is used because inside definitions we do not process
26
+ # nodes (we do not check if they are have a definition or not).
27
+ @inside_definition = true
23
28
  root(definition, indent)
29
+ @inside_definition = false
24
30
 
25
31
  # Add to parent
26
32
  @definitions[name] = definition
@@ -80,18 +80,37 @@ module Opulent
80
80
 
81
81
  # Create a clone of the definition model. Cloning the options is also
82
82
  # necessary because it's a shallow copy
83
- if @definitions.keys.include? node_name
84
- model = @definitions[node_name].clone
85
- model[@options] = {}.merge model[@options]
86
- model[@options][:call] = current_node
87
-
88
- parent[@children] << model
83
+ if !@inside_definition && @definitions.keys.include?(node_name)
84
+ parent[@children] << process_definition(node_name, current_node)
89
85
  else
90
86
  parent[@children] << current_node
91
87
  end
92
88
  end
93
89
  end
94
90
 
91
+ # When entering a definition model, we replace all the node types with their
92
+ # know definitions at definition call time.
93
+ #
94
+ # @param node_name [Symbol] Node identifier
95
+ # @param call_context [Node] Initial node call with its attributes
96
+ #
97
+ def process_definition(node_name, call_context)
98
+ model = @definitions[node_name].clone
99
+ model[@options] = {}.merge model[@options]
100
+ model[@options][:call] = call_context
101
+
102
+ # Recursively map each child node with its definition
103
+ model[@children].map! do |child|
104
+ if @definitions.keys.include? child[@value]
105
+ process_definition child[@value], child
106
+ else
107
+ child
108
+ end
109
+ end
110
+
111
+ return model
112
+ end
113
+
95
114
  # Helper method to create an array of values when an attribute is set
96
115
  # multiple times. This happens unless the key is id, which is unique
97
116
  #
@@ -41,12 +41,11 @@ module Opulent
41
41
  class << self
42
42
  # Opulent runtime options
43
43
  Defaults = {
44
- pretty: true,
44
+ #pretty: true, # At the moment, code cannot be uglified
45
+ #dependency_manager: true, # Soon to be implemented
45
46
  indent: 2,
46
- dependency_manager: true,
47
- invert_escaping: true,
48
47
  layouts: false,
49
- default_layout: :'layouts/application'
48
+ default_layout: :'views/layouts/application'
50
49
  }
51
50
 
52
51
  # Set defaults as initial options
@@ -1,4 +1,4 @@
1
1
  # @Opulent
2
2
  module Opulent
3
- VERSION = "1.3.3"
3
+ VERSION = "1.4.0"
4
4
  end
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.3.3
4
+ version: 1.4.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-09-01 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,7 +136,11 @@ files:
136
136
  - benchmark/cases/node/node.slim
137
137
  - bin/opulent
138
138
  - docs/attributes.md
139
+ - docs/comments.md
139
140
  - docs/control-structures.md
141
+ - docs/doctype.md
142
+ - docs/expressions.md
143
+ - docs/nodes.md
140
144
  - docs/reference.md
141
145
  - docs/usage.md
142
146
  - lib/opulent.rb