Skip to content

Commit

Permalink
Add link to internal handbook in homepage intro (#640)
Browse files Browse the repository at this point in the history
* Add link to internal handbook in homepage intro

* Remove duplicate lock

Co-authored-by: Zach Margolis <[email protected]>

---------

Co-authored-by: Zach Margolis <[email protected]>
  • Loading branch information
aduth and zachmargolis authored Dec 12, 2024
1 parent e823906 commit ec8eeb0
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source "https://rubygems.org"

ruby '~> 3.2.2'

gem "activemodel", "~> 8.0.0"
gem "actionpack", "~> 8.0.0"
gem "activesupport", "~> 8.0.0"
gem "actionview", "~> 8.0.0"
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activemodel (8.0.0.1)
activesupport (= 8.0.0.1)
activesupport (8.0.0.1)
base64
benchmark (>= 0.3)
Expand Down Expand Up @@ -176,6 +178,7 @@ PLATFORMS
DEPENDENCIES
actionpack (~> 8.0.0)
actionview (~> 8.0.0)
activemodel (~> 8.0.0)
activesupport (~> 8.0.0)
html-proofer (~> 4.4.3)
jekyll (~> 4)
Expand Down
5 changes: 5 additions & 0 deletions _components/alert_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= tag.div(**tag_options, class: css_class, role:) do %>
<div class="usa-alert__body">
<%= content_tag(text_tag, content, class: 'usa-alert__text') %>
</div>
<% end %>
45 changes: 45 additions & 0 deletions _components/alert_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

class AlertComponent < BaseComponent
attr_reader :type, :message, :tag_options, :text_tag

validates_inclusion_of :type, in: [nil, :info, :success, :warning, :error, :emergency]

def initialize(type: nil, text_tag: 'p', message: nil, **tag_options)
@type = type
@message = message
@tag_options = tag_options
@text_tag = text_tag
end

def role
if type == :error
'alert'
else
'status'
end
end

def css_class
['usa-alert', modifier_css_class, *tag_options[:class]]
end

def modifier_css_class
case type
when :info
'usa-alert--info'
when :success
'usa-alert--success'
when :error
'usa-alert--error'
when :warning
'usa-alert--warning'
when :emergency
'usa-alert--emergency'
end
end

def content
@message || super
end
end
11 changes: 11 additions & 0 deletions _components/base_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require 'active_model'

class BaseComponent < ViewComponent::Base
include ActiveModel::Model

def before_render
validate!
end
end
2 changes: 1 addition & 1 deletion _components/breadcrumb_component.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
class BreadcrumbComponent < ViewComponent::Base; end
class BreadcrumbComponent < BaseComponent; end
15 changes: 12 additions & 3 deletions _plugins/view_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def self.application
end
end

require './_components/base_component.rb'
Dir['_components/**/*.rb'].each { |f| require File.join('.', f) }

class ComponentTag < Liquid::Block
PARAM_SYNTAX = /(\w+)(?:=(?:"([^"]+?)"|(\S+)))?/.freeze
PARAM_SYNTAX = /(\w+)(?:=(?:"([^"]+?)"|(:[a-z_]+)|(\S+)))?/.freeze

def initialize(tag_name, variables, context)
super
Expand All @@ -53,9 +54,11 @@ def initialize(tag_name, variables, context)
# would be assigned to a string literal, and `current` would be `true`.
def parse_params(context)
params = {}
@params.scan(PARAM_SYNTAX) do |key, string, variable|
@params.scan(PARAM_SYNTAX) do |key, string, symbol, variable|
if string
params[key] = string
elsif symbol
params[key] = symbol[1..].to_sym
elsif variable
parts = variable.split('.')
value = context
Expand All @@ -71,7 +74,13 @@ def parse_params(context)
end

def render(context)
content = super.html_safe
content = super
if !content.include?('<')
content = context.registers[:site].
find_converter_instance(Jekyll::Converters::Markdown).
convert(super).sub(/^<p>(.+)<\/p>$/, '\1')
end
content = content.html_safe

component_class = "#{@component_name.camelize}Component".constantize
component = component_class.new(**parse_params(context).symbolize_keys).with_content(content)
Expand Down
4 changes: 4 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ to [avoid contributing sensitive information][sensitive-information].

[sensitive-information]: {{ site.baseurl }}/articles/contributing.html#sensitive-information

{% component alert type=:info %}
Internal documentation can be found in our [Internal Login.gov Handbook](https://lg-public.pages.production.gitlab.login.gov/identity-internal-handbook/).
{% endcomponent %}

## Categories

<div class="margin-bottom-4"></div>
Expand Down

0 comments on commit ec8eeb0

Please sign in to comment.