bade 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Bade.gemspec +7 -6
- data/Gemfile +8 -3
- data/lib/bade/ast/node.rb +0 -1
- data/lib/bade/ast/node/mixin_node.rb +3 -3
- data/lib/bade/ast/node/static_text_node.rb +4 -2
- data/lib/bade/ast/node/value_node.rb +4 -2
- data/lib/bade/generator.rb +1 -5
- data/lib/bade/parser.rb +3 -1
- data/lib/bade/parser/parser_constants.rb +4 -4
- data/lib/bade/parser/parser_lines.rb +13 -13
- data/lib/bade/parser/parser_mixin.rb +10 -10
- data/lib/bade/parser/parser_ruby_code.rb +17 -7
- data/lib/bade/parser/parser_tag.rb +4 -4
- data/lib/bade/parser/parser_text.rb +3 -3
- data/lib/bade/precompiled.rb +6 -3
- data/lib/bade/renderer.rb +3 -0
- data/lib/bade/ruby2_keywords.rb +2 -0
- data/lib/bade/ruby_extensions/string.rb +0 -5
- data/lib/bade/runtime/block.rb +4 -2
- data/lib/bade/runtime/mixin.rb +32 -29
- data/lib/bade/version.rb +1 -1
- metadata +26 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 148aef838267196453c729800e51c4d3b1f194586f5226e00c659d8f3fc80e58
|
4
|
+
data.tar.gz: dff1e493ea8a08976cd6cdd1fc80cf937cb2582bc41630c2ca6198fc9eab5ada
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86853f78cc0d8647ab5d639664dbb12d5e7101165641d91e4afdbc2affb3cf2c5434ea85bc7f9f92cec7ed571d34a4f23dd4bc0db6eaea9522df29e986df071f
|
7
|
+
data.tar.gz: 335be41aa317132979197275b9c6fad798525af1247d2878239229e4f81b6beaac916000af24a1da0ccd61ea22ee3356127aa7a485fe806cc9385ef8945370be
|
data/Bade.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
lib = File.expand_path('
|
4
|
+
lib = File.expand_path('lib', __dir__)
|
4
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
6
|
|
6
7
|
require 'bade/version'
|
7
8
|
|
8
|
-
|
9
9
|
Gem::Specification.new do |spec|
|
10
10
|
spec.name = 'bade'
|
11
11
|
spec.version = Bade::VERSION
|
@@ -16,13 +16,14 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.license = 'MIT'
|
17
17
|
spec.required_ruby_version = '>= 2.0'
|
18
18
|
|
19
|
-
spec.files = Dir['bin/**/*'] + Dir['lib/**/*'] + %w
|
19
|
+
spec.files = Dir['bin/**/*'] + Dir['lib/**/*'] + %w[Bade.gemspec Gemfile README.md]
|
20
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
21
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.
|
24
|
+
spec.add_dependency 'psych', '>= 2.2', '< 4.0'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'rake'
|
25
27
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
26
|
-
spec.add_development_dependency '
|
27
|
-
spec.add_development_dependency 'rubocop', '~> 0.35'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 0.50.0'
|
28
29
|
end
|
data/Gemfile
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
5
|
-
gem 'coveralls', require: false
|
6
7
|
gem 'benchmark-ips', require: false
|
7
|
-
gem '
|
8
|
-
|
8
|
+
gem 'coveralls', require: false
|
9
|
+
|
10
|
+
group :banchmarks, optional: true do
|
11
|
+
gem 'flamegraph'
|
12
|
+
gem 'ruby-prof'
|
13
|
+
end
|
data/lib/bade/ast/node.rb
CHANGED
@@ -22,19 +22,19 @@ module Bade
|
|
22
22
|
|
23
23
|
class MixinDeclarationNode < MixinCommonNode
|
24
24
|
def allowed_parameter_types
|
25
|
-
[
|
25
|
+
%i[mixin_param mixin_key_param mixin_block_param]
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
class MixinBlockNode < MixinCommonNode
|
30
30
|
def allowed_parameter_types
|
31
|
-
[
|
31
|
+
%i[mixin_param mixin_key_param]
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
class MixinCallNode < MixinCommonNode
|
36
36
|
def allowed_parameter_types
|
37
|
-
[
|
37
|
+
%i[mixin_param mixin_key_param]
|
38
38
|
end
|
39
39
|
|
40
40
|
def blocks
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../../ruby2_keywords'
|
4
|
+
|
3
5
|
module Bade
|
4
6
|
module AST
|
5
7
|
class StaticTextNode < Node
|
@@ -11,8 +13,8 @@ module Bade
|
|
11
13
|
#
|
12
14
|
attr_accessor :escaped
|
13
15
|
|
14
|
-
def initialize(*args)
|
15
|
-
super
|
16
|
+
ruby2_keywords def initialize(*args)
|
17
|
+
super(*args)
|
16
18
|
|
17
19
|
@escaped = false
|
18
20
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../../ruby2_keywords'
|
4
|
+
|
3
5
|
module Bade
|
4
6
|
module AST
|
5
7
|
class ValueNode < Node
|
@@ -15,8 +17,8 @@ module Bade
|
|
15
17
|
#
|
16
18
|
attr_accessor :conditional
|
17
19
|
|
18
|
-
def initialize(*args)
|
19
|
-
super
|
20
|
+
ruby2_keywords def initialize(*args)
|
21
|
+
super(*args)
|
20
22
|
|
21
23
|
@escaped = false
|
22
24
|
@conditional = false
|
data/lib/bade/generator.rb
CHANGED
@@ -78,7 +78,6 @@ module Bade
|
|
78
78
|
@buff << ' ' * @code_indent + text
|
79
79
|
end
|
80
80
|
|
81
|
-
|
82
81
|
# @param document [Bade::Document]
|
83
82
|
#
|
84
83
|
def visit_document(document)
|
@@ -158,8 +157,7 @@ module Bade
|
|
158
157
|
buff_print_text output_code
|
159
158
|
|
160
159
|
when :newline
|
161
|
-
#
|
162
|
-
|
160
|
+
# no-op
|
163
161
|
when :import
|
164
162
|
base_path = File.expand_path(current_node.value, File.dirname(@document.file_path))
|
165
163
|
load_path = if base_path.end_with?('.rb') && File.exist?(base_path)
|
@@ -362,8 +360,6 @@ module Bade
|
|
362
360
|
buff_code '})'
|
363
361
|
end
|
364
362
|
|
365
|
-
|
366
|
-
|
367
363
|
# @param [String] str
|
368
364
|
#
|
369
365
|
# @return [Void]
|
data/lib/bade/parser.rb
CHANGED
@@ -126,7 +126,9 @@ module Bade
|
|
126
126
|
|
127
127
|
def parse_import
|
128
128
|
# TODO: change this to something better
|
129
|
-
|
129
|
+
# rubocop:disable Security/Eval
|
130
|
+
path = eval(@line)
|
131
|
+
# rubocop:enable Security/Eval
|
130
132
|
append_node(:import, value: path)
|
131
133
|
|
132
134
|
@dependency_paths << path unless @dependency_paths.include?(path)
|
@@ -9,10 +9,10 @@ module Bade
|
|
9
9
|
NAME_RE_STRING = "(#{WORD_RE}(?:#{WORD_RE}|:|-|_)*)".freeze
|
10
10
|
|
11
11
|
ATTR_NAME_RE_STRING = "\\A\\s*#{NAME_RE_STRING}".freeze
|
12
|
-
CODE_ATTR_RE = /#{ATTR_NAME_RE_STRING}\s*&?:\s
|
12
|
+
CODE_ATTR_RE = /#{ATTR_NAME_RE_STRING}\s*&?:\s*/.freeze
|
13
13
|
|
14
|
-
TAG_RE = /\A#{NAME_RE_STRING}
|
15
|
-
CLASS_TAG_RE = /\A\.#{NAME_RE_STRING}
|
16
|
-
ID_TAG_RE = /\A##{NAME_RE_STRING}
|
14
|
+
TAG_RE = /\A#{NAME_RE_STRING}/.freeze
|
15
|
+
CLASS_TAG_RE = /\A\.#{NAME_RE_STRING}/.freeze
|
16
|
+
ID_TAG_RE = /\A##{NAME_RE_STRING}/.freeze
|
17
17
|
end
|
18
18
|
end
|
@@ -6,19 +6,19 @@ module Bade
|
|
6
6
|
|
7
7
|
class Parser
|
8
8
|
module LineIndicatorRegexps
|
9
|
-
IMPORT = /\Aimport
|
10
|
-
MIXIN_DECL = /\Amixin #{NAME_RE_STRING}
|
11
|
-
MIXIN_CALL = /\A\+#{NAME_RE_STRING}
|
12
|
-
BLOCK_DECLARATION = /\Ablock #{NAME_RE_STRING}
|
13
|
-
HTML_COMMENT = %r{\A//! }
|
14
|
-
NORMAL_COMMENT = %r{\A//}
|
15
|
-
TEXT_BLOCK_START = /\A\|( ?)
|
16
|
-
INLINE_HTML = /\A
|
17
|
-
CODE_BLOCK = /\A
|
18
|
-
OUTPUT_BLOCK = /\A(\??)(&?)
|
19
|
-
DOCTYPE = /\Adoctype\s/i
|
20
|
-
TAG_CLASS_START_BLOCK = /\A
|
21
|
-
TAG_ID_START_BLOCK = /\A
|
9
|
+
IMPORT = /\Aimport /.freeze
|
10
|
+
MIXIN_DECL = /\Amixin #{NAME_RE_STRING}/.freeze
|
11
|
+
MIXIN_CALL = /\A\+#{NAME_RE_STRING}/.freeze
|
12
|
+
BLOCK_DECLARATION = /\Ablock #{NAME_RE_STRING}/.freeze
|
13
|
+
HTML_COMMENT = %r{\A//! }.freeze
|
14
|
+
NORMAL_COMMENT = %r{\A//}.freeze
|
15
|
+
TEXT_BLOCK_START = /\A\|( ?)/.freeze
|
16
|
+
INLINE_HTML = /\A</.freeze
|
17
|
+
CODE_BLOCK = /\A-/.freeze
|
18
|
+
OUTPUT_BLOCK = /\A(\??)(&?)=/.freeze
|
19
|
+
DOCTYPE = /\Adoctype\s/i.freeze
|
20
|
+
TAG_CLASS_START_BLOCK = /\A\./.freeze
|
21
|
+
TAG_ID_START_BLOCK = /\A#/.freeze
|
22
22
|
end
|
23
23
|
|
24
24
|
def reset(lines = nil, stacks = nil)
|
@@ -6,17 +6,17 @@ module Bade
|
|
6
6
|
|
7
7
|
class Parser
|
8
8
|
module MixinRegexps
|
9
|
-
TEXT_START = /\A
|
10
|
-
BLOCK_EXPANSION = /\A:\s
|
11
|
-
OUTPUT_CODE = /\A(&?)
|
9
|
+
TEXT_START = /\A /.freeze
|
10
|
+
BLOCK_EXPANSION = /\A:\s+/.freeze
|
11
|
+
OUTPUT_CODE = /\A(&?)=/.freeze
|
12
12
|
|
13
|
-
PARAMS_END = /\A\s*\)
|
13
|
+
PARAMS_END = /\A\s*\)/.freeze
|
14
14
|
|
15
|
-
PARAMS_END_SPACES = /^\s
|
16
|
-
PARAMS_ARGS_DELIMITER = /\A\s
|
15
|
+
PARAMS_END_SPACES = /^\s*$/.freeze
|
16
|
+
PARAMS_ARGS_DELIMITER = /\A\s*,/.freeze
|
17
17
|
|
18
|
-
PARAMS_PARAM_NAME = /\A\s*#{NAME_RE_STRING}
|
19
|
-
PARAMS_BLOCK_NAME = /\A\s*&#{NAME_RE_STRING}
|
18
|
+
PARAMS_PARAM_NAME = /\A\s*#{NAME_RE_STRING}/.freeze
|
19
|
+
PARAMS_BLOCK_NAME = /\A\s*&#{NAME_RE_STRING}/.freeze
|
20
20
|
PARAMS_KEY_PARAM_NAME = CODE_ATTR_RE
|
21
21
|
end
|
22
22
|
|
@@ -64,7 +64,7 @@ module Bade
|
|
64
64
|
@line = $'
|
65
65
|
attr_node = append_node(:mixin_key_param)
|
66
66
|
attr_node.name = fixed_trailing_colon($1)
|
67
|
-
attr_node.value = parse_ruby_code(ParseRubyCodeRegexps::END_PARAMS_ARG)
|
67
|
+
attr_node.value = parse_ruby_code(ParseRubyCodeRegexps::END_PARAMS_ARG, allow_multiline: true)
|
68
68
|
|
69
69
|
when MixinRegexps::PARAMS_ARGS_DELIMITER
|
70
70
|
# args delimiter
|
@@ -83,7 +83,7 @@ module Bade
|
|
83
83
|
|
84
84
|
else
|
85
85
|
attr_node = append_node(:mixin_param)
|
86
|
-
attr_node.value = parse_ruby_code(ParseRubyCodeRegexps::END_PARAMS_ARG)
|
86
|
+
attr_node.value = parse_ruby_code(ParseRubyCodeRegexps::END_PARAMS_ARG, allow_multiline: true)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -6,8 +6,8 @@ module Bade
|
|
6
6
|
|
7
7
|
class Parser
|
8
8
|
module ParseRubyCodeRegexps
|
9
|
-
END_NEW_LINE = /\A\s*\n
|
10
|
-
END_PARAMS_ARG = /\A\s*[,)]
|
9
|
+
END_NEW_LINE = /\A\s*\n/.freeze
|
10
|
+
END_PARAMS_ARG = /\A\s*[,)]/.freeze
|
11
11
|
end
|
12
12
|
|
13
13
|
# Parse ruby code, ended with outer delimiters
|
@@ -16,17 +16,27 @@ module Bade
|
|
16
16
|
#
|
17
17
|
# @return [Void] parsed ruby code
|
18
18
|
#
|
19
|
-
def parse_ruby_code(outer_delimiters)
|
19
|
+
def parse_ruby_code(outer_delimiters, allow_multiline: false)
|
20
20
|
code = String.new
|
21
21
|
end_re = if outer_delimiters.is_a?(Regexp)
|
22
22
|
outer_delimiters
|
23
23
|
else
|
24
24
|
/\A\s*[#{Regexp.escape outer_delimiters.to_s}]/
|
25
25
|
end
|
26
|
+
|
26
27
|
delimiters = []
|
27
28
|
string_start_quote_char = nil
|
28
29
|
|
29
|
-
|
30
|
+
loop do
|
31
|
+
break if !allow_multiline && @line.empty?
|
32
|
+
break if allow_multiline && @line.empty? && (@lines && @lines.empty?)
|
33
|
+
break if delimiters.empty? && @line =~ end_re
|
34
|
+
|
35
|
+
if @line.empty? && allow_multiline && !(@lines && @lines.empty?)
|
36
|
+
next_line
|
37
|
+
code << "\n"
|
38
|
+
end
|
39
|
+
|
30
40
|
char = @line[0]
|
31
41
|
|
32
42
|
# backslash escaped delimiter
|
@@ -70,7 +80,7 @@ module Bade
|
|
70
80
|
'{' => '}',
|
71
81
|
}.freeze
|
72
82
|
|
73
|
-
RUBY_QUOTES = %w
|
83
|
+
RUBY_QUOTES = %w[' "].freeze
|
74
84
|
|
75
85
|
RUBY_NOT_NESTABLE_DELIMITERS = RUBY_QUOTES
|
76
86
|
|
@@ -78,7 +88,7 @@ module Bade
|
|
78
88
|
RUBY_END_DELIMITERS = (%w(\) ] }) + RUBY_NOT_NESTABLE_DELIMITERS).freeze
|
79
89
|
RUBY_ALL_DELIMITERS = (RUBY_START_DELIMITERS + RUBY_END_DELIMITERS).uniq.freeze
|
80
90
|
|
81
|
-
RUBY_START_DELIMITERS_RE = /\A[#{Regexp.escape RUBY_START_DELIMITERS.join}]
|
82
|
-
RUBY_END_DELIMITERS_RE = /\A[#{Regexp.escape RUBY_END_DELIMITERS.join}]
|
91
|
+
RUBY_START_DELIMITERS_RE = /\A[#{Regexp.escape RUBY_START_DELIMITERS.join}]/.freeze
|
92
|
+
RUBY_END_DELIMITERS_RE = /\A[#{Regexp.escape RUBY_END_DELIMITERS.join}]/.freeze
|
83
93
|
end
|
84
94
|
end
|
@@ -6,12 +6,12 @@ module Bade
|
|
6
6
|
|
7
7
|
class Parser
|
8
8
|
module TagRegexps
|
9
|
-
BLOCK_EXPANSION = /\A:\s
|
9
|
+
BLOCK_EXPANSION = /\A:\s+/.freeze
|
10
10
|
OUTPUT_CODE = LineIndicatorRegexps::OUTPUT_BLOCK
|
11
|
-
TEXT_START = /\A
|
11
|
+
TEXT_START = /\A /.freeze
|
12
12
|
|
13
|
-
PARAMS_ARGS_DELIMITER = /\A\s
|
14
|
-
PARAMS_END = /\A\s*\)
|
13
|
+
PARAMS_ARGS_DELIMITER = /\A\s*,/.freeze
|
14
|
+
PARAMS_END = /\A\s*\)/.freeze
|
15
15
|
end
|
16
16
|
|
17
17
|
# @param [String] tag tag name
|
@@ -6,8 +6,8 @@ module Bade
|
|
6
6
|
|
7
7
|
class Parser
|
8
8
|
module TextRegexps
|
9
|
-
INTERPOLATION_START = /(\\)?(&|#)\{
|
10
|
-
INTERPOLATION_END = /\A\}
|
9
|
+
INTERPOLATION_START = /(\\)?(&|#)\{/.freeze
|
10
|
+
INTERPOLATION_END = /\A\}/.freeze
|
11
11
|
end
|
12
12
|
|
13
13
|
def parse_text
|
@@ -64,7 +64,7 @@ module Bade
|
|
64
64
|
|
65
65
|
next_line
|
66
66
|
|
67
|
-
@line.remove_indent!(text_indent
|
67
|
+
@line.remove_indent!(text_indent || indent, @tabsize)
|
68
68
|
|
69
69
|
parse_text
|
70
70
|
|
data/lib/bade/precompiled.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
3
|
+
require 'psych'
|
5
4
|
|
6
5
|
module Bade
|
7
6
|
class Precompiled
|
@@ -26,7 +25,11 @@ module Bade
|
|
26
25
|
file
|
27
26
|
end
|
28
27
|
|
29
|
-
hash =
|
28
|
+
hash = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.0')
|
29
|
+
YAML.safe_load(file, filename: file.path, permitted_classes: [Symbol])
|
30
|
+
else
|
31
|
+
YAML.safe_load(file, [Symbol])
|
32
|
+
end
|
30
33
|
raise LoadError, 'YAML file is not in valid format' unless hash.is_a?(Hash)
|
31
34
|
|
32
35
|
file_path = hash[:source_file_path]
|
data/lib/bade/renderer.rb
CHANGED
@@ -164,9 +164,11 @@ module Bade
|
|
164
164
|
|
165
165
|
# @return [RenderBinding]
|
166
166
|
#
|
167
|
+
# rubocop:disable Lint/DuplicateMethods
|
167
168
|
def render_binding
|
168
169
|
@render_binding ||= Runtime::RenderBinding.new(locals || {})
|
169
170
|
end
|
171
|
+
# rubocop:enable Lint/DuplicateMethods
|
170
172
|
|
171
173
|
# @return [Proc]
|
172
174
|
#
|
@@ -249,6 +251,7 @@ module Bade
|
|
249
251
|
|
250
252
|
if File.exist?(sub_path)
|
251
253
|
return if sub_path.end_with?('.rb') # handled in Generator
|
254
|
+
|
252
255
|
sub_path
|
253
256
|
else
|
254
257
|
bade_path = "#{sub_path}.bade"
|
@@ -13,12 +13,10 @@ class String
|
|
13
13
|
%('#{self}')
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
16
|
def blank?
|
18
17
|
strip.empty?
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
20
|
def remove_last(count = 1)
|
23
21
|
slice(0, length - count)
|
24
22
|
end
|
@@ -27,7 +25,6 @@ class String
|
|
27
25
|
slice!(length - count, count)
|
28
26
|
end
|
29
27
|
|
30
|
-
|
31
28
|
def remove_first(count = 1)
|
32
29
|
slice(count, length - count)
|
33
30
|
end
|
@@ -67,7 +64,6 @@ class String
|
|
67
64
|
remove_first(__chars_count_for_indent(indent, tabsize))
|
68
65
|
end
|
69
66
|
|
70
|
-
|
71
67
|
# Remove indent
|
72
68
|
#
|
73
69
|
# @param [Int] indent
|
@@ -77,7 +73,6 @@ class String
|
|
77
73
|
remove_first!(__chars_count_for_indent(indent, tabsize))
|
78
74
|
end
|
79
75
|
|
80
|
-
|
81
76
|
# Calculate indent for line
|
82
77
|
#
|
83
78
|
# @param [Int] tabsize
|
data/lib/bade/runtime/block.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../ruby2_keywords'
|
4
|
+
|
3
5
|
module Bade
|
4
6
|
module Runtime
|
5
7
|
class RuntimeError < ::StandardError; end
|
@@ -52,11 +54,11 @@ module Bade
|
|
52
54
|
|
53
55
|
# --- Calling methods
|
54
56
|
|
55
|
-
def call(*args)
|
57
|
+
ruby2_keywords def call(*args)
|
56
58
|
call!(*args) unless @block.nil?
|
57
59
|
end
|
58
60
|
|
59
|
-
def call!(*args)
|
61
|
+
ruby2_keywords def call!(*args)
|
60
62
|
raise MissingBlockDefinitionError.new(name, :call) if @block.nil?
|
61
63
|
|
62
64
|
render_binding.__buff.concat(@block.call(*args))
|
data/lib/bade/runtime/mixin.rb
CHANGED
@@ -1,43 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../ruby2_keywords'
|
4
|
+
|
3
5
|
module Bade
|
4
6
|
module Runtime
|
5
7
|
require_relative 'block'
|
6
8
|
|
7
9
|
class Mixin < Block
|
8
|
-
def call!(blocks, *args)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# minus one, because first argument is always hash of blocks
|
17
|
-
given = $1.to_i - 1
|
18
|
-
expected = $2.to_i - 1
|
19
|
-
raise ArgumentError, "wrong number of arguments (given #{given}, expected #{expected}) for mixin `#{name}`"
|
10
|
+
ruby2_keywords def call!(blocks, *args)
|
11
|
+
begin
|
12
|
+
block.call(blocks, *args)
|
13
|
+
rescue ArgumentError => e
|
14
|
+
case e.message
|
15
|
+
when /\Awrong number of arguments \(given ([0-9]+), expected ([0-9]+)\)\Z/,
|
16
|
+
/\Awrong number of arguments \(([0-9]+) for ([0-9]+)\)\Z/
|
17
|
+
# handle incorrect parameters count
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
# minus one, because first argument is always hash of blocks
|
20
|
+
given = $1.to_i - 1
|
21
|
+
expected = $2.to_i - 1
|
22
|
+
raise ArgumentError, "wrong number of arguments (given #{given}, expected #{expected}) for mixin `#{name}`"
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
when /\Aunknown keyword: (.*)\Z/
|
25
|
+
# handle unknown key-value parameter
|
26
|
+
key_name = $1
|
27
|
+
raise ArgumentError, "unknown key-value argument `#{key_name}` for mixin `#{name}`"
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
else
|
30
|
+
raise
|
31
|
+
end
|
32
|
+
rescue Block::MissingBlockDefinitionError => e
|
33
|
+
msg = case e.context
|
34
|
+
when :call
|
35
|
+
"Mixin `#{name}` requires block to get called of block `#{e.name}`"
|
36
|
+
when :render
|
37
|
+
"Mixin `#{name}` requires block to get rendered content of block `#{e.name}`"
|
38
|
+
else
|
39
|
+
raise ::ArgumentError, "Unknown context #{e.context} of error #{e}!"
|
40
|
+
end
|
39
41
|
|
40
|
-
|
42
|
+
raise Block::MissingBlockDefinitionError.new(e.name, e.context, msg)
|
43
|
+
end
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
data/lib/bade/version.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Kříž
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: psych
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
|
19
|
+
version: '2.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.0'
|
23
|
+
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '2.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- - "
|
37
|
+
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
39
|
+
version: '0'
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
|
-
- - "
|
44
|
+
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
46
|
+
version: '0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: rspec
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '3.2'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '3.2'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rubocop
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
67
|
+
version: 0.50.0
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
74
|
+
version: 0.50.0
|
69
75
|
description:
|
70
76
|
email:
|
71
77
|
- samnung@gmail.com
|
@@ -98,6 +104,7 @@ files:
|
|
98
104
|
- lib/bade/parser/parser_text.rb
|
99
105
|
- lib/bade/precompiled.rb
|
100
106
|
- lib/bade/renderer.rb
|
107
|
+
- lib/bade/ruby2_keywords.rb
|
101
108
|
- lib/bade/ruby_extensions/array.rb
|
102
109
|
- lib/bade/ruby_extensions/string.rb
|
103
110
|
- lib/bade/runtime.rb
|
@@ -124,8 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
131
|
- !ruby/object:Gem::Version
|
125
132
|
version: '0'
|
126
133
|
requirements: []
|
127
|
-
|
128
|
-
rubygems_version: 2.7.7
|
134
|
+
rubygems_version: 3.1.2
|
129
135
|
signing_key:
|
130
136
|
specification_version: 4
|
131
137
|
summary: Minimalistic template engine for Ruby.
|