notion_to_html 1.2.1 → 1.3.1
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 +4 -4
- data/lib/notion_to_html/base_block.rb +68 -31
- data/lib/notion_to_html/service.rb +19 -1
- data/lib/notion_to_html/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ae21e019724a4f1e4524140a11365eaa8abbb7564fcca823a17bb618054b037
|
4
|
+
data.tar.gz: e860e17724407d000232d933b9cf244611d97f17bcb9323c71750d09fb67b98b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e013321283c02d19986e9e80779bf1127ead9445b1932f818f78e9f4324a0ee34f129d8cad09e9b5896b520ed900245aa1900d1d0aa384b3ac8cea3b2a57541b
|
7
|
+
data.tar.gz: 0e2e63856a1c706c37cf61f9b774f00e93fd9e1ab3492cb01560d3b6f2520b3cf2018c76bbd4222301b99336950bb3084eef6559e4e0f12e7b86822c3fb9d6d7
|
@@ -68,46 +68,83 @@ module NotionToHtml
|
|
68
68
|
@properties = data[@type]
|
69
69
|
end
|
70
70
|
|
71
|
+
RENDERERS = {}.with_indifferent_access
|
72
|
+
|
71
73
|
BLOCK_TYPES.each do |block|
|
72
74
|
define_method("class_for_#{block}") { |options| options.dig(block, :class) }
|
73
75
|
define_method("data_for_#{block}") { |options| options.dig(block, :data) }
|
76
|
+
RENDERERS[block] = "render_#{block}_block".to_sym
|
74
77
|
end
|
75
78
|
|
79
|
+
RENDERERS.freeze
|
80
|
+
|
76
81
|
# Renders the block based on its type.
|
77
82
|
# @param options [Hash] Additional options for rendering the block.
|
78
83
|
# @return [String] The rendered block as HTML.
|
79
84
|
def render(options = {})
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
85
|
+
render_method = RENDERERS[@type]
|
86
|
+
return 'Unsupported block' unless render_method
|
87
|
+
|
88
|
+
send(render_method, build_render_options(options))
|
89
|
+
end
|
90
|
+
|
91
|
+
# Builds render options for a block type
|
92
|
+
# @param options [Hash] The original options hash
|
93
|
+
# @return [Hash] Processed options for rendering
|
94
|
+
def build_render_options(options)
|
95
|
+
{
|
96
|
+
class: send("class_for_#{@type}", options),
|
97
|
+
data: send("data_for_#{@type}", options),
|
98
|
+
**options.with_indifferent_access.dig(@type)&.except(:class, :data).to_h
|
99
|
+
}.deep_symbolize_keys
|
100
|
+
end
|
101
|
+
|
102
|
+
def render_paragraph_block(options)
|
103
|
+
render_paragraph(rich_text, **options)
|
104
|
+
end
|
105
|
+
|
106
|
+
def render_heading_1_block(options)
|
107
|
+
render_heading_1(rich_text, **options)
|
108
|
+
end
|
109
|
+
|
110
|
+
def render_heading_2_block(options)
|
111
|
+
render_heading_2(rich_text, **options)
|
112
|
+
end
|
113
|
+
|
114
|
+
def render_heading_3_block(options)
|
115
|
+
render_heading_3(rich_text, **options)
|
116
|
+
end
|
117
|
+
|
118
|
+
def render_table_of_contents_block(_options)
|
119
|
+
render_table_of_contents
|
120
|
+
end
|
121
|
+
|
122
|
+
def render_bulleted_list_item_block(options)
|
123
|
+
render_bulleted_list_item(rich_text, @siblings, @children, 0, **options)
|
124
|
+
end
|
125
|
+
|
126
|
+
def render_numbered_list_item_block(options)
|
127
|
+
render_numbered_list_item(rich_text, @siblings, @children, 0, **options)
|
128
|
+
end
|
129
|
+
|
130
|
+
def render_quote_block(options)
|
131
|
+
render_quote(rich_text, **options)
|
132
|
+
end
|
133
|
+
|
134
|
+
def render_callout_block(options)
|
135
|
+
render_callout(rich_text, icon, **options)
|
136
|
+
end
|
137
|
+
|
138
|
+
def render_code_block(options)
|
139
|
+
render_code(rich_text, **options.merge(language: @properties['language']))
|
140
|
+
end
|
141
|
+
|
142
|
+
def render_image_block(options)
|
143
|
+
render_image(*multi_media, **options)
|
144
|
+
end
|
145
|
+
|
146
|
+
def render_video_block(options)
|
147
|
+
render_video(*multi_media, **options)
|
111
148
|
end
|
112
149
|
|
113
150
|
# Retrieves the rich text content of the block.
|
@@ -111,7 +111,7 @@ module NotionToHtml
|
|
111
111
|
parent_list_block_index = nil
|
112
112
|
results = []
|
113
113
|
blocks['results'].each_with_index do |block, index|
|
114
|
-
block = refresh_block(block['id']) if
|
114
|
+
block = refresh_block(block['id']) if refresh_block?(block)
|
115
115
|
base_block = NotionToHtml::BaseBlock.new(block)
|
116
116
|
base_block.children = get_blocks(base_block.id) if base_block.has_children
|
117
117
|
if %w[numbered_list_item].include? base_block.type
|
@@ -133,6 +133,13 @@ module NotionToHtml
|
|
133
133
|
results
|
134
134
|
end
|
135
135
|
|
136
|
+
# Determines if a block needs to be refreshed based on its type and expiry time
|
137
|
+
# @param block [Hash] The block data to check
|
138
|
+
# @return [Boolean] True if the block needs to be refreshed, false otherwise
|
139
|
+
def refresh_block?(block)
|
140
|
+
refresh_image?(block) || refresh_video?(block)
|
141
|
+
end
|
142
|
+
|
136
143
|
# Determines if an image block needs to be refreshed based on its expiry time
|
137
144
|
# @param data [Hash] The data of the image block
|
138
145
|
# @return [Boolean] True if the image needs to be refreshed, false otherwise
|
@@ -144,6 +151,17 @@ module NotionToHtml
|
|
144
151
|
expiry_time.to_datetime.past?
|
145
152
|
end
|
146
153
|
|
154
|
+
# Determines if a video block needs to be refreshed based on its expiry time
|
155
|
+
# @param data [Hash] The data of the video block
|
156
|
+
# @return [Boolean] True if the video needs to be refreshed, false otherwise
|
157
|
+
def refresh_video?(data)
|
158
|
+
return false unless data['type'] == 'video'
|
159
|
+
return false unless data.dig('video', 'type') == 'file'
|
160
|
+
|
161
|
+
expiry_time = data.dig('video', 'file', 'expiry_time')
|
162
|
+
expiry_time.to_datetime.past?
|
163
|
+
end
|
164
|
+
|
147
165
|
private
|
148
166
|
|
149
167
|
# Accessor for the client
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notion_to_html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillermo Aguirre
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-01-31 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: actionview
|