Class: Components::PathTemplatePreview
- Inherits:
-
Base
- Object
- Base
- Components::PathTemplatePreview
- Includes:
- Phlex::Rails::Helpers::TurboFrameTag
- Defined in:
- app/components/path_template_preview.rb
Instance Method Summary collapse
- #before_template ⇒ Object
-
#initialize(library:) ⇒ PathTemplatePreview
constructor
A new instance of PathTemplatePreview.
- #view_template ⇒ Object
Constructor Details
#initialize(library:) ⇒ PathTemplatePreview
Returns a new instance of PathTemplatePreview.
4 5 6 |
# File 'app/components/path_template_preview.rb', line 4 def initialize(library:) @library = library end |
Instance Method Details
#before_template ⇒ Object
8 9 10 11 12 |
# File 'app/components/path_template_preview.rb', line 8 def before_template if @library.valid? && @library. @paths = @library.sample(3).map { [it, PathParserService.new(@library.path_template, it).call] } end end |
#view_template ⇒ 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 |
# File 'app/components/path_template_preview.rb', line 14 def view_template turbo_frame_tag "parse-preview" do if @paths p { t("components.path_template_preview.description") } table class: "table table-striped table-sm" do tr do th { t("components.path_template_preview.path") } th { Creator.model_name.human } th { Collection.model_name.human } th { ActsAsTaggableOn::Tag.model_name.human(count: 100) } th { Model.model_name.human } end @paths.map do |path, parsed| tr do td(style: "word-break: break-all") { path } td { find_or_new_from_path_component(Creator, parsed[:creator])&.name || "❌" } td { parsed[:collections] ? Array(find_or_new_from_path_component(Collection, parsed[:collections])).map(&:name).join(", ") : "❌" } td { parsed[:tags]&.map do Tag tag: ActsAsTaggableOn::Tag.new(name: it), link: false whitespace end || "❌" } td { to_human_name(parsed[:model_name]) || "❌" } end end end end end end |