notion_to_md 3.0.0.beta1 → 3.0.0.beta2

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: 2671f75f28373209f1846e06ed528f7adcc9d857da3fde4d1b0a5e43144c5850
4
- data.tar.gz: 39c65f58ff9432277667c0c5c2597561d1b28d9252a7868ec2b8885d0e94e07a
3
+ metadata.gz: 3892953f8ab81cb3c4ff219452e8daf615997b27b41aedcd64984d127fcc2d6e
4
+ data.tar.gz: d85c49651c090a1fbd47d0fd57584b71ec7e76955147c9a4526b60ffd496c354
5
5
  SHA512:
6
- metadata.gz: 3c1571b5b93eb39bccb66032db2296d84b1d02313a6098e3d0e0f03022bfbea5eb0d46b54ae20b7bed6a9a5d6e79721922623491b5b1b829060e08b09cb67114
7
- data.tar.gz: 5eea9bf71539d0d6c66880c89a39950c42da4c67767d651b1e218ebb380539b27c5b3ed5f00c18c77a13f547db9edc21f3645bb66e4c3e6204d08b59085da0fa
6
+ metadata.gz: 7414f7b60612f7dbf9565b4e5d97d0f6c96c389abd5f0c0d46906711621d99e5e617fcf94e2809e483f244438f9184dacc4ba043bc52d6129909a93ae05229cc
7
+ data.tar.gz: 6a4520688e495502e140e170f69ff78fa55ead84021e0bb8e2cbc99615fd30d87be3bb613ee18a253a0c41403567b0786f44f78f6654c9c272f690aeddb1c176
@@ -35,16 +35,7 @@ class NotionToMd
35
35
  #
36
36
  # @see .build
37
37
  def call(id:, notion_client:, filter: nil, sorts: nil, frontmatter: false)
38
- metadata = notion_client.database(database_id: id)
39
- pages = Builder.call(
40
- database_id: id,
41
- notion_client: notion_client,
42
- filter: filter,
43
- sorts: sorts,
44
- frontmatter: frontmatter
45
- )
46
-
47
- new(metadata: metadata, children: pages)
38
+ new(id: id, notion_client: notion_client, filter: filter, sorts: sorts, frontmatter: frontmatter).call
48
39
  end
49
40
 
50
41
  # @!method build(...)
@@ -52,6 +43,15 @@ class NotionToMd
52
43
  alias build call
53
44
  end
54
45
 
46
+ # @return [String] The Notion id database.
47
+ attr_reader :id
48
+
49
+ # @param jNotion::Client] The Notion API client.
50
+ attr_reader :notion_client
51
+
52
+ # @return [Hash] The database configuration options.
53
+ attr_reader :config
54
+
55
55
  # @return [Object] The metadata associated with the database.
56
56
  attr_reader :metadata
57
57
 
@@ -64,13 +64,42 @@ class NotionToMd
64
64
 
65
65
  # Initialize a new database representation.
66
66
  #
67
- # @param metadata [Object] The Notion database metadata.
68
- # @param children [Array<NotionToMd::Page>] The pages belonging to the database.
69
- def initialize(metadata:, children:)
70
- @metadata = metadata
71
- @children = children
67
+ # @param id [String] The Notion database ID.
68
+ # @param notion_client [Notion::Client] The Notion API client.
69
+ # @param filter [Hash, nil] Optional filter criteria to pass to the Notion API.
70
+ # @param sorts [Array<Hash>, nil] Optional sort criteria.
71
+ # @param frontmatter [Boolean] Whether to include frontmatter in each page’s Markdown output.
72
+ def initialize(id:, notion_client:, filter:, sorts:, frontmatter: false)
73
+ @id = id
74
+ @notion_client = notion_client
75
+ @config = {
76
+ frontmatter: frontmatter,
77
+ filter: filter,
78
+ sorts: sorts
79
+ }
72
80
  end
73
81
 
82
+ # Fetch database metadata and contained pages from the Notion API.
83
+ #
84
+ # This method populates the database's metadata and children by making API calls
85
+ # to retrieve the database structure and all pages contained within it, applying
86
+ # any configured filters and sorting criteria.
87
+ #
88
+ # @return [NotionToMd::Database] returns self to allow method chaining.
89
+ def call
90
+ @metadata = notion_client.database(database_id: id)
91
+ @children = Builder.call(
92
+ database_id: id,
93
+ notion_client: notion_client,
94
+ filter: config[:filter],
95
+ sorts: config[:sorts],
96
+ frontmatter: config[:frontmatter]
97
+ )
98
+ self
99
+ end
100
+
101
+ alias build call
102
+
74
103
  # Convert all database pages into Markdown.
75
104
  #
76
105
  # @return [Array<String>] Markdown documents for each page in the database.
@@ -28,10 +28,7 @@ class NotionToMd
28
28
  #
29
29
  # @see .build
30
30
  def call(id:, notion_client:, frontmatter: false)
31
- metadata = notion_client.page(page_id: id)
32
- blocks = Builder.call(block_id: id, notion_client: notion_client)
33
-
34
- new(metadata: metadata, children: blocks, frontmatter: frontmatter)
31
+ new(id: id, notion_client: notion_client, frontmatter: frontmatter).call
35
32
  end
36
33
 
37
34
  # @!method build(...)
@@ -39,6 +36,15 @@ class NotionToMd
39
36
  alias build call
40
37
  end
41
38
 
39
+ # @return [String] The Notion id page.
40
+ attr_reader :id
41
+
42
+ # @param jNotion::Client] The Notion API client.
43
+ attr_reader :notion_client
44
+
45
+ # @param [Hash] The page configuration options.
46
+ attr_reader :config
47
+
42
48
  # @return [Object] The metadata associated with the page.
43
49
  attr_reader :metadata
44
50
 
@@ -51,15 +57,29 @@ class NotionToMd
51
57
 
52
58
  # Initialize a new Page.
53
59
  #
54
- # @param metadata [Object] The Notion page metadata.
55
- # @param children [Array<#to_md>] The block children belonging to the page.
60
+ # @param id [String] The Notion page ID.
61
+ # @param notion_client [Notion::Client] The Notion API client.
56
62
  # @param frontmatter [Boolean] Whether to include frontmatter in the Markdown output.
57
- def initialize(metadata:, children:, frontmatter: false)
58
- @metadata = metadata
59
- @children = children
63
+ def initialize(id:, notion_client:, frontmatter: false)
64
+ @id = id
65
+ @notion_client = notion_client
60
66
  @config = { frontmatter: frontmatter }
61
67
  end
62
68
 
69
+ # Fetch page data and child blocks from the Notion API.
70
+ #
71
+ # This method populates the page's metadata and children by making API calls
72
+ # to retrieve the page content and its nested blocks.
73
+ #
74
+ # @return [NotionToMd::Page] returns self to allow method chaining.
75
+ def call
76
+ @metadata = notion_client.page(page_id: id)
77
+ @children = Builder.call(block_id: id, notion_client: notion_client)
78
+ self
79
+ end
80
+
81
+ alias build call
82
+
63
83
  # Render the body of the page (Markdown representation of its blocks).
64
84
  #
65
85
  # @return [String] The Markdown content of the page.
@@ -71,7 +91,7 @@ class NotionToMd
71
91
  #
72
92
  # @return [Boolean]
73
93
  def frontmatter?
74
- @config[:frontmatter]
94
+ config[:frontmatter]
75
95
  end
76
96
 
77
97
  # Render the page as a Markdown string, including optional frontmatter.
@@ -43,8 +43,6 @@ class NotionToMd
43
43
  CONTENT
44
44
  end
45
45
 
46
- private
47
-
48
46
  # Merge custom and default properties into the final set of frontmatter properties.
49
47
  #
50
48
  # @return [Hash{String => Object}]
@@ -52,6 +50,8 @@ class NotionToMd
52
50
  @frontmatter_properties ||= frontmatter_custom_properties.deep_merge(frontmatter_default_properties)
53
51
  end
54
52
 
53
+ private
54
+
55
55
  # Retrieve sanitized custom properties.
56
56
  #
57
57
  # @return [Hash{String => Object}]
@@ -101,7 +101,7 @@ class NotionToMd
101
101
  # @return [Hash{String => Object}]
102
102
  def frontmatter_default_properties
103
103
  @frontmatter_default_properties ||= {
104
- 'id' => id,
104
+ 'id' => metadata['id'],
105
105
  'title' => escape_frontmatter_value(title),
106
106
  'created_time' => created_time,
107
107
  'cover' => cover,
@@ -27,11 +27,6 @@ class NotionToMd
27
27
  base.def_delegators :metadata, :properties
28
28
  end
29
29
 
30
- # @return [String] The Notion record ID.
31
- def id
32
- metadata[:id]
33
- end
34
-
35
30
  # Extract the page or database title.
36
31
  #
37
32
  # @return [String] Plain text concatenated from `title` property.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NotionToMd
4
- VERSION = '3.0.0.beta1'
4
+ VERSION = '3.0.0.beta2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notion_to_md
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta1
4
+ version: 3.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrique Arias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-31 00:00:00.000000000 Z
11
+ date: 2025-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport