bade 0.3.9 → 0.3.11

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
  SHA256:
3
- metadata.gz: 73d88fecdae76de6653aa57c44576f3ce21bee35ac62eb242a8b57780e5a68af
4
- data.tar.gz: 25d7ff84bb953fbd393c0fa2831f768a27e6d6487547c7551e750758170aefee
3
+ metadata.gz: a8686ad9e6c2c1ef1c752a2dc0e05e12b7e2ee30bfe7d4eb8ffc5256ed8a1594
4
+ data.tar.gz: 47516ba228a2111cdd8e966e468ba1bd5b02e905f9b0042bb96dd84299f737eb
5
5
  SHA512:
6
- metadata.gz: 7d03cef22b6ed6fcb6beeb8fbb19c5e0b0ff164f063083e78c7d5e92da5c7777c98b94e32fab62fc12a0bf3326c607e3d127901b18ec3ae502546d39052a5076
7
- data.tar.gz: aa449b5351d9adb774b9ed101e1063cbe76bacf4ea82f2718a78547cbc69945ab640bc9c5d6c7044c9bb741eb519075416710aabfab6f197826ca2c28fc01f1d
6
+ metadata.gz: 1852993735fd0917d23e1fb73922bef6df9263d69f93f3c68109bd29bc6d0c2d94c56e385ed8e8d779b7fb64dd69a0b2631b2d5f3bbbad3602cb41bafa96b2ec
7
+ data.tar.gz: deea59751038b074cc1f20791b4f8f19cc6b0ed8dad026ceec4c0341d9c34f0526b56f817ebd006943528ed9d8b8580ccf0b86f14ce980d850458f44a6a8dde8
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  gem 'benchmark-ips', require: false
8
+ gem 'rake', '~> 13.0'
8
9
 
9
10
  group :dev, optional: true do
10
11
  gem 'debase', require: false
@@ -14,7 +14,7 @@ module Bade
14
14
 
15
15
  DEFAULT_BLOCK_NAME = 'default_block'.freeze
16
16
 
17
- REQUIRE_RELATIVE_REGEX = /require_relative\s+(['"])(.+)['"]/
17
+ REQUIRE_RELATIVE_REGEX = /require_relative\s+(['"])(.+)['"]/.freeze
18
18
 
19
19
  # @param [Document] document
20
20
  #
@@ -361,7 +361,9 @@ module Bade
361
361
  #
362
362
  def visit_block_decl(current_node)
363
363
  params = formatted_mixin_params(current_node)
364
- buff_code "#{MIXINS_NAME}['#{current_node.name}'] = __create_mixin('#{current_node.name}', #{location_node(current_node)}, &lambda { |#{params}|"
364
+
365
+ buff_code "#{MIXINS_NAME}['#{current_node.name}'] = __create_mixin(" \
366
+ "'#{current_node.name}', #{location_node(current_node)}, &lambda { |#{params}|"
365
367
 
366
368
  code_indent do
367
369
  blocks_name_declaration(current_node)
@@ -386,7 +388,7 @@ module Bade
386
388
  when :code
387
389
  value = node.value.strip
388
390
 
389
- %w[end else }].include?(value) || value.match(/^(when|elsif) /) || value.match(/^\./)
391
+ value.match(/^(end|else|\}|class)\b/) || value.match(/^(when|elsif) /) || value.match(/^\./)
390
392
  when :newline
391
393
  true
392
394
  else
@@ -438,7 +440,7 @@ module Bade
438
440
  quote = Regexp.last_match[1]
439
441
  relative_path = Regexp.last_match[2]
440
442
 
441
- should_not_process = quote === '"' && relative_path.include?('#{')
443
+ should_not_process = quote == '"' && relative_path.include?('#{')
442
444
 
443
445
  new_relative_path = relative_path
444
446
  unless should_not_process
@@ -19,11 +19,7 @@ module Bade
19
19
  # @param [String, File] file file instance or path to file
20
20
  #
21
21
  def self.from_yaml_file(file)
22
- file = if file.is_a?(String)
23
- File.new(file, 'r')
24
- else
25
- file
26
- end
22
+ file = File.new(file, 'r') if file.is_a?(String)
27
23
 
28
24
  hash = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.0')
29
25
  Psych.safe_load(file, filename: file.path, permitted_classes: [Symbol])
@@ -48,11 +44,7 @@ module Bade
48
44
  # @param [String, File] file file instance or path to file
49
45
  #
50
46
  def write_yaml_to_file(file)
51
- file = if file.is_a?(String)
52
- File.new(file, 'w')
53
- else
54
- file
55
- end
47
+ file = File.new(file, 'w') if file.is_a?(String)
56
48
 
57
49
  content = {
58
50
  source_file_path: source_file_path,
data/lib/bade/renderer.rb CHANGED
@@ -40,7 +40,8 @@ module Bade
40
40
  attr_accessor :clear_constants
41
41
  end
42
42
 
43
- # @param clear_constants [Boolean] When set to true it will remove all constants that template created. Off by default.
43
+ # @param clear_constants [Boolean] When set to true it will remove all constants that template created.
44
+ # Off by default.
44
45
  def initialize(clear_constants: Bade::Renderer.clear_constants)
45
46
  @optimize = false
46
47
  @clear_constants = clear_constants
@@ -231,7 +232,7 @@ module Bade
231
232
  end
232
233
  rescue Bade::Runtime::RuntimeError => e
233
234
  raise e
234
- rescue Exception => e
235
+ rescue Exception => e # rubocop:disable Lint/RescueException
235
236
  msg = "Exception raised during execution of template: #{e}"
236
237
  raise Bade::Runtime::RuntimeError.wrap_existing_error(msg, e, render_binding.__location_stack)
237
238
  ensure
@@ -251,11 +252,7 @@ module Bade
251
252
  raise LoadError.new(nil, file_path, "Don't know what to do with nil values for both content and path")
252
253
  end
253
254
 
254
- content = if !file_path.nil? && content.nil?
255
- File.read(file_path)
256
- else
257
- content
258
- end
255
+ content = File.read(file_path) if !file_path.nil? && content.nil?
259
256
 
260
257
  parsed_document = parsed_documents[file_path]
261
258
  return parsed_document unless parsed_document.nil?
@@ -2,16 +2,14 @@
2
2
 
3
3
  unless Object.respond_to?(:const_source_location)
4
4
  class Object
5
- def Object.const_source_location(name)
5
+ def self.const_source_location(name)
6
6
  require_relative 'utils/where'
7
7
 
8
8
  konst = const_get(name)
9
9
  is_meta = konst.is_a?(Module) || konst.is_a?(Class)
10
- if is_meta
11
- Bade.where_is(konst)
12
- else
13
- nil
14
- end
10
+ return unless is_meta
11
+
12
+ Bade.where_is(konst)
15
13
  end
16
14
  end
17
15
  end
@@ -74,7 +72,7 @@ module Bade
74
72
 
75
73
  def clear_global_variables
76
74
  @caught_variables.each do |name|
77
- eval("#{name} = nil", binding, __FILE__, __LINE__)
75
+ eval("#{name} = nil", binding, __FILE__, __LINE__) # rubocop:disable Security/Eval
78
76
  end
79
77
  end
80
78
 
@@ -48,11 +48,9 @@ module Bade
48
48
  end
49
49
 
50
50
  raise Block::MissingBlockDefinitionError.new(e.name, e.context, msg, render_binding.__location_stack)
51
-
52
51
  rescue RuntimeError
53
52
  raise
54
-
55
- rescue Exception => e
53
+ rescue Exception => e # rubocop:disable Lint/RescueException
56
54
  msg = "Exception raised during execution of mixin `#{name}`: #{e}"
57
55
  raise Bade::Runtime::RuntimeError.wrap_existing_error(msg, e, render_binding.__location_stack)
58
56
  end
@@ -44,7 +44,9 @@ module Bade
44
44
  def __reset
45
45
  @__buffs_stack = []
46
46
  @__location_stack = []
47
- @__mixins = Hash.new { |_hash, key| raise Bade::Runtime::KeyError.new("Undefined mixin '#{key}'", __location_stack) }
47
+ @__mixins = Hash.new do |_hash, key|
48
+ raise Bade::Runtime::KeyError.new("Undefined mixin '#{key}'", __location_stack)
49
+ end
48
50
  end
49
51
 
50
52
  # @return [Binding]
@@ -123,7 +125,10 @@ module Bade
123
125
  end
124
126
 
125
127
  def __tag_render_attribute(name, *values)
126
- values = values.compact
128
+ values = values
129
+ .compact
130
+ .map(&:to_s)
131
+ .map { |value| __html_escaped(value) }
127
132
  return if values.empty?
128
133
 
129
134
  %( #{name}="#{values.join(' ')}")
@@ -7,55 +7,53 @@ module Bade
7
7
  class << self
8
8
  # @param [Proc] proc
9
9
  # @return [[String, Integer], String]
10
- def is_proc(proc)
10
+ def proc?(proc)
11
11
  source_location(proc)
12
12
  end
13
13
 
14
14
  # @param [Class] klass
15
15
  # @param [Symbol, String] method_name
16
16
  # @return [[String, Integer], String]
17
- def is_method(klass, method_name)
17
+ def method?(klass, method_name)
18
18
  source_location(klass.method(method_name))
19
19
  end
20
20
 
21
21
  # @param [Object] klass
22
22
  # @param [Symbol, String] method_name
23
23
  # @return [[String, Integer], String]
24
- def is_instance_method(klass, method_name)
24
+ def instance_method?(klass, method_name)
25
25
  source_location(klass.instance_method(method_name))
26
26
  end
27
27
 
28
- def are_methods(klass, method_name)
29
- are_via_extractor(:method, klass, method_name)
28
+ def methods?(klass, method_name)
29
+ via_extractor?(:method, klass, method_name)
30
30
  end
31
31
 
32
- def are_instance_methods(klass, method_name)
33
- are_via_extractor(:method, klass, method_name)
32
+ def instance_methods?(klass, method_name)
33
+ via_extractor?(:method, klass, method_name)
34
34
  end
35
35
 
36
36
  # @param [Class] klass
37
37
  # @return [[String, Integer], String]
38
- def is_class(klass)
38
+ def class?(klass)
39
39
  defined_methods(klass)
40
40
  .group_by { |sl| sl[0] }
41
41
  .map do |file, sls|
42
42
  lines = sls.map { |sl| sl[1] }
43
- count = lines.size
44
- line = lines.min
45
43
 
46
44
  {
47
45
  file: file,
48
- count: count,
49
- line: line
46
+ count: lines.size,
47
+ line: lines.min,
50
48
  }
51
- end
49
+ end # rubocop:disable Style/MultilineBlockChain
52
50
  .sort_by { |fc| fc[:count] }
53
51
  .map { |fc| [fc[:file], fc[:line]] }
54
52
  end
55
53
 
56
54
  # Raises ArgumentError if klass does not have any Ruby methods defined in it.
57
- def is_class_primarily(klass)
58
- source_locations = is_class(klass)
55
+ def class_primarily?(klass)
56
+ source_locations = class?(klass)
59
57
  if source_locations.empty?
60
58
  methods = defined_methods(klass)
61
59
  msg = if methods.empty?
@@ -80,7 +78,7 @@ module Bade
80
78
  )
81
79
  end
82
80
 
83
- def are_via_extractor(extractor, klass, method_name)
81
+ def via_extractor?(extractor, klass, method_name)
84
82
  klass.ancestors
85
83
  .map do |ancestor|
86
84
  method = ancestor.send(extractor, method_name)
@@ -106,12 +104,12 @@ module Bade
106
104
  def self.where_is(klass, method = nil)
107
105
  if method
108
106
  begin
109
- Where.is_instance_method(klass, method)
107
+ Where.instance_method?(klass, method)
110
108
  rescue NameError
111
- Where.is_method(klass, method)
109
+ Where.method?(klass, method)
112
110
  end
113
111
  else
114
- Where.is_class_primarily(klass)
112
+ Where.class_primarily?(klass)
115
113
  end
116
114
  end
117
115
  end
data/lib/bade/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bade
4
- VERSION = '0.3.9'.freeze
4
+ VERSION = '0.3.11'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Kříž
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-27 00:00:00.000000000 Z
11
+ date: 2024-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.4.21
143
+ rubygems_version: 3.5.11
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Minimalistic template engine for Ruby.