Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

Commit

Permalink
Add shopify-dev link to suggestion title
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmanzella committed Jan 9, 2023
1 parent fb8d025 commit 365bcf2
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def render(entry)
private

def title(entry)
"### #{entry.name}"
"### [#{entry.name}](#{entry.shopify_dev_url})"
end

def body(entry)
Expand Down
6 changes: 6 additions & 0 deletions lib/theme_check/shopify_liquid/source_index/base_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class BaseEntry

def_delegators :return_type_instance, :generic_type?, :array_type?, :array_type, :to_s, :denied_filters

SHOPIFY_DEV_ROOT_URL = "https://shopify.dev/api/liquid"

def initialize(hash = {})
@hash = hash || {}
@return_type = nil
Expand Down Expand Up @@ -39,6 +41,10 @@ def deprecation_reason
hash['deprecation_reason'] || nil
end

def shopify_dev_url
SHOPIFY_DEV_ROOT_URL
end

attr_writer :return_type

def return_type
Expand Down
4 changes: 4 additions & 0 deletions lib/theme_check/shopify_liquid/source_index/filter_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def parameters
def input_type
@input_type ||= hash['syntax'].split(' | ')[0]
end

def shopify_dev_url
"#{SHOPIFY_DEV_ROOT_URL}/filters/#{hash['name']}"
end
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/theme_check/shopify_liquid/source_index/object_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ class SourceIndex
class ObjectEntry < BaseEntry
def properties
(hash['properties'] || [])
.map { |hash| PropertyEntry.new(hash) }
.map do |prop_hash|
PropertyEntry.new(prop_hash, hash['name'])
end
end

def shopify_dev_url
"#{SHOPIFY_DEV_ROOT_URL}/objects/#{hash['name']}"
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def summary
nil
end

def shopify_dev_url
"#{SHOPIFY_DEV_ROOT_URL}/filters/#{hash['name']}"
end

private

def return_type_hash
Expand Down
14 changes: 13 additions & 1 deletion lib/theme_check/shopify_liquid/source_index/property_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
module ThemeCheck
module ShopifyLiquid
class SourceIndex
class PropertyEntry < BaseEntry; end
class PropertyEntry < BaseEntry
attr_reader :parent_name

def initialize(hash, parent_name)
@hash = hash || {}
@return_type = nil
@parent_name = parent_name
end

def shopify_dev_url
"#{SHOPIFY_DEV_ROOT_URL}/objects/#{parent_name}##{parent_name}-#{hash['name']}"
end
end
end
end
end
4 changes: 4 additions & 0 deletions lib/theme_check/shopify_liquid/source_index/tag_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def return_type_hash
'type' => "tag<#{name}>",
}
end

def shopify_dev_url
"#{SHOPIFY_DEV_ROOT_URL}/tags/#{hash['name']}"
end
end
end
end
Expand Down
90 changes: 77 additions & 13 deletions test/shopify_liquid/documentation/markdown_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ def setup
end

def test_render
entry = SourceIndex::BaseEntry.new(
entry = SourceIndex::ObjectEntry.new(
'name' => 'product',
'summary' => 'A product in the store.',
'description' => 'A more detailed description of a product in the store.',
)

actual_temaplte = @markdown_template.render(entry)
expected_template = "### product\n" \
actual_template = @markdown_template.render(entry)
expected_template = "### [product](https://shopify.dev/api/liquid/objects/product)\n" \
"A product in the store.\n" \
"\n---\n\n" \
"A more detailed description of a product in the store."

assert_equal(expected_template, actual_temaplte)
assert_equal(expected_template, actual_template)
end

def test_render_with_summary_only
Expand All @@ -32,11 +32,11 @@ def test_render_with_summary_only
'summary' => 'A product in the store.'
)

actual_temaplte = @markdown_template.render(entry)
expected_template = "### product\n" \
actual_template = @markdown_template.render(entry)
expected_template = "### [product](https://shopify.dev/api/liquid)\n" \
"A product in the store." \

assert_equal(expected_template, actual_temaplte)
assert_equal(expected_template, actual_template)
end

def test_render_with_description_only
Expand All @@ -45,11 +45,11 @@ def test_render_with_description_only
'description' => 'A more detailed description of a product in the store.'
)

actual_temaplte = @markdown_template.render(entry)
expected_template = "### product\n" \
actual_template = @markdown_template.render(entry)
expected_template = "### [product](https://shopify.dev/api/liquid)\n" \
"A more detailed description of a product in the store." \

assert_equal(expected_template, actual_temaplte)
assert_equal(expected_template, actual_template)
end

def test_render_with_shopify_dev_urls
Expand All @@ -62,13 +62,77 @@ def test_render_with_shopify_dev_urls
BODY
)

actual_temaplte = @markdown_template.render(entry)
expected_template = "### product\n" \
actual_template = @markdown_template.render(entry)
expected_template = "### [product](https://shopify.dev/api/liquid)\n" \
"When you render [...] [`include` tag](https://shopify.dev/api/liquid/tags#include) [...],\n" \
"[`if`](https://shopify.dev/api/liquid/tags#if) [`if`](https://shopify.dev/api/liquid/tags#if)\n" \
"[`unless`](https://shopify.dev/api/liquid/tags#unless) Allows you to specify a [...]\n" \

assert_equal(expected_template, actual_temaplte)
assert_equal(expected_template, actual_template)
end

def test_object_property_entry_title_link
entry = SourceIndex::ObjectEntry.new(
'name' => 'product',
'properties' => [
{
"name" => "created_at",
"summary" => "A timestamp for when the product was created.",
},
]
)

actual_template = @markdown_template.render(entry.properties[0])
expected_template = "### [created_at](https://shopify.dev/api/liquid/objects/product#product-created_at)\n" \
"A timestamp for when the product was created."

assert_equal(expected_template, actual_template)
end

def test_tag_entry_title_link
entry = SourceIndex::TagEntry.new(
"name" => "if",
"summary" => "Renders an expression if a specific condition is `true`.",
)

actual_template = @markdown_template.render(entry)

expected_template = "### [if](https://shopify.dev/api/liquid/tags/if)\n" \
"Renders an expression if a specific condition is `true`."

assert_equal(expected_template, actual_template)
end

def test_filter_title_link
entry = SourceIndex::FilterEntry.new(
"name" => "payment_type_img_url",
"summary" => "Returns the URL for an SVG image of a given [payment type](/api/liquid/objects/shop#shop-enabled_payment_types).",
)

actual_template = @markdown_template.render(entry)

expected_template = "### [payment_type_img_url](https://shopify.dev/api/liquid/filters/payment_type_img_url)\n" \
"Returns the URL for an SVG image of a given [payment type](https://shopify.dev/api/liquid/objects/shop#shop-enabled_payment_types)."

assert_equal(expected_template, actual_template)
end

def test_filter_parameter_entry_title_link
entry = SourceIndex::FilterEntry.new(
"name" => "stylesheet_tag",
"summary" => "Generates an HTML `&lt;link&gt;` tag for a given resource URL.",
"parameters" => [
"description" => "The type of media that the resource applies to.",
"name" => "media",
]
)

actual_template = @markdown_template.render(entry.parameters[0])

expected_template = "### [media](https://shopify.dev/api/liquid/filters/media)\n" \
"The type of media that the resource applies to."

assert_equal(expected_template, actual_template)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/shopify_liquid/documentation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_filter_doc
SourceIndex.stubs(:filters).returns([filter_entry])

actual_doc = Documentation.filter_doc('size')
expected_doc = "### size\n" \
expected_doc = "### [size](https://shopify.dev/api/liquid/filters/size)\n" \
"Returns the size of a string or array.\n" \
"\n---\n\n" \
'You can use the "size" filter with dot notation.'
Expand All @@ -21,7 +21,7 @@ def test_tag_doc
SourceIndex.stubs(:tags).returns([tag_entry])

actual_doc = Documentation.tag_doc('tablerow')
expected_doc = "### tablerow\n" \
expected_doc = "### [tablerow](https://shopify.dev/api/liquid/tags/tablerow)\n" \
'The "tablerow" tag must be wrapped in HTML "table" tags.' \

assert_equal(expected_doc, actual_doc)
Expand All @@ -31,7 +31,7 @@ def test_object_doc
SourceIndex.stubs(:objects).returns([object_entry])

actual_doc = Documentation.object_doc('product')
expected_doc = "### product\n" \
expected_doc = "### [product](https://shopify.dev/api/liquid/objects/product)\n" \
'A product in the store.'

assert_equal(expected_doc, actual_doc)
Expand All @@ -41,7 +41,7 @@ def test_object_property_doc
SourceIndex.stubs(:objects).returns([object_entry])

actual_doc = Documentation.object_property_doc('product', 'available')
expected_doc = "### available\n" \
expected_doc = "### [available](https://shopify.dev/api/liquid/objects/product#product-available)\n" \
'Returns "true" if at least one of the variants of the product is available.'

assert_equal(expected_doc, actual_doc)
Expand Down
2 changes: 1 addition & 1 deletion test/shopify_liquid/source_index/property_entry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ShopifyLiquid
class SourceIndex
class PropertyEntryTest < Minitest::Test
def setup
@entry = PropertyEntry.new(hash)
@entry = PropertyEntry.new(hash, "user_agent")
end

def test_return_type
Expand Down

0 comments on commit 365bcf2

Please sign in to comment.