Skip to content
This repository
Browse code

Install views for SimpleForm if the gem is installed

  • Loading branch information...
commit 1d5e9283ad4cacba44fc16473a83f412b55b1897 1 parent 2425541
Josh Steiner jsteiner authored
3  README.md
Source Rendered
@@ -224,6 +224,9 @@ There is a shortcut to copy all Clearance views into your app:
224 224
225 225 rails generate clearance:views
226 226
  227 +If [SimpleForm](https://github.com/plataformatec/simple_form) is installed, it
  228 +will install the appropriate views.
  229 +
227 230 Overriding the model
228 231 --------------------
229 232
5 lib/generators/clearance/templates/simple_form/clearance_mailer/change_password.html.erb
... ... @@ -0,0 +1,5 @@
  1 +<%= t('.opening') %>
  2 +
  3 +<%= edit_user_password_url(@user, :token => @user.confirmation_token.html_safe) %>
  4 +
  5 +<%= t('.closing') %>
24 lib/generators/clearance/templates/simple_form/layouts/application.html.erb
... ... @@ -0,0 +1,24 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <%= javascript_include_tag 'application' %>
  5 + <%= csrf_meta_tag %>
  6 +</head>
  7 +<body>
  8 + <div id='header'>
  9 + <% if signed_in? -%>
  10 + <%= link_to t('.sign_out'), sign_out_path, :method => :delete %>
  11 + <% else -%>
  12 + <%= link_to t('.sign_in'), sign_in_path %>
  13 + <% end -%>
  14 + </div>
  15 +
  16 + <div id='flash'>
  17 + <% flash.each do |key, value| -%>
  18 + <div id='flash_<%= key %>'><%=h value %></div>
  19 + <% end %>
  20 + </div>
  21 +
  22 + <%= yield %>
  23 +</body>
  24 +</html>
3  lib/generators/clearance/templates/simple_form/passwords/create.html.erb
... ... @@ -0,0 +1,3 @@
  1 +<div id="clearance" class="password-reset">
  2 + <p><%= t '.description' %></p>
  3 +</div>
17 lib/generators/clearance/templates/simple_form/passwords/edit.html.erb
... ... @@ -0,0 +1,17 @@
  1 +<div id='clearance' class='password-reset'>
  2 + <h2><%= t '.title' %></h2>
  3 +
  4 + <p><%= t '.description' %></p>
  5 +
  6 + <%= simple_form_for :password_reset,
  7 + :url => user_password_path(@user, :token => @user.confirmation_token),
  8 + :html => { :method => :put } do |form| %>
  9 + <div class='password-field'>
  10 + <%= form.input :password %>
  11 + </div>
  12 +
  13 + <div class='submit-field'>
  14 + <%= form.button :submit %>
  15 + </div>
  16 + <% end %>
  17 +</div>
15 lib/generators/clearance/templates/simple_form/passwords/new.html.erb
... ... @@ -0,0 +1,15 @@
  1 +<div id='clearance' class='password-reset'>
  2 + <h2><%= t '.title' %></h2>
  3 +
  4 + <p><%= t '.description' %></p>
  5 +
  6 + <%= simple_form_for :password, :url => passwords_path do |form| %>
  7 + <div class='text-field'>
  8 + <%= form.input :email %>
  9 + </div>
  10 +
  11 + <div class='submit-field'>
  12 + <%= form.button :submit %>
  13 + </div>
  14 + <% end %>
  15 +</div>
18 lib/generators/clearance/templates/simple_form/sessions/_form.html.erb
... ... @@ -0,0 +1,18 @@
  1 +<%= simple_form_for :session, :url => session_path do |form| %>
  2 + <div class='text-field'>
  3 + <%= form.input :email %>
  4 + </div>
  5 +
  6 + <div class='password-field'>
  7 + <%= form.input :password %>
  8 + </div>
  9 +
  10 + <div class='submit-field'>
  11 + <%= form.button :submit %>
  12 + </div>
  13 +
  14 + <div class='other-links'>
  15 + <%= link_to t('.sign_up'), sign_up_path %>
  16 + <%= link_to t('.forgot_password'), new_password_path %>
  17 + </div>
  18 +<% end %>
6 lib/generators/clearance/templates/simple_form/sessions/new.html.erb
... ... @@ -0,0 +1,6 @@
  1 +<div id='clearance' class='sign-in'>
  2 + <h2><%= t '.title' %></h2>
  3 +
  4 + <%= render :partial => '/sessions/form' %>
  5 +
  6 +</div>
7 lib/generators/clearance/templates/simple_form/users/_form.html.erb
... ... @@ -0,0 +1,7 @@
  1 +<div class='text-field'>
  2 + <%= form.input :email %>
  3 +</div>
  4 +
  5 +<div class='password-field'>
  6 + <%= form.input :password %>
  7 +</div>
15 lib/generators/clearance/templates/simple_form/users/new.html.erb
... ... @@ -0,0 +1,15 @@
  1 +<div id='clearance' class='sign-up'>
  2 + <h2>Sign up</h2>
  3 +
  4 + <%= simple_form_for @user do |form| %>
  5 + <%= render :partial => '/users/form', :object => form %>
  6 +
  7 + <div class='submit-field'>
  8 + <%= form.button :submit %>
  9 + </div>
  10 +
  11 + <div class='other-links'>
  12 + <%= link_to t('.sign_in'), sign_in_path %>
  13 + </div>
  14 + <% end %>
  15 +</div>
2  lib/generators/clearance/views/USAGE
@@ -2,6 +2,8 @@ Description:
2 2 Override the default clearance views. This generator will copy all off the
3 3 base clearance views into your project.
4 4
  5 + If SimpleForm is installed it will install the appropriate views.
  6 +
5 7 Examples:
6 8 rails generate clearance:views
7 9
24 lib/generators/clearance/views/views_generator.rb
@@ -6,33 +6,29 @@ class ViewsGenerator < Rails::Generators::Base
6 6 source_root Clearance.root
7 7
8 8 def create_views
9   - views.each do |view|
10   - copy_file view
11   - end
  9 + directory views, 'app/views/'
12 10 end
13 11
14 12 def create_locales
15   - locales.each do |locale|
16   - copy_file locale
17   - end
  13 + directory locales, 'config/locales/'
18 14 end
19 15
20 16 private
21 17
22 18 def views
23   - files_within_root('.', 'app/views/**/*.*')
  19 + if defined?(SimpleForm)
  20 + directory_within_root 'lib/generators/clearance/templates/simple_form'
  21 + else
  22 + directory_within_root 'app/views'
  23 + end
24 24 end
25 25
26 26 def locales
27   - files_within_root('.', 'config/locales/**/*.*')
  27 + directory_within_root 'config/locales'
28 28 end
29 29
30   - def files_within_root(prefix, glob)
31   - root = "#{self.class.source_root}/#{prefix}"
32   -
33   - Dir["#{root}/#{glob}"].sort.map do |full_path|
34   - full_path.sub(root, '.').gsub('/./', '/')
35   - end
  30 + def directory_within_root(directory)
  31 + "#{self.class.source_root}/#{directory}"
36 32 end
37 33 end
38 34 end

0 comments on commit 1d5e928

Please sign in to comment.
Something went wrong with that request. Please try again.