salvia 0.2.1 → 0.2.2

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: 7c51e30591df5e8347faf21b95bf57e6d324feb29f10c5c82070ff62d23f09cb
4
- data.tar.gz: 696e105566fc056cefa6b947923d3c0e60527c9b38d9740b6b9c79b90cf1fd1a
3
+ metadata.gz: b6e25508aa23c2f3708cc4d21c403d3e265a996a8dd1d84ee818750f473d1638
4
+ data.tar.gz: c5c6c5f90dae32b27cbddcc6e137b5b28cdb5c03a399efd256534bcba5649fb0
5
5
  SHA512:
6
- metadata.gz: a90257f44c7730110d0e94138b00b0d9e8607f9a40736d8cb29b64a7bd5f47a895ffeece690f6b9a7426a3a38f942ee5417297819ade4bfacbd20ba290bd856a
7
- data.tar.gz: 3bb8812e772f2fa8a27696863c5711c564257d87048468921e9e5f2883121900d4e306e4a080080f54e3bfc6604bb5a1c8d6dc413afcae565e3ea2ea08d27270
6
+ metadata.gz: 9a2dba842f6307da35f3e5b58048fb9ccb75cb781bad7d6a030dae69f2fa70c9c8cddb1db2dc097e7021a17c7bfadf4f75c598d1f4ac9ccb3fd93a559513e1eb
7
+ data.tar.gz: 6d00ac1ad82848de874eeb3347c0c590c7e89a0a82569c6db16a94578ea9093ce1caf3f100d341af219f03eed66d662357312261b4bb4ead910e6f6069199b29
@@ -74,7 +74,9 @@ module Salvia
74
74
  # @example ハイドレーションを無効化 (静的 HTML のみ)
75
75
  # <%= island "StaticCard", title: "Hello", hydrate: false %>
76
76
  #
77
+ # @deprecated Use Salvia::SSR.render in controller instead.
77
78
  def island(name, props = {}, options = {})
79
+ warn "[DEPRECATION] `island` helper is deprecated. Please use `Salvia::SSR.render` in your controller (API Mode) instead."
78
80
  tag_name = options.delete(:tag) || :div
79
81
 
80
82
  # デフォルトの hydrate 値を決定
@@ -148,20 +150,7 @@ module Salvia
148
150
  # @option options [Boolean] :doctype <!DOCTYPE html> を付与するか (デフォルト: true)
149
151
  # @return [String] 完全な HTML 文字列
150
152
  def ssr(name, props = {}, options = {})
151
- # SSR HTML を生成
152
- html = Salvia::SSR.render(name, props)
153
-
154
- # <head> がある場合、Import Map を自動注入
155
- if html.include?("</head>")
156
- import_map_html = salvia_import_map
157
- html = html.sub("</head>", "#{import_map_html}</head>")
158
- end
159
-
160
- result = html
161
- if options.fetch(:doctype, true)
162
- result = "<!DOCTYPE html>\n" + result
163
- end
164
-
153
+ result = Salvia::SSR.render_page(name, props, options)
165
154
  result.respond_to?(:html_safe) ? result.html_safe : result
166
155
  end
167
156
 
@@ -40,9 +40,9 @@ module Salvia
40
40
  return serve_islands_js
41
41
  end
42
42
 
43
- # Remove .js extension to find source (if present)
43
+ # Remove extension to find source (supports .js, .tsx, .ts, .jsx)
44
44
  # Also handle requests without extension (from import map resolution)
45
- base_name = path_info.sub(/\.js$/, "")
45
+ base_name = path_info.sub(/\.(js|tsx|ts|jsx)$/, "")
46
46
 
47
47
  source_path = resolve_source_path(base_name)
48
48
 
data/lib/salvia/ssr.rb CHANGED
@@ -89,6 +89,32 @@ module Salvia
89
89
  current_adapter.render(component_name, props)
90
90
  end
91
91
 
92
+ # ページコンポーネントをレンダリング (Import Map 注入 + DOCTYPE)
93
+ # @param component_name [String] コンポーネント名
94
+ # @param props [Hash] プロパティ
95
+ # @param options [Hash] オプション
96
+ # @return [String] 完全な HTML 文字列
97
+ def render_page(component_name, props = {}, options = {})
98
+ html = render(component_name, props)
99
+
100
+ # <head> がある場合、Import Map を自動注入
101
+ if html.include?("</head>")
102
+ map = Salvia::Core::ImportMap.generate
103
+ import_map_html = <<~HTML
104
+ <script type="importmap">
105
+ #{map.to_json}
106
+ </script>
107
+ HTML
108
+ html = html.sub("</head>", "#{import_map_html}</head>")
109
+ end
110
+
111
+ if options.fetch(:doctype, true)
112
+ html = "<!DOCTYPE html>\n" + html
113
+ end
114
+
115
+ html
116
+ end
117
+
92
118
  # コンポーネントを登録
93
119
  def register_component(name, code)
94
120
  ensure_configured!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Salvia
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salvia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroto Furugen