notion_rails 0.2.1 → 0.2.3

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: 8b73231a083c06cfc250557a99ad2fb590f704368e301d7c9a59053b03835fcd
4
- data.tar.gz: 7e2c59c2aa19e4977daa97ae3eef11c829e2322264bd940f0248221e551952d7
3
+ metadata.gz: 7d8520fa8311a89b08c67281c8b2facb0083c983924064f8a73fd99845d45888
4
+ data.tar.gz: 51463269664f950db99b64211544d851d442e966160d96f36cc01d158fe7e457
5
5
  SHA512:
6
- metadata.gz: f5643d4e2204fe42e2691c99d9db2ab980fee60e6f21428e75f937a144870b599a64af429fa7488bde0e8ba83db330645330b1eff271eb6f767f8866a64ab573
7
- data.tar.gz: 88863038b9711c56a55e96e94bb39e681742e7540ab1a62c4535743eca0c6f8bc751366190c459e8aabdc4923dcf5da34775167b8fb777d66d0524ccd7e2c12e
6
+ metadata.gz: '09ab69fb89468ff1713d2433cac98c1777f0c4ab1dde081fc56f79352813c74b987e475408ffacc2379f3a4055681641babf0abb3f847e9550b27da3e7182049'
7
+ data.tar.gz: 72ed0bce7de6e8b055c588f155504a16e1a27925fe06b851c70971dcdd3dbadaee93a9ed56a6ec4be584283ef9b26493b89f48150da6d2a85d6ff387e2a5ff81
@@ -66,9 +66,9 @@ module NotionRails
66
66
  render_numbered_list_item(rich_text, @siblings, @children, class: options[:numbered_list_item])
67
67
  when 'quote' then render_quote(rich_text, class: options[:quote])
68
68
  when 'callout' then render_callout(rich_text, icon, class: options[:callout])
69
- when 'code' then render_code(rich_text, class: "#{options[:code]} language-#{@properties["language"]}")
70
- when 'image' then render_image(*multi_media)
71
- when 'video' then render_video(*multi_media)
69
+ when 'code' then render_code(rich_text, class: options[:code], language: @properties['language'])
70
+ when 'image' then render_image(*multi_media, class: options[:image])
71
+ when 'video' then render_video(*multi_media, class: options[:video])
72
72
  else
73
73
  'Error'
74
74
  end
@@ -80,21 +80,18 @@ module NotionRails
80
80
 
81
81
  def render_code(rich_text_array, options = {})
82
82
  # TODO: render captions
83
- pre_options = options
84
- pre_options[:class] = "border-2 p-6 rounded #{pre_options[:class]}"
85
83
  content_tag(:div, class: 'mt-4', data: { controller: 'highlight' }) do
86
84
  content_tag(:div, data: { highlight_target: 'source' }) do
87
- content_tag(:pre, pre_options) do
85
+ content_tag(:pre, class: "border-2 p-6 rounded w-full overflow-x-auto language-#{options[:language]}",
86
+ **options) do
88
87
  text_renderer(rich_text_array, options)
89
88
  end
90
89
  end
91
90
  end
92
91
  end
93
92
 
94
- def render_bulleted_list_item(rich_text_array, siblings, children, options = {})
95
- pre_options = options
96
- pre_options[:class] = "list-disc break-words #{pre_options[:class]}"
97
- content_tag(:ul, pre_options) do
93
+ def render_bulleted_list_item(rich_text_array, _siblings, children, options = {})
94
+ content_tag(:ul, class: 'list-disc break-words', **options.except(:class)) do
98
95
  content = content_tag(:li, options) do
99
96
  text_renderer(rich_text_array)
100
97
  end
@@ -109,9 +106,7 @@ module NotionRails
109
106
  end
110
107
 
111
108
  def render_numbered_list_item(rich_text_array, siblings, children, options = {})
112
- pre_options = options
113
- pre_options[:class] = "list-decimal #{pre_options[:class]}"
114
- content_tag(:ol, pre_options) do
109
+ content_tag(:ol, class: 'list-decimal', **options.except(:class)) do
115
110
  render_list_items(:numbered_list_item, rich_text_array, siblings, children, options)
116
111
  end
117
112
  end
@@ -135,13 +130,9 @@ module NotionRails
135
130
  end
136
131
 
137
132
  def render_quote(rich_text_array, options = {})
138
- div_options = options.dup
139
- pre_options = options.dup
140
- div_options[:class] = "mt-4 #{options[:class]}"
141
- content_tag(:div, div_options) do
142
- pre_options[:class] = "border-l-4 border-black px-5 py-1 #{options[:class]}"
133
+ content_tag(:div, class: 'mt-4', **options) do
143
134
  content_tag(:cite) do
144
- content_tag(:p, pre_options) do
135
+ content_tag(:p, class: 'border-l-4 border-black px-5 py-1', **options) do
145
136
  text_renderer(rich_text_array)
146
137
  end
147
138
  end
@@ -149,16 +140,14 @@ module NotionRails
149
140
  end
150
141
 
151
142
  def render_callout(rich_text_array, icon, options = {})
152
- pre_options = options
153
- pre_options[:class] = "p-4 rounded bg-neutral-200 mt-4 #{pre_options[:class]}"
154
- content_tag(:div, pre_options) do
143
+ content_tag(:div, class: 'p-4 rounded bg-neutral-200 mt-4', **options) do
155
144
  content = tag.span(icon, class: 'pr-2')
156
145
  content += text_renderer(rich_text_array)
157
146
  content
158
147
  end
159
148
  end
160
149
 
161
- def render_image(src, expiry_time, caption, type, options = {})
150
+ def render_image(src, _expiry_time, caption, _type, options = {})
162
151
  content_tag(:figure, options) do
163
152
  content = tag.img(src: src, alt: '')
164
153
  content += tag.figcaption(text_renderer(caption))
@@ -166,7 +155,7 @@ module NotionRails
166
155
  end
167
156
  end
168
157
 
169
- def render_video(src, expiry_time, caption, type, options = {})
158
+ def render_video(src, _expiry_time, caption, type, options = {})
170
159
  content_tag(:figure, options) do
171
160
  content = if type == 'file'
172
161
  video_tag(src, controls: true)
@@ -52,7 +52,7 @@ module NotionRails
52
52
 
53
53
  def get_article(id)
54
54
  base_page = NotionRails::BasePage.new(__get_page(id))
55
- base_blocks = NotionRails.config.cache_store.fetch(id) { get_blocks(id) }
55
+ base_blocks = get_blocks(id)
56
56
  NotionRails::Page.new(base_page, base_blocks)
57
57
  end
58
58
 
@@ -61,6 +61,7 @@ module NotionRails
61
61
  parent_list_block_index = nil
62
62
  results = []
63
63
  blocks['results'].each_with_index do |block, index|
64
+ block = refresh_block(block['id']) if refresh_image?(block)
64
65
  base_block = NotionRails::BaseBlock.new(block)
65
66
  base_block.children = get_blocks(base_block.id) if base_block.has_children
66
67
  # Notion returns same list items as different blocks so we have to do some processing to have them be related
@@ -86,6 +87,14 @@ module NotionRails
86
87
  results
87
88
  end
88
89
 
90
+ def refresh_image?(data)
91
+ return false unless data['type'] == 'image'
92
+ return false unless data.dig('image', 'type') == 'file'
93
+
94
+ expiry_time = data.dig('image', 'file', 'expiry_time')
95
+ expiry_time.to_datetime.past?
96
+ end
97
+
89
98
  private
90
99
 
91
100
  def __get_articles(tag: nil, slug: nil, page_size: 10)
@@ -106,7 +115,15 @@ module NotionRails
106
115
  end
107
116
 
108
117
  def __get_blocks(id)
109
- @client.block_children(block_id: id)
118
+ NotionRails.config.cache_store.fetch(id) { @client.block_children(block_id: id) }
119
+ end
120
+
121
+ def __get_block(id)
122
+ @client.block(block_id: id)
123
+ end
124
+
125
+ def refresh_block(id)
126
+ __get_block(id)
110
127
  end
111
128
  end
112
129
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotionRails
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.3'
5
5
  end
data/lib/notion_rails.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/all'
3
4
  require 'notion_rails/renderers'
4
5
  require 'notion_rails/base_block'
5
6
  require 'notion_rails/base_page'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Aguirre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-18 00:00:00.000000000 Z
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview