Skip to content

Commit

Permalink
Support symbol and string keys for some components
Browse files Browse the repository at this point in the history
This is a transitional change to switch components that expect
string key'd objects to handle symbol key'd objects only.

We should only use one style of keys for objects used in components,
to avoid reduce confusion when using components (I spent a while
trying to work out why the arguements I was passing to prev/next
weren't rendering). Consistency is good.

After discussion with @edds we agreed to use symbols consistently,
as this makes more sense in a ruby/rails environment.

The first step is to support both, as clients of those components
will still be sending string key;d objects and can't be updated
at the time as this app, so we have to;

 1. Support both kinds of keys on components that expect strings
 2. Update clients sending string keys to use symbols instead
 3. Remove support for string keys from these components

This PR is step 1., and using `with_indifferent_access` is a quick
hack to support both, which we can remove at step 3.
  • Loading branch information
David Singleton committed Jun 16, 2015
1 parent d9d042f commit 0593bf6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions app/views/govuk_component/option_select.raw.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
<div class='options-container' id='<%= options_container_id %>'>
<div class='js-auto-height-inner'>
<% options.each do | option |%>

<label for='<%= option['id'] %>'>
<% option = option.with_indifferent_access %>
<label for='<%= option[:id] %>'>
<input
name="<%= key %>[]"
value="<%= option['value']%>"
id="<%= option['id']%>"
value="<%= option[:value]%>"
id="<%= option[:id]%>"
type="checkbox"

<% if local_assigns.include?(:aria_controls_id) %>
aria-controls="<%= aria_controls_id %>"
<% end %>

<% if option['checked'].present? %>
<% if option[:checked].present? %>
checked="checked"
<% end %>

>
<%= option['label']%>
<%= option[:label] %>
</label>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<nav class="govuk-previous-and-next-navigation" role="navigation" aria-label="Pagination">
<ul class="group">
<% if local_assigns.include?(:previous_page) %>
<% previous_page = previous_page.with_indifferent_access %>
<li class="previous-page">
<a href="<%= previous_page['url'] %>" rel="previous" >
<span class="pagination-part-title"><%= previous_page['title'] %></span>
<span class="pagination-label"><%= previous_page['label'] %></span>
<a href="<%= previous_page[:url] %>" rel="previous" >
<span class="pagination-part-title"><%= previous_page[:title] %></span>
<span class="pagination-label"><%= previous_page[:label] %></span>
</a>
</li>
<% end %>
<% if local_assigns.include?(:next_page) %>
<% next_page = next_page.with_indifferent_access %>
<li class="next-page">
<a href="<%= next_page['url'] %>" rel="next">
<span class="pagination-part-title"><%= next_page['title'] %></span>
<span class="pagination-label"><%= next_page['label'] %></span>
<a href="<%= next_page[:url] %>" rel="next">
<span class="pagination-part-title"><%= next_page[:title] %></span>
<span class="pagination-label"><%= next_page[:label] %></span>
</a>
</li>
<% end %>
Expand Down

0 comments on commit 0593bf6

Please sign in to comment.