Module: ApplicationHelper
- Defined in:
- app/helpers/application_helper.rb
Instance Method Summary collapse
- #code_example(str = nil, language: :erb, toolbar: true, &block) ⇒ Object
- #component_page(&block) ⇒ Object
- #example(**attrs) ⇒ Object
- #lead(text = nil, &block) ⇒ Object
- #markdown(str) ⇒ Object
- #section(**attrs) ⇒ Object
- #section_title(text) ⇒ Object
- #title(text = nil, **attrs, &block) ⇒ Object
Instance Method Details
#code_example(str = nil, language: :erb, toolbar: true, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/application_helper.rb', line 48 def code_example(str = nil, language: :erb, toolbar: true, &block) if block_given? str = capture(&block) .gsub(/{#/, "<%") .gsub(/#}/, "%>") end lexer = Rouge::Lexer.find(language) formatter = Rouge::Formatters::HTML.new tag .div( class: "bg-[#f7f8fa] dark:bg-[#161b22] divide-y border rounded-sm overflow-hidden", data: {controller: "copy-to-clipboard"} ) do if concat( tag.div(class: "px-1 py-1 flex w-full") do concat( ( icon: :copy, size: :xs, data: {copy_to_clipboard_target: "button", action: "copy-to-clipboard#copy"} ) { "Copy" } ) concat( ( icon: :check, size: :xs, data: {copy_to_clipboard_target: "successMessage"}, class: "hidden" ) { "Copied!" } ) end ) end concat( tag .pre( class: "text-sm highlight py-3 px-4 font-mono overflow-scroll", data: {copy_to_clipboard_target: "source"} ) do tag.code do formatter.format(lexer.lex(str.strip_heredoc.strip)).html_safe end end ) end end |
#component_page(&block) ⇒ Object
2 3 4 5 6 |
# File 'app/helpers/application_helper.rb', line 2 def component_page(&block) tag.div(class: "p-5") do capture(&block) end end |
#example(**attrs) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/application_helper.rb', line 33 def example(**attrs) tag .div( **attrs, class: class_names( [ "flex flex-wrap gap-2 justify-center items-center min-h-[200px] py-12 p-5 w-full rounded border overflow-scroll", attrs[:class] ] ) ) do yield end end |
#lead(text = nil, &block) ⇒ Object
13 14 15 16 17 18 |
# File 'app/helpers/application_helper.rb', line 13 def lead(text = nil, &block) text = capture(&block) if block_given? tag.div(class: "text-lg text-gray-600 dark:text-gray-400 mb-6") do text end end |
#markdown(str) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'app/helpers/application_helper.rb', line 99 def markdown(str) Commonmarker .to_html( str.strip_heredoc, options: { parse: {smart: true} } ) .html_safe end |
#section(**attrs) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/helpers/application_helper.rb', line 20 def section(**attrs) tag.div( **attrs, class: class_names("mt-8 space-y-4", attrs[:class]) ) do yield end end |
#section_title(text) ⇒ Object
29 30 31 |
# File 'app/helpers/application_helper.rb', line 29 def section_title(text) tag.h2(class: "text-2xl font-semibold mb-4") { text } end |
#title(text = nil, **attrs, &block) ⇒ Object
8 9 10 11 |
# File 'app/helpers/application_helper.rb', line 8 def title(text = nil, **attrs, &block) text = capture(&block) if block_given? tag.h1(**attrs, class: class_names("text-3xl font-semibold mb-6", attrs[:class])) { text } end |