govuk_admin_template 3.3.2 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bc5691dfe01fbf62bc24ae0c00dc024a8361657
4
- data.tar.gz: 79ab1dc23f2b3fd9412893eca477ca21129d39d3
3
+ metadata.gz: b753aff3e74434c378a51ccf64763abee3cb0926
4
+ data.tar.gz: f64165ce6992c9a5c2a693ca7e9e4b1701219d37
5
5
  SHA512:
6
- metadata.gz: 8643da55fd87cdc39078b5ba3f71e82536c46e2bb670e423c4c47b45c4f562415e24ff289a1f39e89dbee62047014fe5d469d063d58f6dda7e811bf1112c231e
7
- data.tar.gz: 4877eb686592fc3bb417c3735ebf4520d7920afe9970f4526168d908a2cf60a68963050281dd6cbb01e251e14367d95bb839999464505b399c94f15c8739cf91
6
+ metadata.gz: 0d364ccd057fb188e6d0f7237cfcdd255197d559f114fd56c492f662ed666885c77d47a1b6c51c632641438136082f15c60ba2129df3954ed47e22b529e1c129
7
+ data.tar.gz: f51cd8a59cad0869c31de60b8ad491ed32f13570021a820386bd35ddaba165ce06bfb6d4c07175c08863afee42205ab4b4312ff8d743d02a493ab63cc1654f78
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 3.4.0
2
+
3
+ * Add support for flash messages
4
+ * Add optional signout element to navigation bar
5
+
1
6
  # 3.3.2
2
7
 
3
8
  * Fix module starting when the module is defined on the container passed into `GOVUKAdmin.start` https://github.com/alphagov/govuk_admin_template/pull/98
data/README.md CHANGED
@@ -13,32 +13,37 @@ This gem provides (via a Rails engine):
13
13
  * Google Analytics tracking code (Universal Analytics), using the "GOV.UK apps" profile
14
14
 
15
15
  [Apps using this gem](https://github.com/search?q=govuk_admin_template+user%3Aalphagov+filename%3AGemfile) include:
16
- * [Transition](https://github.com/alphagov/transition)
16
+ * [Collections publisher](https://github.com/alphagov/collections-publisher)
17
+ * [Imminence](https://github.com/alphagov/imminence)
17
18
  * [Maslow](https://github.com/alphagov/maslow)
19
+ * [Panopticon](https://github.com/alphagov/panopticon)
18
20
  * [Publisher](https://github.com/alphagov/publisher)
21
+ * [Search admin](https://github.com/alphagov/search-admin)
19
22
  * [Sign on](https://github.com/alphagov/signonotron2)
20
- * [Panopticon](https://github.com/alphagov/panopticon)
21
- * [Imminence](https://github.com/alphagov/imminence)
23
+ * [Specialist publisher](https://github.com/alphagov/specialist-publisher)
22
24
  * [Support](https://github.com/alphagov/support)
25
+ * [Transition](https://github.com/alphagov/transition)
23
26
  * [Travel advice publisher](https://github.com/alphagov/travel-advice-publisher)
24
- * [Specialist publisher](https://github.com/alphagov/specialist-publisher)
25
- * [Search admin](https://github.com/alphagov/search-admin)
26
27
 
27
28
  ## Usage
28
29
 
29
- Firstly, include the gem in your Gemfile, pinned to the appropriate version and run ```bundle```:
30
+ Firstly, include the gem in your Gemfile, pinned to the appropriate version and run `bundle`:
31
+
30
32
  ```ruby
31
- gem 'govuk_admin_template', '1.0.0'
33
+ # Gemfile
34
+ gem 'govuk_admin_template', '~> 3.3'
32
35
  ```
33
36
 
34
37
  At the top of `application.scss` include the styles (this provides all the mixins and variables from the gem as well as from bootstrap — [bootstrap mixins](https://github.com/twbs/bootstrap-sass/blob/master/vendor/assets/stylesheets/bootstrap/_mixins.scss)):
35
38
  ```css
39
+ /* application.scss */
36
40
  @import 'govuk_admin_template';
37
41
  ```
38
42
 
39
43
  In `application.html.erb` after any content blocks you want to include, render the base template:
40
44
  ```erb
41
- <%= render :template => 'layouts/govuk_admin_template' %>
45
+ # views/layouts/application.html.rb
46
+ <%= render template: 'layouts/govuk_admin_template' %>
42
47
  ```
43
48
 
44
49
  The [base template](app/views/layouts/govuk_admin_template.html.erb) includes:
@@ -49,23 +54,42 @@ The [base template](app/views/layouts/govuk_admin_template.html.erb) includes:
49
54
  * header HTML
50
55
  * footer HTML
51
56
 
52
- You will also need to include your styles within the `<head>` of your HTML, do this using nested layouts:
57
+ You will also need to include your styles and javascripts:
58
+
53
59
  ```erb
60
+ # views/layouts/application.html.rb
54
61
  <% content_for :head do %>
55
- <%= stylesheet_link_tag "application", :media => "all" %>
62
+ <%= stylesheet_link_tag "application", media: "all" %>
63
+ <%= javascript_include_tag 'application' %>
56
64
  <% end %>
57
65
  ```
58
66
 
59
67
  It is recommended that the style guide is also made available within your app at the route `/style-guide`. Add this to your `config/routes.rb` file:
60
68
 
61
69
  ```ruby
62
- mount GovukAdminTemplate::Engine, at: "/style-guide"
70
+ # config/routes.rb
71
+ if Rails.env.development?
72
+ mount GovukAdminTemplate::Engine, at: "/style-guide"
73
+ end
63
74
  ```
64
75
 
65
76
  The gem source includes a [dummy app](spec/dummy) configured to behave like an app using the gem. If you have the gem checked out it can be run from the `spec\dummy` directory using `rails s`.
66
77
 
67
78
  For Javascript usage, available modules and writing modules, see the [Javascript guide](JAVASCRIPT.md).
68
79
 
80
+ ### Configuration
81
+
82
+ You can configure the gem with a config block in an initializer:
83
+
84
+ ```ruby
85
+ # config/initializers/govuk_admin_template.rb
86
+ GovukAdminTemplate.configure do |c|
87
+ c.app_title = "My Publisher"
88
+ c.show_flash = true
89
+ c.show_signout = true
90
+ end
91
+ ```
92
+
69
93
  ### Content blocks
70
94
 
71
95
  The gem [uses nested layouts](http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts) for customisation.
@@ -88,6 +112,7 @@ The gem [uses nested layouts](http://guides.rubyonrails.org/layouts_and_renderin
88
112
 
89
113
  Example navbar_items:
90
114
  ```erb
115
+ # views/layouts/application.html.rb
91
116
  <% content_for :navbar_items do %>
92
117
  <li>
93
118
  <a href="#">navbar_item</a>
@@ -130,6 +155,52 @@ GovukAdminTemplate.environment_style = [preview|production|development]
130
155
  GovukAdminTemplate.environment_label = [Preview|Staging|Production|Development]
131
156
  ```
132
157
 
158
+ ## Flash messages
159
+
160
+ Turn on flash messages in the config:
161
+
162
+ ```ruby
163
+ # config/initializers/govuk_admin_template.rb
164
+ GovukAdminTemplate.configure do |c|
165
+ c.show_flash = true
166
+ end
167
+ ```
168
+
169
+ Use like this:
170
+
171
+ ```ruby
172
+ # app/controllers/my_controller.rb
173
+ class MyController < ApplicationController
174
+ def create
175
+ if thing.save
176
+ flash[:success] = "Your thing has been created!"
177
+ else
178
+ flash[:danger] = "Sorry, it did not work."
179
+ end
180
+
181
+ redirect_to :back
182
+ end
183
+ end
184
+ ```
185
+
186
+ We support `:success`, `:info`, `:warning` and `:danger`:
187
+
188
+ ![Flash types](docs/flash-types.png)
189
+
190
+ In Rails 4, you can register your types to allow them to be used as arguments
191
+ to `redirect_to`.
192
+
193
+ ```ruby
194
+ # app/controllers/application_controller.rb
195
+ class ApplicationController < ActionController::Base
196
+ add_flash_types :success, :info, :warning, :danger
197
+ end
198
+
199
+ # Now this works:
200
+ redirect_to :back, success: "Well done!"
201
+ redirect_to :back, danger: "This didn't work."
202
+ ```
203
+
133
204
  ## Development
134
205
 
135
206
  Clone the repository and run `bundle`.
@@ -2,6 +2,7 @@
2
2
  environment_style = GovukAdminTemplate.environment_style
3
3
  environment_label = GovukAdminTemplate.environment_label
4
4
  app_home_path = content_for?(:app_home_path) ? yield(:app_home_path) : root_path
5
+ app_title = content_for?(:app_title) ? yield(:app_title) : GovukAdminTemplate::Config.app_title
5
6
  %>
6
7
  <!DOCTYPE html>
7
8
  <!--[if lte IE 7]><html class="no-js lte-ie7" lang="en"><![endif]-->
@@ -9,7 +10,7 @@
9
10
  <!--[if gt IE 8]><!--><html class="no-js" lang="en"><!--<![endif]-->
10
11
  <head>
11
12
  <meta charset="utf-8">
12
- <title><%= content_for?(:page_title) ? yield(:page_title) : "GOV.UK" %></title>
13
+ <title><%= content_for?(:page_title) ? yield(:page_title) : app_title %></title>
13
14
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
14
15
  <meta name="viewport" content="width=device-width, initial-scale=1">
15
16
  <script>(function(d){d.className=d.className.replace(/^no-js\b/,'js');}(document.documentElement));</script>
@@ -59,20 +60,28 @@
59
60
  <span class="icon-bar"></span>
60
61
  </a>
61
62
  <% end %>
62
- <%= link_to content_for?(:app_title) ? yield(:app_title) : "GOV.UK", app_home_path, :class => 'navbar-brand' %>
63
+ <%= link_to app_title, app_home_path, :class => 'navbar-brand' %>
63
64
  <% if environment_label %>
64
65
  <div class="environment-label">
65
66
  <%= environment_label %>
66
67
  </div>
67
68
  <% end %>
68
69
  </div>
69
- <% if content_for?(:navbar_right) || content_for?(:navbar_items) %>
70
+ <% if GovukAdminTemplate::Config.show_signout || content_for?(:navbar_right) || content_for?(:navbar_items) %>
70
71
  <nav role="navigation" class="collapse navbar-collapse">
71
72
  <% if content_for?(:navbar_items) %>
72
73
  <ul class="nav navbar-nav">
73
74
  <%= yield :navbar_items %>
74
75
  </ul>
75
76
  <% end %>
77
+
78
+ <% if GovukAdminTemplate::Config.show_signout %>
79
+ <div class="navbar-text pull-right">
80
+ <%= link_to current_user.name, Plek.current.find('signon') %>
81
+ &bull; <%= link_to 'Sign out', '/auth/gds/sign_out' %>
82
+ </div>
83
+ <% end %>
84
+
76
85
  <% if content_for?(:navbar_right) %>
77
86
  <div class="navbar-text pull-right">
78
87
  <%= yield :navbar_right %>
@@ -85,6 +94,10 @@
85
94
  <% end %>
86
95
  <section class="<%= content_for?(:full_width) ? 'container-fluid' : 'container' %>">
87
96
  <main role="main">
97
+ <% if GovukAdminTemplate::Config.show_flash %>
98
+ <%= display_flash_message %>
99
+ <% end %>
100
+
88
101
  <%= content_for?(:content) ? yield(:content) : yield %>
89
102
  </main>
90
103
  <footer class="page-footer">
@@ -0,0 +1,19 @@
1
+ module GovukAdminTemplate
2
+ def self.configure
3
+ yield(Config)
4
+ end
5
+
6
+ module Config
7
+ # Name of your application
8
+ mattr_accessor :app_title
9
+ @@app_title = "GOV.UK"
10
+
11
+ # Show flash-messages
12
+ # Default: false
13
+ mattr_accessor :show_flash
14
+
15
+ # Show username and signout link in the top right corner
16
+ # Default: false
17
+ mattr_accessor :show_signout
18
+ end
19
+ end
@@ -25,5 +25,9 @@ module GovukAdminTemplate
25
25
  # 1:15pm
26
26
  Time::DATE_FORMATS[:govuk_time] = '%-I:%M%P'
27
27
  end
28
+
29
+ initializer "govuk_admin_template.view_helpers" do
30
+ ActionView::Base.send :include, ViewHelpers
31
+ end
28
32
  end
29
33
  end
@@ -1,3 +1,3 @@
1
1
  module GovukAdminTemplate
2
- VERSION = "3.3.2"
2
+ VERSION = "3.4.0"
3
3
  end
@@ -0,0 +1,14 @@
1
+ module GovukAdminTemplate
2
+ module ViewHelpers
3
+ def display_flash_message
4
+ html = []
5
+
6
+ flash.each do |type, message|
7
+ next unless type.to_sym.in?(%i[success info warning danger])
8
+ html << content_tag(:div, message, class: "alert alert-#{type}")
9
+ end
10
+
11
+ html.join.html_safe
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,7 @@
1
1
  require "govuk_admin_template/version"
2
2
  require "govuk_admin_template/engine"
3
+ require "govuk_admin_template/config"
4
+ require "govuk_admin_template/view_helpers"
3
5
 
4
6
  module GovukAdminTemplate
5
7
  mattr_accessor :environment_style, :environment_label
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_admin_template
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.2
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-13 00:00:00.000000000 Z
11
+ date: 2015-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bootstrap-sass
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 3.3.3
33
+ version: 3.3.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 3.3.3
40
+ version: 3.3.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jquery-rails
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -174,8 +174,10 @@ files:
174
174
  - app/views/layouts/govuk_admin_template.html.erb
175
175
  - config/routes.rb
176
176
  - lib/govuk_admin_template.rb
177
+ - lib/govuk_admin_template/config.rb
177
178
  - lib/govuk_admin_template/engine.rb
178
179
  - lib/govuk_admin_template/version.rb
180
+ - lib/govuk_admin_template/view_helpers.rb
179
181
  homepage: https://github.com/alphagov/govuk_admin_template
180
182
  licenses: []
181
183
  metadata: {}