Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.4
0.0.5
2 changes: 1 addition & 1 deletion draft_generators.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Gem::Specification.new do |s|
s.name = "draft_generators".freeze
s.version = "0.0.4"
s.version = "0.0.5"

s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
Expand Down
14 changes: 7 additions & 7 deletions lib/generators/draft/resource/resource_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def generate_model
end

def create_root_folder
empty_directory File.join("app/views", "#{plural_table_name}")
empty_directory File.join("app/views", "#{singular_table_name}_templates")
end

def generate_view_files
available_views.each do |view|
filename = view_filename_with_extensions(view)
template filename, File.join("app/views", "#{plural_table_name}", File.basename(options[:new_form_name].presence || filename))
template filename, File.join("app/views", "#{singular_table_name}_templates", File.basename(options[:new_form_name].presence || filename))
end
end

Expand Down Expand Up @@ -72,16 +72,16 @@ def golden_five_routes

# CREATE
post("/insert_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create" })

# READ
get("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index" })

get("/#{plural_table_name}/:path_id", { :controller => "#{plural_table_name}", :action => "show" })

# UPDATE

post("/modify_#{singular_table_name}/:path_id", { :controller => "#{plural_table_name}", :action => "update" })

# DELETE
get("/delete_#{singular_table_name}/:path_id", { :controller => "#{plural_table_name}", :action => "destroy" })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def index

@list_of_<%= plural_table_name.underscore %> = matching_<%= plural_table_name.underscore %>.order({ :created_at => :desc })

render({ :template => "<%= plural_table_name.underscore %>/index" })
render({ :template => "<%= singular_table_name.underscore %>_templates/index" })
end

def show
Expand All @@ -14,7 +14,7 @@ def show

@the_<%= singular_table_name.underscore %> = matching_<%= plural_table_name.underscore.downcase %>.at(0)

render({ :template => "<%= plural_table_name.underscore %>/show" })
render({ :template => "<%= singular_table_name.underscore %>_templates/show" })
end

def create
Expand Down Expand Up @@ -62,7 +62,7 @@ def update
<% unless skip_validation_alerts? -%>
if the_<%= singular_table_name.underscore %>.valid?
the_<%= singular_table_name.underscore %>.save
redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}", { :notice => "<%= singular_table_name.humanize %> updated successfully."} )
redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}", { :notice => "<%= singular_table_name.humanize %> updated successfully." } )
else
redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}", { :alert => the_<%= singular_table_name.underscore %>.errors.full_messages.to_sentence })
end
Expand All @@ -72,7 +72,7 @@ def update
<% unless skip_redirect? -%>
redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}")
<% else -%>
render({ :template => "<%= plural_table_name.underscore %>/show" })
render({ :template => "<%= singular_table_name.underscore %>_templates/show" })
<% end -%>
<% end -%>
end
Expand All @@ -84,7 +84,7 @@ def destroy
the_<%= singular_table_name.underscore %>.destroy

<% unless skip_validation_alerts? -%>
redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> deleted successfully."} )
redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> deleted successfully." } )
<% else -%>
<% unless skip_redirect? -%>
redirect_to("/<%= plural_table_name.underscore %>")
Expand Down
158 changes: 38 additions & 120 deletions lib/generators/draft/resource/templates/views/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,148 +1,66 @@
<div>
<div>
<h1>
List of all <%= plural_table_name.humanize.downcase %>
</h1>
</div>
</div>
<h1>
List of all <%= plural_table_name.humanize.downcase %>
</h1>

<hr>

<div>
<div>
<article>
<header>
<h2>
Add a new <%= singular_table_name.humanize.downcase %>
</h2>
</header>

<form action="/insert_<%= singular_table_name %>"<% unless skip_post? -%> method="post"<% end -%>>
<form action="/insert_<%= singular_table_name %>"<% unless skip_post? -%> method="post"<% end -%>>
<% attributes.each do |attribute| -%>
<% if attribute.field_type == :check_box -%>
<div>
<input type="checkbox" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>" value="1">
<div>
<input type="checkbox" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>" value="1">

<label for="<%= attribute.column_name %>_box"><%= attribute.column_name.humanize %></label>
</div>
<label for="<%= attribute.column_name %>_box"><%= attribute.column_name.humanize %></label>
</div>

<% else -%>
<div>
<label for="<%= attribute.column_name %>_box">
<%= attribute.column_name.humanize %>
</label>
<div>
<label for="<%= attribute.column_name %>_box">
<%= attribute.column_name.humanize %>
</label>

<% if attribute.field_type == :text_area -%>
<textarea id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>" rows="3"></textarea>
<textarea id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>" rows="3"></textarea>
<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%>
<input type="datetime-local" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>">
<input type="datetime-local" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>">
<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%>
<input type="date" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>">
<input type="date" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>">
<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :time -%>
<input type="time" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>">
<input type="time" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>">
<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :integer -%>
<input type="number" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>">
<input type="number" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>">
<% else -%>
<input type="text" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>">
<input type="text" id="<%= attribute.column_name %>_box" name="query_<%= attribute.column_name %>">
<% end -%>
</div>
</div>

<% end -%>
<% end -%>
<button>
Create <%= singular_table_name.humanize.downcase %>
</button>
</form>
</div>
</div>
<button type="submit">
Create <%= singular_table_name.humanize.downcase %>
</button>
</form>
</article>

<hr>
<% if with_sentinels? -%>
<!-- Ransack Code start -->

<!-- Ransack Code end -->

<!-- Location Map Code start -->

<!-- Location Map Code end -->

<hr>

<% end -%>
<div>
<div>
<table border="1">
<tr>
<th>
ID
</th>

<% attributes.each do |attribute| -%>
<th>
<%= attribute.human_name %>
</th>

<% end -%>
<th>
Created at
</th>

<th>
Updated at
</th>

<th>
</th>
</tr>

<%% @list_of_<%= plural_table_name %>.each do |<%= singular_table_name.indefinitize.gsub(" ", "_") %>| %>
<tr>
<% if with_sentinels? -%>
<!-- Display <%= singular_table_name.indefinitize.gsub(" ", "_") %>.id start -->
<% end -%>
<td>
<%%= <%= singular_table_name.indefinitize.gsub(" ", "_") %>.id %>
</td>
<% if with_sentinels? -%>
<!-- Display <%= singular_table_name.indefinitize.gsub(" ", "_") %>.id end -->
<% end -%>

<% attributes.each do |attribute| -%>
<% if with_sentinels? -%>
<!-- Display <%= singular_table_name.indefinitize.gsub(" ", "_") %>.<%= attribute.column_name %> start -->
<% end -%>
<td>
<%%= <%= singular_table_name.indefinitize.gsub(" ", "_") %>.<%= attribute.column_name %> %>
</td>
<% if with_sentinels? -%>
<!-- Display <%= singular_table_name.indefinitize.gsub(" ", "_") %>.<%= attribute.column_name %> end -->
<% end -%>

<% end -%>
<% if with_sentinels? -%>
<!-- Display <%= singular_table_name.indefinitize.gsub(" ", "_") %>.created_at start -->
<% end -%>
<td>
<%%= time_ago_in_words(<%= singular_table_name.indefinitize.gsub(" ", "_") %>.created_at) %> ago
</td>
<% if with_sentinels? -%>
<!-- Display <%= singular_table_name.indefinitize.gsub(" ", "_") %>.created_at end -->

<!-- Display <%= singular_table_name.indefinitize.gsub(" ", "_") %>.updated_at start -->
<% end -%>
<td>
<%%= time_ago_in_words(<%= singular_table_name.indefinitize.gsub(" ", "_") %>.updated_at) %> ago
</td>
<% if with_sentinels? -%>
<!-- Display <%= singular_table_name.indefinitize.gsub(" ", "_") %>.updated_at end -->
<% end -%>

<td>
<a href="/<%= plural_table_name %>/<%%= <%= singular_table_name.indefinitize.gsub(" ", "_") %>.id %>">
Show details
</a>
</td>
</tr>
<%% end %>
</table>
</div>
</div>
<article>
<ul>
<%% @list_of_<%= plural_table_name %>.each do |<%= singular_table_name.indefinitize.gsub(" ", "_") %>| %>
<li>
<a href="/<%= plural_table_name.underscore %>/<%%= <%= singular_table_name.indefinitize.gsub(" ", "_") %>.id %>">
<%= singular_table_name.humanize %> #<%%= <%= singular_table_name.indefinitize.gsub(" ", "_") %>.id %>
</a>
</li>
<%% end %>
</ul>
</article>

<hr>
Loading