Class: CollavreNotion::NotionCreativeExporter
- Inherits:
-
Object
- Object
- CollavreNotion::NotionCreativeExporter
- Includes:
- Collavre::CreativesHelper
- Defined in:
- app/services/collavre_notion/notion_creative_exporter.rb
Instance Method Summary collapse
- #export_blocks ⇒ Object
- #export_tree_blocks(creatives, level = 1, bullet_depth = 0) ⇒ Object
-
#initialize(creative, with_progress: false) ⇒ NotionCreativeExporter
constructor
A new instance of NotionCreativeExporter.
Constructor Details
#initialize(creative, with_progress: false) ⇒ NotionCreativeExporter
Returns a new instance of NotionCreativeExporter.
5 6 7 8 |
# File 'app/services/collavre_notion/notion_creative_exporter.rb', line 5 def initialize(creative, with_progress: false) @creative = creative @with_progress = with_progress end |
Instance Method Details
#export_blocks ⇒ Object
10 11 12 |
# File 'app/services/collavre_notion/notion_creative_exporter.rb', line 10 def export_blocks convert_creative_to_blocks(@creative, level: 1) end |
#export_tree_blocks(creatives, level = 1, bullet_depth = 0) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/services/collavre_notion/notion_creative_exporter.rb', line 14 def export_tree_blocks(creatives, level = 1, bullet_depth = 0) return [] if creatives.blank? blocks = [] creatives.each do |creative| # Convert the creative to blocks creative_blocks = convert_creative_to_blocks(creative, level: level) # Handle children based on the level if creative.respond_to?(:children) && creative.children.present? if level > 3 # For bullet points (level > 3), limit nesting depth to 2 levels max text_content = extract_text_content(creative.effective_description(nil, true).gsub(/<!--.*?-->/m, "").strip) if bullet_depth < 2 # Can still nest deeper children_blocks = export_tree_blocks(creative.children, level + 1, bullet_depth + 1) bullet_block = create_bulleted_list_item_block(text_content, children_blocks) blocks << bullet_block else # Max depth reached, flatten remaining levels bullet_block = create_bulleted_list_item_block(text_content) blocks << bullet_block # Add children as flat bullet points at same level blocks.concat(export_tree_blocks(creative.children, level, bullet_depth)) end else # For headings (level <= 3), add heading then children as separate blocks blocks.concat(creative_blocks) blocks.concat(export_tree_blocks(creative.children, level + 1, 0)) end else # No children, just add the blocks blocks.concat(creative_blocks) end end blocks end |