Skip to content

Instantly share code, notes, and snippets.

@bholtbholt
Last active October 12, 2017 22:40
Show Gist options
  • Save bholtbholt/69d5f31a1642dd6be822c00088b0eeda to your computer and use it in GitHub Desktop.
Save bholtbholt/69d5f31a1642dd6be822c00088b0eeda to your computer and use it in GitHub Desktop.
Ruby on Rails server-side component library
- options[:text_link][:class] = "comp_academy-banner-link" if options[:text_link]
- options[:text_link][:target] = "_blank" if options[:text_link]
- options[:text_link][:label] << " »" if options[:text_link]
- options[:image_src] ||= "legacy/knowledge_base_icon.png"
%header.comp_academy-banner{ id: options[:id] }
= image_tag( options[:image_src], alt: "Unbounce Academy Icon", class: "margin-right flex-auto", width: options[:image_width] )
.flex-expand
= content_tag(:h3, options[:title], class: "comp_title") if options[:title]
= content_tag(:p, options[:text]) if options[:text]
= prefix_component(:text_link, options[:text_link]) if options[:text_link]
- description ||= false
- if description
%h2 :academy_banner
%p
The
%strong :banner
is meant to provide additional information. It often contains an external link to the Academy, which automatically opens in a new window. It includes the Academy logo automatically.
- schema = { id: "The ID of the banner",
title: "Banner title text.",
text: "Paragraph text next to the Academy logo",
image_src: "Takes a string path to display an alternative image instead of the Academy Logo. Defaults to academy logo.",
image_width: "The width attribute on the image tag",
text_link: "Calls :text_link. Options must be passed as a nested hash. Automatically assigns target to '_blank'",
}
- state = { id: "example-id",
title: "This is the academy banner title",
text: "<strong>Please note:</strong> This is the text.".html_safe,
text_link: { label: "This is the page banner link" },
}
- options ||= state
= render partial: "components/#{File.basename(__FILE__).sub(/^_/,'')}", locals: { options: options }
= prefix_component(:schema, schema)
module ApplicationHelper
def prefix_component(component, options = {})
render partial: "components/#{component}", locals: { options: options }
rescue ActionView::MissingTemplate
render partial: "components/help", locals: { component: component }
end
end
require 'spec_helper'
describe 'Component documentation' do
it 'should exist for all components' do
Dir.foreach("#{Rails.root}/app/views/components/") do |file|
next unless file.start_with?("_")
documentation_file = File.file?("#{Rails.root}/app/views/components/documentation/#{file}")
expect(documentation_file).to be(true), "#{file} doesn't exist in components/documentation"
end
end
end
= prefix_component(:academy_banner,
id: "academy-banner-id",
title: "This is the Academy Banner",
text: "This is supporting text"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment