humid 0.1.0 → 0.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: 6c4f5090d85ea4b1c4998f6c8533816a8875039f2ffe5b5785e3e571092445c6
4
- data.tar.gz: 844410054db5d2c89fa3fc1fd3ac4d64f83605cf4a157573ebd6d172b01d0a7f
3
+ metadata.gz: 73079cacc72320a7c7d439d5cc443a42221a9e177dda5f25712c9898212f533a
4
+ data.tar.gz: f06abbe52e2e566a415d7982cac6c6313d158e1f47f2ec142179226f55d7cd63
5
5
  SHA512:
6
- metadata.gz: 574e6c64e749180f964a3d9ffe4dd91f18179408901b4b26960b2ef3c9bbe12c601e0879fc97bb60b340ed0270be627aaf0cc92d18827deda5f45dd515d952c4
7
- data.tar.gz: b1511fc86f5655ac063bf6d927866bd00096c7ddca23e822e2cd3dbe03a97d1e4f62288f1242c9b436e67695402c2a61a59e4f096a0dc0f3dbf450ac0fbdc250
6
+ metadata.gz: ce807ac8725f2054eaa15f00ecd2ec7532b5d720145f9078d211966fd3b5c81f06e282a9511778fa1ecfdcc4af028dd109ae950c14d6a9c4cb1f2c78d64bba14
7
+ data.tar.gz: 903b52f1aebf08c3f90d606f5e1eca7656aa04bc988d1342f863cf9a915acdc52b94d440d2f6f50c68f3d8e34f58d400c669dd7afc6f75688aad9104203e592c
data/README.md CHANGED
@@ -123,6 +123,29 @@ The following functions are **not** available in the mini_racer environment
123
123
  `console.log` and friends (`info`, `error`, `warn`) are delegated to the
124
124
  respective methods on the configured logger.
125
125
 
126
+ All arguments are passed through — MiniRacer converts JS objects to Ruby
127
+ hashes and arrays automatically. A `log_formatter` proc controls how these
128
+ arguments are formatted into a single string for the logger:
129
+
130
+ ```ruby
131
+ Humid.configure do |config|
132
+ config.logger = Rails.logger
133
+
134
+ config.log_formatter = proc { |level, message, *rest|
135
+ parts = [message]
136
+ parts += rest.map { |a| a.is_a?(String) ? a : JSON.pretty_generate(a) }
137
+ parts.join("\n")
138
+ }
139
+ end
140
+ ```
141
+
142
+ The formatter receives `(level, message, *rest)` where:
143
+ - `level` — the log level as a symbol (`:debug`, `:info`, `:warn`, `:error`)
144
+ - `message` — the first argument passed to `console.log/info/warn/error`
145
+ - `rest` — any additional arguments (objects come through as Ruby hashes/arrays)
146
+
147
+ The default formatter simply returns `message` unchanged.
148
+
126
149
  ## Usage
127
150
 
128
151
  In your entry file, e.g, `server_rendering.js`, pass your HTML render function
data/lib/humid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Humid
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
data/lib/humid.rb CHANGED
@@ -20,6 +20,7 @@ class Humid
20
20
  self.config = ActiveSupport::OrderedOptions.new.merge({
21
21
  raise_render_errors: true,
22
22
  context_options: {},
23
+ log_formatter: proc { |_level, message, *_rest| message },
23
24
  })
24
25
 
25
26
  class << self
@@ -66,10 +67,11 @@ class Humid
66
67
  ctx = MiniRacer::Context.new(**config.context_options)
67
68
 
68
69
  if logger
69
- ctx.attach("console.log", proc { |err| logger.debug(err.to_s) })
70
- ctx.attach("console.info", proc { |err| logger.info(err.to_s) })
71
- ctx.attach("console.error", proc { |err| logger.error(err.to_s) })
72
- ctx.attach("console.warn", proc { |err| logger.warn(err.to_s) })
70
+ fmt = config.log_formatter || proc { |_level, message, *_rest| message }
71
+ ctx.attach("console.log", proc { |*args| logger.debug(fmt.call(:debug, *args)) })
72
+ ctx.attach("console.info", proc { |*args| logger.info(fmt.call(:info, *args)) })
73
+ ctx.attach("console.error", proc { |*args| logger.error(fmt.call(:error, *args)) })
74
+ ctx.attach("console.warn", proc { |*args| logger.warn(fmt.call(:warn, *args)) })
73
75
  end
74
76
 
75
77
  js = ""
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho