bade 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Bade.gemspec +1 -0
- data/Gemfile +3 -0
- data/README.md +3 -2
- data/lib/bade.rb +1 -0
- data/lib/bade/ast/document.rb +53 -0
- data/lib/bade/ast/node.rb +50 -0
- data/lib/bade/ast/node/doctype_node.rb +25 -0
- data/lib/bade/ast/node/key_value_node.rb +21 -0
- data/lib/bade/ast/node/mixin_node.rb +45 -0
- data/lib/bade/ast/node/tag_node.rb +23 -0
- data/lib/bade/ast/node/value_node.rb +32 -0
- data/lib/bade/ast/node_registrator.rb +82 -0
- data/lib/bade/ast/string_serializer.rb +72 -0
- data/lib/bade/generator.rb +353 -6
- data/lib/bade/parser.rb +199 -129
- data/lib/bade/precompiled.rb +61 -0
- data/lib/bade/renderer.rb +151 -31
- data/lib/bade/ruby_extensions/array.rb +45 -0
- data/lib/bade/ruby_extensions/string.rb +50 -20
- data/lib/bade/runtime.rb +2 -0
- data/lib/bade/runtime/block.rb +56 -10
- data/lib/bade/runtime/mixin.rb +43 -0
- data/lib/bade/runtime/render_binding.rb +53 -9
- data/lib/bade/version.rb +2 -1
- metadata +16 -14
- data/lib/bade/document.rb +0 -33
- data/lib/bade/generator/html_generator.rb +0 -80
- data/lib/bade/generator/ruby_generator.rb +0 -336
- data/lib/bade/node.rb +0 -116
- data/lib/bade/node/doctype_node.rb +0 -21
- data/lib/bade/node/key_value_node.rb +0 -10
- data/lib/bade/node/mixin_node.rb +0 -69
- data/lib/bade/node/tag_node.rb +0 -29
- data/lib/bade/ruby_extensions/object.rb +0 -11
data/lib/bade/node.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative 'parser'
|
3
|
-
require_relative 'ruby_extensions/object'
|
4
|
-
|
5
|
-
|
6
|
-
module Bade
|
7
|
-
class Node
|
8
|
-
require_relative 'node/key_value_node'
|
9
|
-
require_relative 'node/tag_node'
|
10
|
-
require_relative 'node/mixin_node'
|
11
|
-
require_relative 'node/doctype_node'
|
12
|
-
|
13
|
-
# @return [Symbol]
|
14
|
-
#
|
15
|
-
attr_reader :type
|
16
|
-
|
17
|
-
|
18
|
-
# @return [Int] line number
|
19
|
-
#
|
20
|
-
attr_accessor :lineno
|
21
|
-
|
22
|
-
# @return [String]
|
23
|
-
#
|
24
|
-
attr_accessor :data
|
25
|
-
|
26
|
-
|
27
|
-
# @return [Node]
|
28
|
-
#
|
29
|
-
attr_accessor :parent
|
30
|
-
|
31
|
-
# @return [Array<Node>]
|
32
|
-
#
|
33
|
-
attr_accessor :childrens
|
34
|
-
|
35
|
-
# @return [TrueClass, FalseClass]
|
36
|
-
#
|
37
|
-
attr_accessor :escaped
|
38
|
-
|
39
|
-
# @param [Symbol] type
|
40
|
-
# @param [Node] parent
|
41
|
-
#
|
42
|
-
def initialize(type, parent = nil)
|
43
|
-
@type = type
|
44
|
-
@childrens = []
|
45
|
-
|
46
|
-
if parent
|
47
|
-
parent << self
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# @param [Node] node
|
52
|
-
#
|
53
|
-
def << (node)
|
54
|
-
node.parent = self
|
55
|
-
@childrens << node
|
56
|
-
|
57
|
-
self
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
# @return [Hash<Symbol, Class>]
|
65
|
-
def self.registered_types
|
66
|
-
@@registered_types ||= {}
|
67
|
-
end
|
68
|
-
|
69
|
-
# @param [Symbol] type
|
70
|
-
# @param [Class] klass registering class
|
71
|
-
#
|
72
|
-
def self.register_type(type, klass = self)
|
73
|
-
raise StandardError, "Class #{klass} should be subclass of #{self}" unless klass <= Node
|
74
|
-
|
75
|
-
registered_types[type] = klass
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
def self.create(type, parent)
|
82
|
-
klass = registered_types[type]
|
83
|
-
|
84
|
-
if klass.nil?
|
85
|
-
raise Parser::ParserInternalError, "undefined node type #{type.inspect}"
|
86
|
-
end
|
87
|
-
|
88
|
-
klass.new(type, parent)
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
Node.register_type :text
|
94
|
-
Node.register_type :newline
|
95
|
-
Node.register_type :ruby_code
|
96
|
-
|
97
|
-
Node.register_type :comment
|
98
|
-
Node.register_type :html_comment
|
99
|
-
|
100
|
-
TagNode.register_type :tag
|
101
|
-
KeyValueNode.register_type :tag_attribute
|
102
|
-
|
103
|
-
Node.register_type :output
|
104
|
-
|
105
|
-
Node.register_type :mixin_param
|
106
|
-
Node.register_type :mixin_block_param
|
107
|
-
Node.register_type :mixin_block
|
108
|
-
|
109
|
-
MixinCallNode.register_type :mixin_call
|
110
|
-
MixinDeclarationNode.register_type :mixin_declaration
|
111
|
-
KeyValueNode.register_type :mixin_key_param
|
112
|
-
|
113
|
-
DoctypeNode.register_type :doctype
|
114
|
-
|
115
|
-
Node.register_type :import
|
116
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative '../node'
|
2
|
-
|
3
|
-
|
4
|
-
module Bade
|
5
|
-
class DoctypeNode < Node
|
6
|
-
# @return [String]
|
7
|
-
#
|
8
|
-
def xml_output
|
9
|
-
case self.data
|
10
|
-
when 'xml'
|
11
|
-
'<?xml version="1.0" encoding="utf-8" ?>'
|
12
|
-
|
13
|
-
when 'html'
|
14
|
-
'<!DOCTYPE html>'
|
15
|
-
|
16
|
-
else
|
17
|
-
raise Parser::ParserInternalError 'Unknown doctype type'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/bade/node/mixin_node.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require_relative '../node'
|
2
|
-
|
3
|
-
|
4
|
-
module Bade
|
5
|
-
class MixinCommonNode < Node
|
6
|
-
|
7
|
-
# @return [Array<Node>]
|
8
|
-
#
|
9
|
-
attr_reader :params
|
10
|
-
|
11
|
-
def initialize(*args)
|
12
|
-
super
|
13
|
-
|
14
|
-
@params = []
|
15
|
-
end
|
16
|
-
|
17
|
-
def << (node)
|
18
|
-
if allowed_parameter_types.include?(node.type)
|
19
|
-
node.parent = self
|
20
|
-
@params << node
|
21
|
-
else
|
22
|
-
super
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class MixinDeclarationNode < MixinCommonNode
|
28
|
-
def allowed_parameter_types
|
29
|
-
[:mixin_param, :mixin_key_param, :mixin_block_param]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class MixinCallNode < MixinCommonNode
|
34
|
-
attr_reader :blocks
|
35
|
-
|
36
|
-
attr_reader :default_block
|
37
|
-
|
38
|
-
def initialize(*args)
|
39
|
-
super
|
40
|
-
|
41
|
-
@blocks = []
|
42
|
-
end
|
43
|
-
|
44
|
-
def allowed_parameter_types
|
45
|
-
[:mixin_param, :mixin_key_param]
|
46
|
-
end
|
47
|
-
|
48
|
-
def << (node)
|
49
|
-
if allowed_parameter_types.include?(node.type)
|
50
|
-
node.parent = self
|
51
|
-
@params << node
|
52
|
-
elsif node.type == :mixin_block
|
53
|
-
node.parent = self
|
54
|
-
@blocks << node
|
55
|
-
else
|
56
|
-
if @default_block.nil?
|
57
|
-
if node.type == :newline
|
58
|
-
# skip newlines at start
|
59
|
-
return self
|
60
|
-
end
|
61
|
-
|
62
|
-
@default_block = Node.create(:mixin_block, self)
|
63
|
-
end
|
64
|
-
|
65
|
-
@default_block << node
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/lib/bade/node/tag_node.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require_relative '../node'
|
2
|
-
|
3
|
-
|
4
|
-
module Bade
|
5
|
-
class TagNode < Node
|
6
|
-
attr_forw_accessor :name, :data
|
7
|
-
|
8
|
-
# @return [Array<TagAttributeNode>]
|
9
|
-
#
|
10
|
-
attr_reader :attributes
|
11
|
-
|
12
|
-
def initialize(*args)
|
13
|
-
super(*args)
|
14
|
-
|
15
|
-
@attributes = []
|
16
|
-
end
|
17
|
-
|
18
|
-
# @param [Node] node
|
19
|
-
#
|
20
|
-
def << (node)
|
21
|
-
if node.type == :tag_attribute
|
22
|
-
node.parent = self
|
23
|
-
@attributes << node
|
24
|
-
else
|
25
|
-
super
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|