Skip to content

Commit

Permalink
Implement @location tag
Browse files Browse the repository at this point in the history
  • Loading branch information
allmarkedup committed May 22, 2024
1 parent b80dddc commit 1642133
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ The 'todo' list below is intended to provide a _very rough_ overview of the curr
* [x] `@!group ... @!endgroup`
* [x] `@id` 🆕
* [x] `@priority` 🆕
* [ ] `@logical_path`
* [x] `@location/@logical_path`
* [ ] `@component/@renders`
* [ ] `@source`
* [ ] `@after_render`
Expand Down
5 changes: 3 additions & 2 deletions lib/lookbook/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ def default_preview_tags
[
Lookbook::DisplayTag,
Lookbook::HiddenTag,
Lookbook::IdTag,
Lookbook::LabelTag,
Lookbook::LocationTag,
Lookbook::ParamTag,
Lookbook::PriorityTag,
Lookbook::IdTag
Lookbook::PriorityTag
]
end

Expand Down
8 changes: 7 additions & 1 deletion lib/lookbook/previews/preview_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ def url_param
end

def lookup_path
preview_class_name.underscore.downcase.gsub("_component", "").gsub("_preview", "")
default_lookup_path = preview_class_name.underscore.downcase.gsub("_component", "").gsub("_preview", "")
directory_override = metadata.fetch(:location, metadata.fetch(:logical_path, nil))
if directory_override.nil?
default_lookup_path
else
Utils.strip_slashes("#{directory_override}/#{default_lookup_path.split("/").last}")
end
end

def url_path
Expand Down
10 changes: 10 additions & 0 deletions lib/lookbook/previews/tags/location_tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Lookbook
class LocationTag < YardTag
TAG_NAME = "location"
TAG_ALIASES = ["logical_path"]

def value
Utils.strip_slashes(@text)
end
end
end
4 changes: 4 additions & 0 deletions lib/lookbook/previews/tags/yard_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def name
end

def label = name.titleize

def aliases
defined?(self::TAG_ALIASES) ? self::TAG_ALIASES : []
end
end
end
end
3 changes: 3 additions & 0 deletions lib/lookbook/source_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ def initialize(log_level: YARD::Logger::ERROR, tags: [])
tag_class = tag_class.constantize if tag_class.is_a?(String)

YARD::Tags::Library.define_tag(tag_class.label, tag_class.name, tag_class)
tag_class.aliases.each do |name|
YARD::Tags::Library.define_tag(tag_class.label, name, tag_class)
end
end
end

Expand Down

0 comments on commit 1642133

Please sign in to comment.