From 86bd96563aa8e5d92069444ba01011b788e9ff25 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Thu, 18 Dec 2025 16:13:19 -0700 Subject: [PATCH 1/7] Add agents file --- AGENTS.md | 15 +++++++++++++++ Gemfile.lock | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..f02577a --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,15 @@ +# Build Commands +- Setup: bin/setup +- Test all: rake test +- Test single: ruby -I test test/dast_document_test.rb --name +- Lint: rake standard + +# Code Style +- frozen_string_literal: true at file top +- require_relative for internal requires +- StandardRB linting (ruby 2.6+) +- RBS type signatures required +- Minitest for testing +- Nokogiri for HTML parsing +- Use &. safe navigation, then chaining +- Descriptive test method names \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 863c957..0892bb3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - dast_document (0.1.0) + dast_document (1.2.0) nokogiri (>= 1.13.4) GEM From 3803e8e505010a1ef4939e35e0d211347b7333b5 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Thu, 18 Dec 2025 16:19:40 -0700 Subject: [PATCH 2/7] Fix broken test --- test/dast_document_test.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/dast_document_test.rb b/test/dast_document_test.rb index 90af990..d87cc4f 100644 --- a/test/dast_document_test.rb +++ b/test/dast_document_test.rb @@ -62,12 +62,12 @@ def test_no_component end module Components - class TextWithImageComponent + class TextWithImage def initialize(resource:) @resource = resource end - def render_in(context) + def render_in(_context) "

Rendered

" end end @@ -76,7 +76,9 @@ def render_in(context) def test_everything blocks = OpenStruct.new(id: "AS6rmJJ2Qpqs5woeo6C6SQ", text: "Amazing", _model_api_key: "text_with_image") dast = OpenStruct.new(value: SAMPLE_DOCUMENT, blocks: [blocks]) - @document = DastDocument::Document.new(dast, component_module: Components, view_context: OpenStruct.new({})).walk + view_context = OpenStruct.new({}) + view_context.define_singleton_method(:render) { |component| component.render_in(self) } + @document = DastDocument::Document.new(dast, component_module: Components, view_context: view_context).walk assert_equal @document.css("h3").text, "Rendered" end end From f319c8d833b24a90e45a2fa963585d270d564fc4 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Thu, 18 Dec 2025 16:45:32 -0700 Subject: [PATCH 3/7] Update readme & add changelog --- CHANGELOG.md | 31 ++++++++++++++++++++++++++++++- README.md | 31 +++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09fb4d2..6997fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,34 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + ## [Unreleased] +## [1.2.0] - 2024-02-22 + +### Added +- Support for ordered lists and horizontal rules in HTML output. +- AGENTS.md file with project information and build commands. + +### Changed +- Major library rewrite to support passing blocks and custom components for enhanced rendering flexibility. +- Removed requirement for "Component" suffix in block names, simplifying component naming conventions. +- Improved newline handling in text content for more accurate HTML rendering. +- Code cleanup and refactoring for better maintainability. +- Added RuboCop configuration for improved code style and linting. + +### Fixed +- Added null checks to prevent runtime errors during document processing. +- Corrected data passing in block rendering to ensure components receive accurate content. +- Minor adjustments to block rendering functionality for improved reliability. +- Fixed broken test case to maintain test suite integrity. + ## [0.1.0] - 2024-01-31 -- Initial release +### Added +- Initial release with basic HTML rendering and structured document support. + +[1.2.0]: https://github.com/paradem/dast_document/releases/tag/v1.2.0 diff --git a/README.md b/README.md index fa49d90..3c472a6 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,35 @@ # DastDocument -TODO: Delete this and the text below, and describe your gem - -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dast_document`. To experiment with that code, run `bin/console` for an interactive prompt. +A Ruby gem for rendering DatoCMS DAST (DatoCMS Abstract Syntax Tree) documents into HTML. Supports rich text elements (headings, paragraphs, lists) and embedded blocks with custom components. ## Installation -TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org. - Install the gem and add to the application's Gemfile by executing: - $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG + $ bundle add dast_document If bundler is not being used to manage dependencies, install the gem by executing: - $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG + $ gem install dast_document ## Usage -TODO: Write usage instructions here +Basic usage: + +```ruby +require 'dast_document' + +dast = { "value" => { "document" => { "type" => "document", "children" => [...] } }, "blocks" => [...] } +document = DastDocument::Document.new(dast) +html = document.to_html +``` + +For blocks with custom components: + +```ruby +# Assuming Rails view context and component module +document = DastDocument::Document.new(dast, view_context: self, component_module: Components) +``` ## Development @@ -28,8 +39,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dast_document. +Bug reports and pull requests are welcome on GitHub at https://github.com/paradem/dast_document. ## License -The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). \ No newline at end of file From b96000f923a1f25c3505f894ecda04d60bec7c8e Mon Sep 17 00:00:00 2001 From: David Higgins Date: Thu, 18 Dec 2025 16:56:07 -0700 Subject: [PATCH 4/7] Add edge case to test suite --- test/dast_document_test.rb | 183 ++++++++++++++++++++++++++++++++++++- test/test_helper.rb | 7 ++ test/test_runner.rb | 14 +++ 3 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 test/test_runner.rb diff --git a/test/dast_document_test.rb b/test/dast_document_test.rb index d87cc4f..6151c7d 100644 --- a/test/dast_document_test.rb +++ b/test/dast_document_test.rb @@ -1,4 +1,4 @@ -require "test_helper" +require_relative "test_helper" require "ostruct" class DastDocumentTest < Minitest::Test @@ -81,4 +81,185 @@ def test_everything @document = DastDocument::Document.new(dast, component_module: Components, view_context: view_context).walk assert_equal @document.css("h3").text, "Rendered" end + + def test_empty_document + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => []}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.children.count, 0 + end + + def test_headings_valid_levels + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "heading", "level" => 1, "value" => "H1"}, + {"type" => "heading", "level" => 6, "value" => "H6"} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.css("h1").text, "H1" + assert_equal @document.css("h6").text, "H6" + end + + def test_headings_invalid_levels + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "heading", "level" => 0, "value" => "H0"}, + {"type" => "heading", "level" => 7, "value" => "H7"}, + {"type" => "heading", "level" => nil, "value" => "Hnil"} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.css("h0").text, "H0" + assert_equal @document.css("h7").text, "H7" + assert_equal @document.css("h").text, "Hnil" + end + + def test_unordered_list + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "list", "style" => "bullet", "children" => [ + {"type" => "listItem", "children" => [{"type" => "paragraph", "children" => [{"type" => "span", "value" => "item"}]}]} + ]} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.css("ul").count, 1 + assert_equal @document.css("ul li").text, "item" + end + + def test_list_no_style + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "list", "children" => [ + {"type" => "listItem", "children" => [{"type" => "paragraph", "children" => [{"type" => "span", "value" => "item"}]}]} + ]} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.css("ul").count, 1 + end + + def test_span_multiple_marks + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "paragraph", "children" => [{"type" => "span", "value" => "text", "marks" => %w[emphasis underline]}]} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.css("p em u").text, "text" + end + + def test_span_unknown_mark + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "paragraph", "children" => [{"type" => "span", "value" => "text", "marks" => ["bold"]}]} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.css("p bold").text, "text" + end + + def test_span_empty_value + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "paragraph", "children" => [{"type" => "span", "value" => ""}]} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.css("p span").text, "" + end + + def test_link_empty_url + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "link", "url" => ""} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.css("a").attr("href").value, "" + end + + def test_blockquote_empty_attribution + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "blockquote", "attribution" => ""} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.css("figure blockquote").count, 1 + assert_equal @document.css("figcaption").text, "" + end + + def test_blockquote_with_children + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "blockquote", "attribution" => "Author", "children" => [ + {"type" => "paragraph", "children" => [{"type" => "span", "value" => "Quote text"}]} + ]} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.css("figure blockquote p").text, "Quote text" + assert_equal @document.css("figcaption").text, "Author" + end + + def test_unknown_node_type + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "unknown"} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.children.count, 0 + end + + def test_node_missing_type + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"value" => "text"} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal @document.children.count, 0 + end + + def test_paragraph_newlines + dast = OpenStruct.new(value: {"document" => {"type" => "root", "children" => [ + {"type" => "paragraph", "value" => "line1\n\nline2"} + ]}}, blocks: []) + @document = DastDocument::Document.new(dast).walk + assert_equal "line1
line2", @document.css("p").first.inner_html + end + + def test_block_wrapper_nil_content + block_wrapper = DastDocument::BlockWrapper.new(nil) + assert_nil block_wrapper.id + assert_nil block_wrapper.name + assert_equal block_wrapper.component_name, "" + end + + def test_block_invalid_model_api_key + blocks = OpenStruct.new(id: "id", _model_api_key: nil) + block_wrapper = DastDocument::BlockWrapper.new(blocks) + assert_nil block_wrapper.name + assert_equal block_wrapper.component_name, "" + end + + def test_block_model_api_key_empty + blocks = OpenStruct.new(id: "id", _model_api_key: "") + block_wrapper = DastDocument::BlockWrapper.new(blocks) + assert_equal block_wrapper.name, "" + assert_equal block_wrapper.component_name, "" + end + + def test_block_model_api_key_no_underscore + blocks = OpenStruct.new(id: "id", _model_api_key: "textwithimage") + block_wrapper = DastDocument::BlockWrapper.new(blocks) + assert_equal block_wrapper.name, "Textwithimage" + end + + def test_view_context_no_render_method + blocks = OpenStruct.new(id: "AS6rmJJ2Qpqs5woeo6C6SQ", _model_api_key: "text_with_image") + dast = OpenStruct.new(value: SAMPLE_DOCUMENT, blocks: [blocks]) + view_context = OpenStruct.new({}) + document = DastDocument::Document.new(dast, component_module: Components, view_context: view_context) + assert_raises(NoMethodError) { document.walk } + end + + def test_to_html + dast = OpenStruct.new(value: SAMPLE_DOCUMENT, blocks: []) + document = DastDocument::Document.new(dast) + html = document.to_html + assert html.is_a?(String) + assert html.include?("
    ") + assert html.include?("
    ") + end + + def test_multiple_blocks_same_id + blocks = [ + OpenStruct.new(id: "AS6rmJJ2Qpqs5woeo6C6SQ", _model_api_key: "text_with_image"), + OpenStruct.new(id: "AS6rmJJ2Qpqs5woeo6C6SQ", _model_api_key: "another_block") + ] + dast = OpenStruct.new(value: SAMPLE_DOCUMENT, blocks: blocks) + view_context = OpenStruct.new({}) + view_context.define_singleton_method(:render) { |component| component.render_in(self) } + @document = DastDocument::Document.new(dast, component_module: Components, view_context: view_context).walk + assert_equal @document.css("h3").text, "Rendered" # Only first rendered + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 7edc7db..ea8dd10 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,4 +3,11 @@ $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "dast_document" +ENV["MINITEST_PLUGINS"] = nil require "minitest/autorun" + +class String + def html_safe + self + end +end diff --git a/test/test_runner.rb b/test/test_runner.rb new file mode 100644 index 0000000..5294c6f --- /dev/null +++ b/test/test_runner.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Minitest + def self.load_plugins + # do nothing + end +end + +require "minitest" + +require_relative "test_helper" +require_relative "dast_document_test" + +Minitest.run From b9bae69e50fc2aff641b5401db611a4b6fcdcb00 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Thu, 18 Dec 2025 17:02:42 -0700 Subject: [PATCH 5/7] Update documentation --- CHANGELOG.md | 8 +++++ README.md | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 94 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6997fd7..a47ef3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Comprehensive edge case tests for DastDocument rendering: + - Empty documents, invalid node types, and missing data handling. + - Text formatting with multiple marks, unknown marks, and newlines. + - Advanced node types: blockquotes, links, unordered lists. + - Block rendering edge cases: multiple blocks, missing components/view contexts. + - HTML output validation via `to_html` method. + ## [1.2.0] - 2024-02-22 ### Added diff --git a/README.md b/README.md index 3c472a6..b9d1e2c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,20 @@ A Ruby gem for rendering DatoCMS DAST (DatoCMS Abstract Syntax Tree) documents into HTML. Supports rich text elements (headings, paragraphs, lists) and embedded blocks with custom components. +## Table of Contents + +- [Installation](#installation) +- [Usage](#usage) + - [Basic Document Rendering](#basic-document-rendering) + - [Text Formatting and Marks](#text-formatting-and-marks) + - [Links and Blockquotes](#links-and-blockquotes) + - [Blocks and Custom Components](#blocks-and-custom-components) + - [Edge Cases and Error Handling](#edge-cases-and-error-handling) + - [Supported Node Types](#supported-node-types) +- [Development](#development) +- [Contributing](#contributing) +- [License](#license) + ## Installation Install the gem and add to the application's Gemfile by executing: @@ -14,23 +28,92 @@ If bundler is not being used to manage dependencies, install the gem by executin ## Usage -Basic usage: +### Basic Document Rendering + +Basic usage for rendering a DAST document into HTML: ```ruby require 'dast_document' -dast = { "value" => { "document" => { "type" => "document", "children" => [...] } }, "blocks" => [...] } +dast = { "value" => { "document" => { "type" => "root", "children" => [ + { "type" => "paragraph", "children" => [{ "type" => "span", "value" => "Hello world!" }] }, + { "type" => "heading", "level" => 1, "value" => "Title" }, + { "type" => "list", "style" => "numbered", "children" => [ + { "type" => "listItem", "children" => [{ "type" => "paragraph", "children" => [{ "type" => "span", "value" => "Item 1" }] }] } + ] } +] } }, "blocks" => [] } +document = DastDocument::Document.new(dast) +html = document.to_html +# Output:

    Hello world!

    Title

    1. Item 1

    +``` + +Note: Newlines in text content are automatically converted to `
    ` tags (e.g., "line1\n\nline2" becomes "line1
    line2"). + +### Text Formatting and Marks + +Apply rich text formatting using marks on spans: + +```ruby +dast = { "value" => { "document" => { "type" => "root", "children" => [ + { "type" => "paragraph", "children" => [ + { "type" => "span", "value" => "Bold and italic", "marks" => ["emphasis", "underline"] } + ] } +] } }, "blocks" => [] } +document = DastDocument::Document.new(dast) +html = document.to_html +# Output:

    Bold and italic

    +``` + +Unknown marks fall back to using the mark name as the HTML tag. + +### Links and Blockquotes + +Render links and blockquotes: + +```ruby +dast = { "value" => { "document" => { "type" => "root", "children" => [ + { "type" => "link", "url" => "https://example.com" }, + { "type" => "blockquote", "attribution" => "Author Name", "children" => [ + { "type" => "paragraph", "children" => [{ "type" => "span", "value" => "Quote text" }] } + ] } +] } }, "blocks" => [] } document = DastDocument::Document.new(dast) html = document.to_html +# Output:

    Quote text

    Author Name
    ``` -For blocks with custom components: +### Blocks and Custom Components + +For blocks with custom components, provide a view context and component module: ```ruby # Assuming Rails view context and component module document = DastDocument::Document.new(dast, view_context: self, component_module: Components) ``` +If a component is missing or view context lacks a render method, error messages are displayed in the HTML output (e.g., "Can't render block ComponentName no component defined"). + +### Edge Cases and Error Handling + +The gem handles malformed or missing data gracefully: +- Empty documents or missing node types are skipped without errors. +- Invalid inputs (e.g., non-integer heading levels) are rendered as-is or with defaults. +- Unknown node types are ignored, ensuring robust rendering. + +### Supported Node Types + +| Node Type | Description | Example Output | +|----------------|--------------------------------------|----------------| +| paragraph | Text paragraph | `

    Text

    ` | +| heading | Headings (levels 1-6) | `

    Title

    ` | +| list | Ordered/unordered lists | `
    1. Item
    ` or `
      ` | +| listItem | List items | `
    • Item
    • ` | +| span | Text with marks | `Text` or `Text` | +| link | Links | `` | +| blockquote | Blockquotes with attribution | `
      Text
      Attr
      ` | +| thematicBreak | Horizontal rules | `
      ` | +| block | Embedded blocks with components | Custom component HTML | + ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. From 8866d447f6da91a114db65b99e9353f26a8446b9 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Thu, 18 Dec 2025 17:17:50 -0700 Subject: [PATCH 6/7] Bump ruby version - Patching vulnerabilities - Adding missing dependancies - Linting - Update changelog - Bumping gem version --- .standard.yml | 2 +- .tool-versions | 1 + CHANGELOG.md | 12 ++++++++++- Gemfile.lock | 17 +++++++++------- dast_document.gemspec | 4 +++- lib/dast_document.rb | 2 ++ lib/dast_document/block_wrapper.rb | 3 +++ lib/dast_document/version.rb | 2 +- sig/dast_document.rbs | 32 ++++++++++++++++++++++++++++-- test/dast_document_test.rb | 2 ++ 10 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 .tool-versions diff --git a/.standard.yml b/.standard.yml index 8825305..1c922d7 100644 --- a/.standard.yml +++ b/.standard.yml @@ -1,3 +1,3 @@ # For available configuration options, see: # https://github.com/standardrb/standard -ruby_version: 2.6 +ruby_version: 3.2 diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..5184db8 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 3.4.5 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a47ef3e..eea7df3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [1.3.0] - 2025-12-19 ### Added - Comprehensive edge case tests for DastDocument rendering: @@ -15,6 +15,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Block rendering edge cases: multiple blocks, missing components/view contexts. - HTML output validation via `to_html` method. +### Changed +- Bump required Ruby version from >= 3.2.2 to >= 3.4.5 +- Update Nokogiri dependency from >= 1.13.4 to >= 1.18.9 +- Add REXML >= 3.3.9 as runtime dependency + +### Security +- Address multiple CVEs in Nokogiri (e.g., libxml2/libxslt vulnerabilities) +- Address REXML DoS vulnerabilities by requiring Ruby >= 3.4.5 or REXML >= 3.3.9 + ## [1.2.0] - 2024-02-22 ### Added @@ -39,4 +48,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release with basic HTML rendering and structured document support. +[1.3.0]: https://github.com/paradem/dast_document/releases/tag/v1.3.0 [1.2.0]: https://github.com/paradem/dast_document/releases/tag/v1.2.0 diff --git a/Gemfile.lock b/Gemfile.lock index 0892bb3..91a2de2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,10 @@ PATH remote: . specs: - dast_document (1.2.0) - nokogiri (>= 1.13.4) + dast_document (1.3.0) + nokogiri (>= 1.18.9) + ostruct (>= 0.6.0) + rexml (>= 3.3.9) GEM remote: https://rubygems.org/ @@ -11,22 +13,23 @@ GEM json (2.7.1) language_server-protocol (3.17.0.3) lint_roller (1.1.0) - mini_portile2 (2.8.5) + mini_portile2 (2.8.9) minitest (5.21.2) - nokogiri (1.16.0) + nokogiri (1.18.10) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.16.0-arm64-darwin) + nokogiri (1.18.10-arm64-darwin) racc (~> 1.4) + ostruct (0.6.3) parallel (1.24.0) parser (3.3.0.5) ast (~> 2.4.1) racc - racc (1.7.3) + racc (1.8.1) rainbow (3.1.1) rake (13.1.0) regexp_parser (2.9.0) - rexml (3.2.6) + rexml (3.4.4) rubocop (1.59.0) json (~> 2.3) language_server-protocol (>= 3.17.0) diff --git a/dast_document.gemspec b/dast_document.gemspec index 5b71aeb..a33f80e 100644 --- a/dast_document.gemspec +++ b/dast_document.gemspec @@ -30,7 +30,9 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_runtime_dependency "nokogiri", ">= 1.13.4" + spec.add_runtime_dependency "nokogiri", ">= 1.18.9" + spec.add_runtime_dependency "ostruct", ">= 0.6.0" + spec.add_runtime_dependency "rexml", ">= 3.3.9" # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html diff --git a/lib/dast_document.rb b/lib/dast_document.rb index cd832ac..0d7e24d 100644 --- a/lib/dast_document.rb +++ b/lib/dast_document.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "nokogiri" require_relative "dast_document/version" diff --git a/lib/dast_document/block_wrapper.rb b/lib/dast_document/block_wrapper.rb index afeb47b..957cc6f 100644 --- a/lib/dast_document/block_wrapper.rb +++ b/lib/dast_document/block_wrapper.rb @@ -1,6 +1,9 @@ +# frozen_string_literal: true + module DastDocument class BlockWrapper attr_reader :content + def initialize(content) @content = content end diff --git a/lib/dast_document/version.rb b/lib/dast_document/version.rb index 572cc09..6819a0b 100644 --- a/lib/dast_document/version.rb +++ b/lib/dast_document/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module DastDocument - VERSION = "1.2.0" + VERSION = "1.3.0" end diff --git a/sig/dast_document.rbs b/sig/dast_document.rbs index 7b6ef03..653821d 100644 --- a/sig/dast_document.rbs +++ b/sig/dast_document.rbs @@ -1,4 +1,32 @@ module DastDocument VERSION: String - # See the writing guide of rbs: https://github.com/ruby/rbs#guides -end + + class Error < StandardError + end + + class Document + def initialize: (untyped dast, ?view_context: untyped, ?component_module: Module) -> void + def to_html: -> String + def walk: -> untyped + def _walk: (untyped doc, untyped dast) -> untyped + def component_defined?: (String component) -> bool + def build_tag: (untyped node) -> untyped + def build_block: (String id) -> String + def build_list: (untyped node) -> String + def children: (untyped dast_node) -> void + def build_a: (String url) -> String + def build_blockquote: (String attribution) -> String + def build_node: (String tag_name, untyped value, ?untyped marks) -> String + def markup: (untyped value, untyped marks) -> untyped + def t: (String mark) -> String + end + + class BlockWrapper + attr_reader content: untyped + def initialize: (untyped content) -> void + def nil?: -> bool + def id: -> untyped + def name: -> untyped + def component_name: -> String + end +end \ No newline at end of file diff --git a/test/dast_document_test.rb b/test/dast_document_test.rb index 6151c7d..77737c4 100644 --- a/test/dast_document_test.rb +++ b/test/dast_document_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "test_helper" require "ostruct" From 2b369bec2f7b1860af1ebccd0981f14b9bfadb86 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Thu, 18 Dec 2025 17:25:39 -0700 Subject: [PATCH 7/7] Add github actions --- .github/workflows/main.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3a4835a..50f3575 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,6 +15,7 @@ jobs: matrix: ruby: - '3.2.2' + - '3.4.5' steps: - uses: actions/checkout@v4 @@ -23,5 +24,9 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - name: Run the default task - run: bundle exec rake + - name: Run setup + run: bin/setup + - name: Run tests + run: bundle exec rake test + - name: Run lint + run: bundle exec rake standard