bade 0.3.8 → 0.3.10

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: 634cad9ad0535b4b49969984f50f300837fef21b3d98558e0dfa0321bef70481
4
- data.tar.gz: 242c463186adbb17102be57c0bf0071341e40f75b639135fced349d2a31f0210
3
+ metadata.gz: 95b05e356f997fbc5f6a8bd6f6e6f7224f58334778b97c96d1faafd472073154
4
+ data.tar.gz: 9fad2f37dec4f5812899bb4a15eb291af618c7083521688d9d70e9f803db7c84
5
5
  SHA512:
6
- metadata.gz: 5d2c6b50741926cf20cdb4c1243cf95c75c445b6d4b0d3992b2f0d467133b2c33e0f058269840b51af94390fba3c7ac4e8b3ea17cff0be1ba088b410f97de3e6
7
- data.tar.gz: a431f9a0f4c4d087c7e8038d9065c954b135418107de2b0b8796657427e1d550a5d1b72830641dc859027373bbb44d0c725194af93d76d30f65a6606c8abf937
6
+ metadata.gz: 17762e2285d93f223c964cdb3ed3b946bd7b72de2a2aeb95842dcd0be0166e06ee31cdd2c16fdd5a2d20631fda4df48c15adee134ba7bc35fef1e5cacb84f9ea
7
+ data.tar.gz: 3acbf567d6ee1a681e5d0999c899ead310978e0970b0a5376e2fd519c25e03c39fc98159c7176f5c1dab57d1f8209b9636c0d02aefdcc71792b8f8c0147ab521
data/Bade.gemspec CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
22
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'psych', '>= 2.2', '< 5.0'
25
+ spec.add_dependency 'psych', '>= 2.2', '< 6.0'
26
26
 
27
- spec.add_development_dependency 'fakefs', '~> 1.3'
27
+ spec.add_development_dependency 'fakefs', '>= 1.4', '< 3.0'
28
28
  spec.add_development_dependency 'rspec', '~> 3.2'
29
29
  spec.add_development_dependency 'rubocop', '~> 1.14'
30
30
  end
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)
@@ -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,9 @@ 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 { |value| __html_escaped(value) }
127
131
  return if values.empty?
128
132
 
129
133
  %( #{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.8'.freeze
4
+ VERSION = '0.3.10'.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.8
4
+ version: 0.3.10
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-26 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
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '2.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.0'
22
+ version: '6.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,21 +29,27 @@ dependencies:
29
29
  version: '2.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.0'
32
+ version: '6.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: fakefs
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '1.4'
40
+ - - "<"
38
41
  - !ruby/object:Gem::Version
39
- version: '1.3'
42
+ version: '3.0'
40
43
  type: :development
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - "~>"
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '1.4'
50
+ - - "<"
45
51
  - !ruby/object:Gem::Version
46
- version: '1.3'
52
+ version: '3.0'
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: rspec
49
55
  requirement: !ruby/object:Gem::Requirement
@@ -134,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
140
  - !ruby/object:Gem::Version
135
141
  version: '0'
136
142
  requirements: []
137
- rubygems_version: 3.4.21
143
+ rubygems_version: 3.5.11
138
144
  signing_key:
139
145
  specification_version: 4
140
146
  summary: Minimalistic template engine for Ruby.