svelte-on-rails 22.1.0 → 22.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f30afd891885bd5b9d03aacb948116be1d32838d08c9d29589b5d3d68d31317
4
- data.tar.gz: cbd63f36144fac966013a5b6d9e1bcfca9070a56c8367eaff8ff2033ab628ff2
3
+ metadata.gz: a32126c57f42015b2fae36849a77266d174dfc6234a5958c924b490e4c1efc47
4
+ data.tar.gz: b264887e056b7d3aeb763923d1f20eccdab81000bc1c7dae63b7c909397157c0
5
5
  SHA512:
6
- metadata.gz: acfe1cb4a3c02e70f979097867ab426b46b98025c88326831d41c229a41b9e468d2a8a76ae4cb9c35be9e3ba3ed3ff750e3edb2f80d52587de207ffafc62c085
7
- data.tar.gz: 1c5aa90cbc05f1eeef827957035a894eb721ec957223a9230fce24ae0db48ce2c500ad8d19b901a5836431fa70127d7925b01ffa88344c243eb614711c31b7f5
6
+ metadata.gz: ec6ad182cd5a2f06c654017f2ddbc81fe07b07498339262b0ec145d7fbaa815d12abef5a681930080d8edaee57e536f036399e5df011c8e3d3413ecea9b0a5f7
7
+ data.tar.gz: e67beb89b3a4ed77bdb3d7cc39f54596769c1b9cd25d12b7db7341cf860176d0b9a633b6fba4e4703a2a48d42509a1b18a977345b0a91214cefe556c760766b2
@@ -3,7 +3,7 @@ require "svelte_on_rails/view_helpers"
3
3
  require "svelte_on_rails/turbo_stream"
4
4
  require "svelte_on_rails/action_cable"
5
5
  require "svelte_on_rails/active_record_extensions"
6
- require "svelte_on_rails/ssr_server"
6
+ require "svelte_on_rails/ssr_client"
7
7
 
8
8
  require "svelte_on_rails/railtie" if defined?(Rails)
9
9
 
@@ -179,7 +179,7 @@ module SvelteOnRails
179
179
 
180
180
  def redis_cache_store_configs
181
181
  if defined?(Rails.application) && Rails.application.config.cache_store.is_a?(Array) && Rails.application.config.cache_store.first == :redis_cache_store
182
- { 'redis_cache_store' => Rails.application.config.cache_store.second.stringify_keys }
182
+ { redis_cache_store: Rails.application.config.cache_store.second.stringify_keys }
183
183
  else
184
184
  {}
185
185
  end
@@ -274,7 +274,7 @@ module SvelteOnRails
274
274
  def self.template_paths(templates, app_root: nil)
275
275
  paths = []
276
276
  app_root = app_root_path(app_root)
277
- ssr_server_configured = SvelteOnRails::SsrServer.instance.configured?
277
+ ssr_server_configured = SvelteOnRails::SsrClient.instance.configured?
278
278
 
279
279
  templates.each do |t|
280
280
  templates_folder = File.expand_path("../../../templates", __dir__)
@@ -285,7 +285,7 @@ module SvelteOnRails
285
285
  files.each do |f|
286
286
 
287
287
  unless ssr_server_configured
288
- next if File.basename(f) == File.basename(SvelteOnRails::SsrServer.ssr_server_bin_path)
288
+ next if File.basename(f) == File.basename(SvelteOnRails::SsrClient.ssr_server_bin_path)
289
289
  end
290
290
 
291
291
  paths.push(
@@ -24,24 +24,38 @@ module SvelteOnRails
24
24
 
25
25
  # Defining methods to log errors and warnings using Rails logger
26
26
  def self.puts_error(text)
27
- # Using Rails logger to log error with custom formatting
28
- caller_info = caller[1] =~ /`([^']*)'/ ? $1 : "unknown"
29
- Rails.logger.error(" => [SOR] #{caller_info} ERROR")
30
- text.split("\n").each do |line|
31
- Rails.logger.error(" => #{line}")
32
- end
27
+ log_with_severity(:error, text, "ERROR", "\e[31m") # red
33
28
  end
34
29
 
35
30
  # Defining method to log warnings using Rails logger
36
31
  def self.puts_warning(text)
37
- # Using Rails logger to log warning with custom formatting
38
- caller_info = caller[1] =~ /`([^']*)'/ ? $1 : "unknown"
39
- Rails.logger.warn(" => [SOR] #{caller_info} WARNING \e[0m")
40
- text.split("\n").each do |line|
41
- Rails.logger.warn(" => #{line}")
32
+ log_with_severity(:warn, text, "WARNING", "\e[33m")
33
+ end
34
+
35
+ # Internal: emits a tagged, colored block via Rails.logger.
36
+ # ANSI colors are always included; modern terminals + the Rails
37
+ # dev logger render them. In production the logger strips them
38
+ # or they pass through harmlessly to aggregators.
39
+ def self.log_with_severity(level, text, label, color_code)
40
+
41
+ clear = "\e[0m"
42
+ bold = "\e[1m"
43
+
44
+ header = "#{color_code}#{bold}[SOR] #{label}#{clear}"
45
+ Rails.logger.public_send(level, header)
46
+ text.to_s.split("\n").each do |line|
47
+ Rails.logger.public_send(level, "#{color_code} => #{line}#{clear}")
42
48
  end
43
49
  end
44
50
 
51
+ def self.color_supported?
52
+ return false if Rails.env.production?
53
+ # Rails dev logger writes to STDOUT; check that it's a TTY.
54
+ $stdout.tty?
55
+ rescue
56
+ false
57
+ end
58
+
45
59
  def self.component_paths_uncached(component, current_controller_path)
46
60
 
47
61
  file_basename = File.basename(component, ".svelte")
@@ -47,19 +47,20 @@ module SvelteOnRails
47
47
  [Svelte on Rails] Source file not found: «#{p[:path]}»
48
48
  TEXT
49
49
  end
50
- if p[:path][0..9] == 'app/views/'
51
- if !p[:file_basename].match?(/^[A-Z][A-Za-z0-9]+$/) && !p[:file_basename].match?(/^[a-z0-9][a-z0-9_]+$/)
52
- raise <<~TEXT
53
- [SOR] Invalid filename: «#{p[:file_basename]}»
54
- Component names must be CamelCased or under_scored and must be prefixed by underscore.
55
-
56
- TEXT
50
+ if p[:path].start_with?('app/views/')
51
+ if !p[:file_basename].match?(/^[A-Z][A-Za-z0-9]*$/) && !p[:file_basename].match?(/^_[a-z0-9][a-z0-9_]*$/)
52
+ @utils.puts_warning <<~TEXT
53
+ Invalid filename: «#{p[:file_basename]}»
54
+ Component names should be CamelCased, or under_scored and prefixed by an underscore (e.g. «_my_partial»).
55
+ See: https://svelte-on-rails.dev/naming.html
56
+ TEXT
57
57
  end
58
- elsif !p[:file_basename].match?(/^[A-Z][A-Za-z0-9]+$/)
59
- raise <<~TEXT
60
- [SOR] Invalid filename: «#{p[:file_basename]}»
61
- Component names must be CamelCased.
62
- TEXT
58
+ elsif !p[:file_basename].match?(/^[A-Z][A-Za-z0-9]*$/)
59
+ @utils.puts_warning <<~TEXT
60
+ Invalid filename: «#{p[:file_basename]}»
61
+ Component names should be CamelCased.
62
+ See: https://svelte-on-rails.dev/naming.html
63
+ TEXT
63
64
  end
64
65
  full_path = Rails.root.join(p[:path])
65
66
  dir, wanted = full_path.dirname.to_s, full_path.basename.to_s
@@ -232,7 +233,7 @@ module SvelteOnRails
232
233
  def render_with_ssr_server(caller_loc)
233
234
  return {} unless @conf.configs[:ssr_server]
234
235
 
235
- result = SvelteOnRails::SsrServer.instance.render(
236
+ result = SvelteOnRails::SsrClient.instance.render(
236
237
  component_paths,
237
238
  cached_props,
238
239
  debug?,
@@ -21,7 +21,7 @@ module SvelteOnRails
21
21
  SvelteOnRails::Lib::Utils.ssr_server_log("Skipping svelte-on-rails SSR-Server because of top level task: #{Rake.application.top_level_tasks.join(', ')}")
22
22
  $stdout.flush
23
23
  elsif SvelteOnRails::Configuration.instance.configs[:ssr]
24
- SvelteOnRails::SsrServer.instance
24
+ SvelteOnRails::SsrClient.instance
25
25
  end
26
26
 
27
27
  end
@@ -2,7 +2,7 @@ require 'singleton'
2
2
 
3
3
  module SvelteOnRails
4
4
 
5
- class SsrServer
5
+ class SsrClient
6
6
 
7
7
  include Singleton
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svelte-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 22.1.0
4
+ version: 22.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
@@ -97,7 +97,7 @@ files:
97
97
  - lib/svelte_on_rails/lib/view_helper_support.rb
98
98
  - lib/svelte_on_rails/lib/watch_asset_changes.rb
99
99
  - lib/svelte_on_rails/railtie.rb
100
- - lib/svelte_on_rails/ssr_server.rb
100
+ - lib/svelte_on_rails/ssr_client.rb
101
101
  - lib/svelte_on_rails/turbo_stream.rb
102
102
  - lib/svelte_on_rails/view_helpers.rb
103
103
  - lib/tasks/svelte_on_rails_tasks.rake