Module: ExamplesHelper
- Defined in:
- app/helpers/examples_helper.rb
Instance Method Summary collapse
- #code_partial(name, language) ⇒ Object
- #code_sample(content = "", language:, &block) ⇒ Object
- #inline_code(content = nil, &block) ⇒ Object (also: #code)
- #render_code_preview(name) ⇒ Object
- #render_component_header(title:, description:) ⇒ Object
- #render_example ⇒ Object
- #render_preview ⇒ Object
- #render_usage(name) ⇒ Object
Instance Method Details
#code_partial(name, language) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/helpers/examples_helper.rb', line 22 def code_partial(name, language) component, partial = name.split("/") content_tag :pre, class: "code-sample py-4 px-4", data: {controller: "highlight"} do content_tag :code, class: "language-#{language}" do html_escape(File.read(Rails.root.join("app", "views", "examples", "components", "#{component}/code/_#{partial}.erb"))) end end end |
#code_sample(content = "", language:, &block) ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/helpers/examples_helper.rb', line 31 def code_sample(content = "", language:, &block) content_tag :pre, class: "code-sample px-4 my-2 pb-5 min-h-fit", data: {controller: "highlight"} do content_tag :code, class: "language-#{language}" do yield if block end end end |
#inline_code(content = nil, &block) ⇒ Object Also known as: code
39 40 41 42 43 |
# File 'app/helpers/examples_helper.rb', line 39 def inline_code(content = nil, &block) content_tag :code, class: "relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono font-semibold" do content || yield(block) end end |
#render_code_preview(name) ⇒ Object
18 19 20 |
# File 'app/helpers/examples_helper.rb', line 18 def render_code_preview(name) render "examples/components/#{name}/code/preview" end |
#render_component_header(title:, description:) ⇒ Object
2 3 4 |
# File 'app/helpers/examples_helper.rb', line 2 def render_component_header(title:, description:) render "layouts/documentation/component_header", title:, description: end |
#render_example ⇒ Object
6 7 8 |
# File 'app/helpers/examples_helper.rb', line 6 def render_example render "layouts/documentation/examples" end |
#render_preview ⇒ Object
10 11 12 |
# File 'app/helpers/examples_helper.rb', line 10 def render_preview render "layouts/documentation/preview" end |
#render_usage(name) ⇒ Object
14 15 16 |
# File 'app/helpers/examples_helper.rb', line 14 def render_usage(name) render "examples/components/#{name}/usage" end |