Class: NotionRails::BaseBlock
- Inherits:
-
Object
- Object
- NotionRails::BaseBlock
- Includes:
- Renderers
- Defined in:
- lib/notion_rails/base_block.rb
Constant Summary collapse
- BLOCK_TYPES =
%w[ paragraph heading_1 heading_2 heading_3 bulleted_list_item numbered_list_item quote callout code image video table_of_contents ].freeze
Instance Attribute Summary collapse
-
#archived ⇒ Object
readonly
TODO: validate object type is block.
-
#children ⇒ Object
TODO: validate object type is block.
-
#created_by ⇒ Object
readonly
TODO: validate object type is block.
-
#created_time ⇒ Object
readonly
TODO: validate object type is block.
-
#has_children ⇒ Object
readonly
TODO: validate object type is block.
-
#id ⇒ Object
readonly
TODO: validate object type is block.
-
#last_edited_by ⇒ Object
readonly
TODO: validate object type is block.
-
#last_edited_time ⇒ Object
readonly
TODO: validate object type is block.
-
#parent ⇒ Object
readonly
TODO: validate object type is block.
-
#properties ⇒ Object
readonly
TODO: validate object type is block.
-
#siblings ⇒ Object
TODO: validate object type is block.
-
#type ⇒ Object
readonly
TODO: validate object type is block.
Instance Method Summary collapse
- #icon ⇒ Object
-
#initialize(data) ⇒ BaseBlock
constructor
A new instance of BaseBlock.
- #multi_media ⇒ Object
- #render(options = {}) ⇒ Object
- #rich_text ⇒ Object
Methods included from Renderers
#annotation_to_css_class, #render_bulleted_list_item, #render_callout, #render_code, #render_date, #render_heading_1, #render_heading_2, #render_heading_3, #render_image, #render_list_items, #render_numbered_list_item, #render_paragraph, #render_quote, #render_title, #render_video, #text_renderer
Constructor Details
#initialize(data) ⇒ BaseBlock
Returns a new instance of BaseBlock.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/notion_rails/base_block.rb', line 39 def initialize(data) @id = data['id'] @created_time = data['created_time'] @last_edited_time = data['last_edited_time'] # TODO: handle user object @created_by = data['created_by'] @last_edited_by = data['last_edited_by'] # TODO: handle page_id type @parent = data['parent'] @archived = data['archived'] @has_children = data['has_children'] @children = [] @siblings = [] @type = data['type'] @properties = data[@type] end |
Instance Attribute Details
#archived ⇒ Object (readonly)
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def archived @archived end |
#children ⇒ Object
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def children @children end |
#created_by ⇒ Object (readonly)
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def created_by @created_by end |
#created_time ⇒ Object (readonly)
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def created_time @created_time end |
#has_children ⇒ Object (readonly)
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def has_children @has_children end |
#id ⇒ Object (readonly)
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def id @id end |
#last_edited_by ⇒ Object (readonly)
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def last_edited_by @last_edited_by end |
#last_edited_time ⇒ Object (readonly)
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def last_edited_time @last_edited_time end |
#parent ⇒ Object (readonly)
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def parent @parent end |
#properties ⇒ Object (readonly)
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def properties @properties end |
#siblings ⇒ Object
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def siblings @siblings end |
#type ⇒ Object (readonly)
TODO: validate object type is block
9 10 11 |
# File 'lib/notion_rails/base_block.rb', line 9 def type @type end |
Instance Method Details
#icon ⇒ Object
81 82 83 84 |
# File 'lib/notion_rails/base_block.rb', line 81 def icon icon = @properties['icon'] @properties['icon'][icon['type']] || [] end |
#multi_media ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/notion_rails/base_block.rb', line 86 def multi_media case @properties['type'] when 'file' [@properties.dig('file', 'url'), @properties.dig('file', 'expiry_time'), @properties['caption'], 'file'] when 'external' [@properties.dig('external', 'url'), nil, @properties['caption'], 'external'] else [nil, nil, @properties['caption'], nil] end end |
#render(options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/notion_rails/base_block.rb', line 56 def render( = {}) case @type when 'paragraph' then render_paragraph(rich_text, class: [:paragraph]) when 'heading_1' then render_heading_1(rich_text, class: [:heading_1]) when 'heading_2' then render_heading_2(rich_text, class: [:heading_2]) when 'heading_3' then render_heading_3(rich_text, class: [:heading_3]) when 'table_of_contents' then render_table_of_contents when 'bulleted_list_item' render_bulleted_list_item(rich_text, @siblings, @children, class: [:bulleted_list_item]) when 'numbered_list_item' render_numbered_list_item(rich_text, @siblings, @children, class: [:numbered_list_item]) when 'quote' then render_quote(rich_text, class: [:quote]) when 'callout' then render_callout(rich_text, icon, class: [:callout]) when 'code' then render_code(rich_text, class: [:code], language: @properties['language']) when 'image' then render_image(*multi_media, class: [:image]) when 'video' then render_video(*multi_media, class: [:video]) else 'Error' end end |
#rich_text ⇒ Object
77 78 79 |
# File 'lib/notion_rails/base_block.rb', line 77 def rich_text @properties['rich_text'] || [] end |