Skip to content

Commit

Permalink
improve layouts and scaffold templates
Browse files Browse the repository at this point in the history
  • Loading branch information
justalever committed Mar 24, 2018
1 parent 39ac3c1 commit 33b024f
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 73 deletions.
4 changes: 0 additions & 4 deletions app/controllers/home_controller.rb

This file was deleted.

50 changes: 0 additions & 50 deletions app/lib/templates/erb/scaffold/index.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<div class="field">
<div class="control">
<%= f.button :submit, "Sign up", class:"button is-warning is-medium" %>
<%= f.button :submit, "Sign up", class:"button is-medium" %>
</div>
</div>

Expand Down
45 changes: 29 additions & 16 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,29 @@
<p class="notice"><%= notice %></p>
</div>
<% end %>
<% if flash[:alert] %>
<div class="notification is-danger global-notification">
<p class="alert"><%= alert %></p>
</div>
<% end %>

<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<%= link_to root_path, class:"navbar-item" do %>
<h1 class="title is-5"><%= Rails.configuration.application_name %></h1>
<% end %>
<div class="navbar-burger burger" data-target="navbar">
<span></span>
<span></span>
<span></span>
<div class="navbar-burger burger" data-target="navbar">
<span></span>
<span></span>
<span></span>
</div>
</div>
</div>

<div id="navbar" class="navbar-menu">
<div class="navbar-end">
<div class="navbar-item">
<div class="field is-grouped">

<% if user_signed_in? %>

<div class="navbar-item has-dropdown is-hoverable">
Expand All @@ -48,23 +49,35 @@
</div>
</div>
<% else %>
<%= link_to "Sign In", new_user_session_path, class:"navbar-item button" %>
<%= link_to "Sign up", new_user_registration_path, class:"navbar-item button"%>
<p class="control">
<%= link_to "Sign In", new_user_session_path, class:"navbar-item button" %>
</p>
<p class="control">
<%= link_to "Sign up", new_user_registration_path, class:"navbar-item button"%>
</p>
<% end %>

</div>
</div>
</div>
</div>
</div>
</nav>

<div class="container">

<%= yield %>
<section class="section">
<div class="container">
<%= yield %>
</div>
</section>

</div>
<footer class="footer">
<div class="container">
<div class="content has-text-centered">
<p>
Visit <a href="https://web-crunch.com" target="_blank">Web-Crunch.com</a> for more builds like this one.
</p>
</div>
</div>
</footer>

</body>
</html>
</html>
49 changes: 49 additions & 0 deletions lib/templates/erb/scaffold/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<% name_attribute = attributes.find{ |a| a.name == "name" } %>
<% has_name = !!name_attribute %>

<div class="columns">
<div class="column is-6">
<h1><%= plural_table_name.capitalize %></h1>
</div>

<div class="column is-6 has-text-right">
<%%= link_to new_<%= singular_table_name %>_path, class: 'btn btn-primary' do %>
Add New <%= human_name %>
<%% end %>
</div>
</div>

<table class="table is-fullwidth is-striped">
<thead>
<tr>
<% if has_name %>
<th>Name</th>
<% end %>
<% attributes.without(name_attribute).each do |attribute| -%>
<th><%= attribute.human_name %></th>
<% end -%>
<% unless has_name %>
<th></th>
<% end %>
</tr>
</thead>

<tbody>
<%% @<%= plural_table_name%>.each do |<%= singular_table_name %>| %>
<%%= content_tag :tr, id: dom_id(<%= singular_table_name %>), class: dom_class(<%= singular_table_name %>) do %>
<% if has_name %>
<td><%%= link_to <%= singular_table_name %>.name, <%= singular_table_name %> %></td>
<% end %>
<% attributes.without(name_attribute).each do |attribute| -%>
<td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
<% end -%>
<% unless has_name %>
<td><%%= link_to 'Show', <%= singular_table_name %> %></td>
<% end %>
<%% end %>
<%% end %>
</tbody>
</table>
9 changes: 7 additions & 2 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ def add_users
generate :devise, "User", "name"
end

def add_home
generate :controller, "home", "index"
end

def remove_app_css
# Remove Application CSS
run "rm app/assets/stylesheets/application.css"
end

def copy_templates
directory "app", force: true
directory "lib", force: true
# directory "lib", force: true
end

def add_sidekiq
Expand All @@ -84,6 +88,7 @@ def add_foreman
after_bundle do
set_application_name
add_simple_form
add_home
add_users
remove_app_css
add_sidekiq
Expand All @@ -96,6 +101,6 @@ def add_foreman
rails_command "db:migrate"

git :init
git add "."
git add: "."
git commit: %Q{ -m "Initial commit" }
end

0 comments on commit 33b024f

Please sign in to comment.