Class: NotionRubyMapping::Page
- Inherits:
-
Base
- Object
- Base
- NotionRubyMapping::Page
show all
- Defined in:
- lib/notion_ruby_mapping/blocks/page.rb
Overview
Instance Attribute Summary
Attributes inherited from Base
#has_children, #id, #in_trash, #json
Class Method Summary
collapse
Instance Method Summary
collapse
-
#[](key) ⇒ NotionRubyMapping::PropertyCache, Hash
Obtained Page value or PropertyCache.
-
#append_comment(text_objects, dry_run: false) ⇒ Object
-
#build_child_database(title, *assigns) {|db, db.properties| ... } ⇒ NotionRubyMapping::Database
-
#build_child_page(template_page: nil, position: nil, markdown: nil) {|page, pp| ... } ⇒ NotionRubyMapping::Base
-
#create_child_database(title, *assigns, dry_run: false) {|db, db.properties| ... } ⇒ NotionRubyMapping::Database, String
-
#create_child_page(template_page: nil, position: nil, markdown: nil, dry_run: false) {|page, pp| ... } ⇒ NotionRubyMapping::Base
-
#insert_markdown(markdown, after: nil, dry_run: false) ⇒ String, NotionRubyMapping::Base
-
#move_to(page_or_data_source, dry_run: false) ⇒ NotionRubyMapping::Page, String
-
#public_url ⇒ String
-
#replace_markdown(replace, replace_range, allow_deleting_content: nil, dry_run: false) ⇒ String, NotionRubyMapping::Base
-
#title ⇒ String
-
#url ⇒ String
Methods inherited from Base
#append_block_children, #assert_parent_children_pair, #assign_property, #block?, block_id, #children, #comments, #cover, create_from_json, #created_time, #data_source?, data_source_id, #database?, database_id, dry_run_script, #get, #icon, #initialize, #inspect, #json_properties, #last_edited_time, #markdown, #new_record?, #page?, page_id, #parent, #parent_id, #properties, #property_values_json, #reload, #restore_from_json, #save, #set_cover, #set_icon, #synced_block_original?, #update_json
Class Method Details
12
13
14
15
16
17
18
19
20
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 12
def self.find(id, dry_run: false)
nc = NotionCache.instance
page_id = Base.page_id id
if dry_run
Base.dry_run_script :get, nc.page_path(page_id)
else
nc.page page_id
end
end
|
Instance Method Details
Returns obtained Page value or PropertyCache.
24
25
26
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 24
def [](key)
get key
end
|
29
30
31
32
33
34
35
36
37
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 29
def (text_objects, dry_run: false)
rto = RichTextArray.new "rich_text", text_objects: text_objects, will_update: true
json = rto.property_schema_json.merge({"parent" => {"page_id" => @id}})
if dry_run
self.class.dry_run_script :post, @nc., json
else
CommentObject.new json: (@nc. json)
end
end
|
#build_child_database(title, *assigns) {|db, db.properties| ... } ⇒ NotionRubyMapping::Database
43
44
45
46
47
48
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 43
def build_child_database(title, *assigns)
db = Database.new json: {"title" => [TextObject.new(title).property_values_json]},
assign: assigns, parent: {"type" => "page_id", "page_id" => @id}
yield db, db.properties if block_given?
db
end
|
#build_child_page(template_page: nil, position: nil, markdown: nil) {|page, pp| ... } ⇒ NotionRubyMapping::Base
66
67
68
69
70
71
72
73
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 66
def build_child_page(template_page: nil, position: nil, markdown: nil)
page = Page.new assign: [TitleProperty, "title"], parent: {"type" => "page_id", "page_id" => @id},
template_page: template_page, position: position, markdown: markdown
pp = page.properties
pp.clear_will_update
yield page, pp if block_given?
page
end
|
#create_child_database(title, *assigns, dry_run: false) {|db, db.properties| ... } ⇒ NotionRubyMapping::Database, String
55
56
57
58
59
60
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 55
def create_child_database(title, *assigns, dry_run: false)
db = Database.new json: {"title" => [TextObject.new(title).property_values_json]},
assign: assigns, parent: {"type" => "page_id", "page_id" => @id}
yield db, db.properties if block_given?
db.save dry_run: dry_run
end
|
#create_child_page(template_page: nil, position: nil, markdown: nil, dry_run: false) {|page, pp| ... } ⇒ NotionRubyMapping::Base
80
81
82
83
84
85
86
87
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 80
def create_child_page(template_page: nil, position: nil, markdown: nil, dry_run: false)
page = Page.new assign: [TitleProperty, "title"], parent: {"type" => "page_id", "page_id" => @id},
template_page: template_page, position: position, markdown: markdown
pp = page.properties
pp.clear_will_update
yield page, pp if block_given?
page.save dry_run: dry_run
end
|
#insert_markdown(markdown, after: nil, dry_run: false) ⇒ String, NotionRubyMapping::Base
93
94
95
96
97
98
99
100
101
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 93
def insert_markdown(markdown, after: nil, dry_run: false)
json = {"type" => "insert_content", "insert_content" => {"content" => markdown}}
json["insert_content"]["after"] = after if after
if dry_run
self.class.dry_run_script :patch, @nc.markdown_page_path(@id), json
else
update_json @nc.markdown_page_request(@id, json)
end
end
|
#move_to(page_or_data_source, dry_run: false) ⇒ NotionRubyMapping::Page, String
106
107
108
109
110
111
112
113
114
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 106
def move_to(page_or_data_source, dry_run: false)
key = page_or_data_source.is_a?(Page) ? "page_id" : "data_source_id"
json = {"parent" => {"type" => key, key => page_or_data_source.id}}
if dry_run
self.class.dry_run_script :post, @nc.move_page_path(@id), json
else
update_json @nc.move_page_request(@id, json)
end
end
|
#public_url ⇒ String
117
118
119
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 117
def public_url
@json["public_url"]
end
|
#replace_markdown(replace, replace_range, allow_deleting_content: nil, dry_run: false) ⇒ String, NotionRubyMapping::Base
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 125
def replace_markdown(replace, replace_range, allow_deleting_content: nil, dry_run: false)
json = {"type" => "replace_content_range",
"replace_content_range" => {"content" => replace, "content_range" => replace_range}}
json["replace_content_range"]["allow_deleting_content"] = true if allow_deleting_content
if dry_run
self.class.dry_run_script :patch, @nc.markdown_page_path(@id), json
else
update_json @nc.markdown_page_request(@id, json)
end
end
|
#title ⇒ String
138
139
140
141
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 138
def title
tp = properties.select { |p| p.is_a?(TitleProperty) || (p.is_a?(Property) && p.property_id == :title) }
tp.map(&:full_text).join ""
end
|
#url ⇒ String
144
145
146
|
# File 'lib/notion_ruby_mapping/blocks/page.rb', line 144
def url
@json["url"]
end
|