power_resource 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +77 -10
- data/app/controllers/power_resource/base_controller.rb +19 -7
- data/app/helpers/power_resource/action_helper.rb +147 -0
- data/app/helpers/power_resource/base_helper.rb +51 -103
- data/app/helpers/power_resource/collection_helper.rb +20 -0
- data/app/helpers/power_resource/configuration_helper.rb +11 -0
- data/app/helpers/power_resource/rendering_helper.rb +26 -0
- data/app/views/power_resource/base/_actions.html.erb +3 -1
- data/app/views/power_resource/base/_collection.html.erb +5 -11
- data/app/views/power_resource/base/edit.html.erb +1 -1
- data/app/views/power_resource/base/index.html.erb +1 -1
- data/app/views/power_resource/base/new.html.erb +1 -1
- data/app/views/power_resource/builders/_form_for.html.erb +12 -3
- data/lib/power_resource.rb +1 -0
- data/lib/power_resource/configuration.rb +19 -0
- data/lib/power_resource/version.rb +1 -1
- data/power_resource.gemspec +9 -7
- data/spec/dummy/app/assets/javascripts/application.js +2 -0
- data/spec/dummy/app/assets/javascripts/categories.js +2 -0
- data/spec/dummy/app/assets/javascripts/comments.js +2 -0
- data/spec/dummy/app/assets/stylesheets/categories.css +4 -0
- data/spec/dummy/app/assets/stylesheets/comments.css +4 -0
- data/spec/dummy/app/controllers/backend/categories_controller.rb +7 -0
- data/spec/dummy/app/controllers/backend/comments_controller.rb +9 -0
- data/spec/dummy/app/controllers/backend/posts_controller.rb +7 -0
- data/spec/dummy/app/controllers/categories_controller.rb +5 -0
- data/spec/dummy/app/controllers/comments_controller.rb +7 -0
- data/spec/dummy/app/controllers/posts_controller.rb +3 -0
- data/spec/dummy/app/helpers/categories_helper.rb +2 -0
- data/spec/dummy/app/helpers/comments_helper.rb +2 -0
- data/spec/dummy/app/models/category.rb +5 -0
- data/spec/dummy/app/models/comment.rb +3 -0
- data/spec/dummy/app/models/post.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +23 -11
- data/spec/dummy/config/initializers/secret_token.rb +1 -1
- data/spec/dummy/config/locales/en.yml +11 -22
- data/spec/dummy/config/locales/fi.yml +38 -0
- data/spec/dummy/config/routes.rb +13 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/{20130722165046_create_posts.rb → 20130915095616_create_posts.rb} +1 -0
- data/spec/dummy/db/migrate/20130916174608_create_categories.rb +9 -0
- data/spec/dummy/db/migrate/20130916180755_create_comments.rb +11 -0
- data/spec/dummy/db/schema.rb +18 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +17445 -674
- data/spec/dummy/log/test.log +20826 -2
- data/spec/features/posts_spec.rb +8 -0
- data/spec/helpers/action_helper_spec.rb +111 -0
- data/spec/helpers/base_helper_spec.rb +111 -1
- data/spec/helpers/collection_helper_spec.rb +53 -0
- data/spec/helpers/rendering_helper_spec.rb +162 -0
- data/spec/spec_helper.rb +11 -0
- metadata +92 -26
- data/app/views/power_resource/builders/_formtastic.html.erb +0 -4
- data/spec/dummy/spec/controllers/posts_controller_spec.rb +0 -5
- data/spec/dummy/spec/helpers/posts_helper_spec.rb +0 -15
- data/spec/dummy/spec/models/post_spec.rb +0 -5
@@ -0,0 +1,20 @@
|
|
1
|
+
module PowerResource
|
2
|
+
module CollectionHelper
|
3
|
+
# Returns a name for a current collection
|
4
|
+
def collection_name
|
5
|
+
resource_name.tableize
|
6
|
+
end
|
7
|
+
|
8
|
+
# Returns humanized and localized name for a current collection
|
9
|
+
def collection_human_name
|
10
|
+
I18n.t("activerecord.models.#{resource_name}.other",
|
11
|
+
default: collection_name.humanize)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns a title for a current collection
|
15
|
+
def collection_title(options = {})
|
16
|
+
I18n.t("power_resource.titles.#{resource_name}.collection",
|
17
|
+
{ default: "#{collection_human_name}" }.merge(options) )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module PowerResource
|
2
|
+
module ConfigurationHelper
|
3
|
+
def collection_table_classes
|
4
|
+
PowerResource::Configuration.collection_table_classes.join(' ')
|
5
|
+
end
|
6
|
+
|
7
|
+
def collection_table_button_classes
|
8
|
+
PowerResource::Configuration.collection_table_button_classes.join(' ')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PowerResource
|
2
|
+
module RenderingHelper
|
3
|
+
# Renders collection table
|
4
|
+
def render_collection_table(custom_attributes = nil)
|
5
|
+
render 'collection',
|
6
|
+
collection: collection,
|
7
|
+
attributes: custom_attributes || resource_human_attributes,
|
8
|
+
collection_table_classes: collection_table_classes,
|
9
|
+
collection_table_button_classes: collection_table_button_classes
|
10
|
+
end
|
11
|
+
|
12
|
+
# Renders form using selected form builder
|
13
|
+
def render_form(form_builder = 'form_for')
|
14
|
+
fields = resource_human_attributes
|
15
|
+
fields.map! do |arg|
|
16
|
+
arg.to_s.sub('_id', '').to_sym
|
17
|
+
end
|
18
|
+
render "power_resource/builders/#{form_builder}", fields: fields
|
19
|
+
end
|
20
|
+
|
21
|
+
# Renders actions for a specific resource
|
22
|
+
def render_actions_for(resource)
|
23
|
+
render 'actions', resource: resource
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,28 +1,22 @@
|
|
1
1
|
<% @title ||= collection_title %>
|
2
2
|
|
3
|
-
<table>
|
3
|
+
<table class="<%= collection_table_classes %>">
|
4
4
|
<thead>
|
5
5
|
<tr>
|
6
6
|
<% attributes.each do |attribute_name| %>
|
7
|
-
<th><%=
|
7
|
+
<th><%= resource_attribute_human_name_for(attribute_name) %></th>
|
8
8
|
<% end %>
|
9
9
|
<th> </th>
|
10
10
|
</tr>
|
11
11
|
</thead>
|
12
12
|
<tbody>
|
13
|
-
<% collection.each do |
|
13
|
+
<% collection.each do |row| %>
|
14
14
|
<tr>
|
15
15
|
<% attributes.each do |attribute_name| %>
|
16
|
-
<td><%=
|
16
|
+
<td><%= attribute_value_for(row, attribute_name) %></td>
|
17
17
|
<% end %>
|
18
|
-
<td
|
18
|
+
<td><%= render_actions_for(row) %></td>
|
19
19
|
</tr>
|
20
20
|
<% end %>
|
21
21
|
</tbody>
|
22
22
|
</table>
|
23
|
-
|
24
|
-
<%=
|
25
|
-
if defined?(Kaminari)
|
26
|
-
paginate(collection)
|
27
|
-
end
|
28
|
-
%>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<% if resource.errors.any? %>
|
2
2
|
<div id="error_explanation">
|
3
|
-
<%= pluralize(resource.errors.count,
|
3
|
+
<%= pluralize(resource.errors.count, 'error') %>
|
4
4
|
prohibited this resource from being saved:
|
5
5
|
<ul>
|
6
6
|
<% resource.errors.full_messages.each do |msg| %>
|
@@ -12,10 +12,19 @@
|
|
12
12
|
|
13
13
|
<%= form_for(resource, url: resource_form_path) do |f| %>
|
14
14
|
<ul>
|
15
|
-
<%
|
15
|
+
<% resource_human_attributes.each do |field| %>
|
16
16
|
<li>
|
17
17
|
<%= f.label(field) %>
|
18
|
-
<%=
|
18
|
+
<%=
|
19
|
+
if resource_class.columns_hash["#{field}"].type == :text
|
20
|
+
f.text_area(field)
|
21
|
+
elsif field.match(/_id$/)
|
22
|
+
parent_class = field.sub(/_id$/, '').classify
|
23
|
+
f.select(field, eval(parent_class).all.map { |p| [p.name, p.id] })
|
24
|
+
else
|
25
|
+
f.text_field(field)
|
26
|
+
end
|
27
|
+
%>
|
19
28
|
</li>
|
20
29
|
<% end %>
|
21
30
|
</ul>
|
data/lib/power_resource.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module PowerResource
|
2
|
+
module Configuration
|
3
|
+
# Classes for collection tables
|
4
|
+
#
|
5
|
+
# Default values
|
6
|
+
#
|
7
|
+
# collection_table_classes = %w(table)
|
8
|
+
mattr_accessor :collection_table_classes
|
9
|
+
self.collection_table_classes = %w(table)
|
10
|
+
|
11
|
+
# Classes for collection table buttons (edit, delete, etc.)
|
12
|
+
#
|
13
|
+
# Default values
|
14
|
+
#
|
15
|
+
# collection_table_button_classes = %w(btn btn-default btn-xs)
|
16
|
+
mattr_accessor :collection_table_button_classes
|
17
|
+
self.collection_table_button_classes = %w(btn btn-default btn-xs)
|
18
|
+
end
|
19
|
+
end
|
data/power_resource.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = PowerResource::VERSION
|
9
9
|
spec.authors = ['Jari Jokinen']
|
10
10
|
spec.email = ['info@jarijokinen.com']
|
11
|
-
spec.description = 'Power up
|
12
|
-
spec.summary = 'Power up
|
11
|
+
spec.description = 'Power up RESTful resources!'
|
12
|
+
spec.summary = 'Power up RESTful resources!'
|
13
13
|
spec.homepage = 'https://github.com/jarijokinen/power_resource'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -21,11 +21,13 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.required_ruby_version = '>= 2.0.0'
|
22
22
|
|
23
23
|
spec.add_dependency 'rails', '~> 4.0.0'
|
24
|
-
spec.add_dependency '
|
24
|
+
spec.add_dependency 'activerecord', '~> 4.0.0'
|
25
|
+
spec.add_dependency 'inherited_resources', '~> 1.4.1'
|
25
26
|
|
26
27
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
27
|
-
spec.add_development_dependency 'capybara', '2.1.0'
|
28
|
-
spec.add_development_dependency '
|
29
|
-
spec.add_development_dependency '
|
30
|
-
spec.add_development_dependency '
|
28
|
+
spec.add_development_dependency 'capybara', '~> 2.1.0'
|
29
|
+
spec.add_development_dependency 'database_cleaner', '~> 1.0.1'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.1.0'
|
31
|
+
spec.add_development_dependency 'rspec-rails', '~> 2.14.0'
|
32
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3.8'
|
31
33
|
end
|
@@ -1,14 +1,26 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
<head>
|
4
|
+
<title><%= "#{@title} | " unless @title.blank? %>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<nav>
|
11
|
+
<ul>
|
12
|
+
<li><%= link_to('Posts', posts_path) %></li>
|
13
|
+
<li><%= link_to('Categories', categories_path) %></li>
|
14
|
+
</ul>
|
15
|
+
Backend:
|
16
|
+
<ul>
|
17
|
+
<li><%= link_to('Posts', backend_posts_path) %></li>
|
18
|
+
<li><%= link_to('Categories', backend_categories_path) %></li>
|
19
|
+
</ul>
|
20
|
+
</nav>
|
21
|
+
<section>
|
22
|
+
<%= content_tag(:h1, @title) unless @title.blank? %>
|
23
|
+
<%= yield %>
|
24
|
+
</section>
|
25
|
+
</body>
|
14
26
|
</html>
|
@@ -9,4 +9,4 @@
|
|
9
9
|
|
10
10
|
# Make sure your secret_key_base is kept private
|
11
11
|
# if you're sharing your code publicly.
|
12
|
-
Dummy::Application.config.secret_key_base = '
|
12
|
+
Dummy::Application.config.secret_key_base = 'f2a0cd4e95e90681626669aa7832968a9c6c298583fb0264c115015f34fcc7fac21546015d5bd1d0cbbe9b17ece4fbfdcc3de617d169b0333ab9d667ba67302c'
|
@@ -1,23 +1,12 @@
|
|
1
|
-
# Files in the config/locales directory are used for internationalization
|
2
|
-
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
-
# than English, add the necessary files in this directory.
|
4
|
-
#
|
5
|
-
# To use the locales, use `I18n.t`:
|
6
|
-
#
|
7
|
-
# I18n.t 'hello'
|
8
|
-
#
|
9
|
-
# In views, this is aliased to just `t`:
|
10
|
-
#
|
11
|
-
# <%= t('hello') %>
|
12
|
-
#
|
13
|
-
# To use a different locale, set it with `I18n.locale`:
|
14
|
-
#
|
15
|
-
# I18n.locale = :es
|
16
|
-
#
|
17
|
-
# This would use the information in config/locales/es.yml.
|
18
|
-
#
|
19
|
-
# To learn more, please read the Rails Internationalization guide
|
20
|
-
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
-
|
22
1
|
en:
|
23
|
-
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
category:
|
5
|
+
one: 'Category'
|
6
|
+
other: 'Categories'
|
7
|
+
comment:
|
8
|
+
one: 'Comment'
|
9
|
+
other: 'Comments'
|
10
|
+
post:
|
11
|
+
one: 'Post'
|
12
|
+
other: 'Posts'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
fi:
|
2
|
+
activerecord:
|
3
|
+
attributes:
|
4
|
+
post:
|
5
|
+
category_id: 'Kategoria'
|
6
|
+
title: 'Otsikko'
|
7
|
+
content: 'Sisältö'
|
8
|
+
models:
|
9
|
+
category:
|
10
|
+
one: 'Kategoria'
|
11
|
+
other: 'Kategoriat'
|
12
|
+
comment:
|
13
|
+
one: 'Kommentti'
|
14
|
+
other: 'Kommentit'
|
15
|
+
post:
|
16
|
+
one: 'Artikkeli'
|
17
|
+
other: 'Artikkelit'
|
18
|
+
power_resource:
|
19
|
+
actions:
|
20
|
+
new: 'Uusi'
|
21
|
+
edit: 'Muokkaa'
|
22
|
+
delete: 'Poista'
|
23
|
+
duplicate: 'Kopioi'
|
24
|
+
resource_actions:
|
25
|
+
new: 'Uusi %{downcased_resource_name}'
|
26
|
+
edit: 'Muokkaa %{resource_name}'
|
27
|
+
delete: 'Poista %{resource_name}'
|
28
|
+
duplicate: 'Kopioi %{resource_name}'
|
29
|
+
links:
|
30
|
+
post:
|
31
|
+
edit: 'Muokkaa'
|
32
|
+
titles:
|
33
|
+
post:
|
34
|
+
resource: 'Artikkeli nro %{resource_id}'
|
35
|
+
collection: 'Lista artikkeleista'
|
36
|
+
edit: 'Muokkaa artikkelia'
|
37
|
+
confirmations:
|
38
|
+
delete: 'Oletko varma?'
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,3 +1,15 @@
|
|
1
1
|
Dummy::Application.routes.draw do
|
2
|
-
|
2
|
+
namespace :backend, path: 'admin' do
|
3
|
+
resources :posts do
|
4
|
+
resources :comments
|
5
|
+
end
|
6
|
+
resources :categories
|
7
|
+
root to: 'posts#index'
|
8
|
+
end
|
9
|
+
|
10
|
+
resources :categories
|
11
|
+
resources :posts do
|
12
|
+
resources :comments
|
13
|
+
end
|
14
|
+
root to: 'posts#index'
|
3
15
|
end
|