noa-resource 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +28 -0
- data/Rakefile +7 -0
- data/app/controllers/noa/resource/base_controller.rb +30 -0
- data/app/helpers/noa/resource/base_helper.rb +150 -0
- data/app/views/noa/resource/base/_actions.html.erb +0 -0
- data/app/views/noa/resource/base/_collection.html.erb +28 -0
- data/app/views/noa/resource/base/_form.html.erb +1 -0
- data/app/views/noa/resource/base/index.html.erb +9 -0
- data/app/views/noa/resource/base/new.html.erb +3 -0
- data/app/views/noa/resource/builders/_form_for.html.erb +11 -0
- data/lib/noa/resource.rb +9 -0
- data/lib/noa/resource/engine.rb +6 -0
- data/lib/noa/resource/version.rb +5 -0
- data/noa-resource.gemspec +27 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/posts_controller.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/post.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +27 -0
- data/spec/dummy/config/boot.rb +9 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +27 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/db/migrate/20130406105846_create_posts.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +27 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/posts.rb +6 -0
- data/spec/helpers/base_helper_spec.rb +69 -0
- data/spec/spec_helper.rb +25 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 490c703c34fc98e6985ffa6571881b110cf72f16
|
4
|
+
data.tar.gz: 944d5e069e7624faa8fc51da4eae1dfaa61a4927
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb9720353e77df5aa9737b7c26194743efac34d41c086955cca63d0fdff72b8875490adc189f49a6285ece871f5b408743cf228c9e999874ca509087fa0af564
|
7
|
+
data.tar.gz: 70931438204b8ddd1267736a6971c7b326d2a9fb7564f128fe82649e69641b2aaf2905e2324498be12f2a1c452e19ed5611c0b9c6f44c454d16da6f4ca5aa5e0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem "inherited_resources",
|
6
|
+
github: "jarijokinen/inherited_resources", branch: "rails4"
|
7
|
+
gem "responders",
|
8
|
+
github: "plataformatec/responders"
|
9
|
+
gem "rails", "4.0.0.beta1"
|
10
|
+
gem "spork-rails", github: "A-gen/spork-rails"
|
11
|
+
gem "database_cleaner", github: "bmabey/database_cleaner"
|
12
|
+
gem "jquery-rails"
|
13
|
+
gem "turbolinks"
|
14
|
+
gem "coffee-rails"
|
15
|
+
|
16
|
+
gem "noa-core", github: "jarijokinen/noa-core"
|
17
|
+
gem "noa-developer", github: "jarijokinen/noa-developer"
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jari Jokinen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Noa::Resource
|
2
|
+
|
3
|
+
Resource module for [Noa](https://github.com/jarijokinen/noa).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem "noa-resource"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install noa-resource
|
18
|
+
|
19
|
+
## Support
|
20
|
+
|
21
|
+
If you have any issues with Noa, or if you like to report a bug, please create
|
22
|
+
an [issue on GitHub](https://github.com/jarijokinen/noa/issues).
|
23
|
+
|
24
|
+
## License
|
25
|
+
|
26
|
+
MIT License. Copyright (c) 2013 Jari Jokinen. See
|
27
|
+
[LICENSE](https://github.com/jarijokinen/noa/blob/master/LICENSE.txt) for
|
28
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Noa
|
2
|
+
module Resource
|
3
|
+
class BaseController < Noa::Core::BaseController
|
4
|
+
inherit_resources
|
5
|
+
defaults route_prefix: ""
|
6
|
+
|
7
|
+
def create
|
8
|
+
create! { collection_url }
|
9
|
+
end
|
10
|
+
|
11
|
+
def update
|
12
|
+
update! { collection_url }
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def resource_params
|
18
|
+
params.require(resource_name).permit(*permit_attributes)
|
19
|
+
end
|
20
|
+
|
21
|
+
def resource_name
|
22
|
+
controller_name.tableize.singularize.to_sym
|
23
|
+
end
|
24
|
+
|
25
|
+
def permit_attributes
|
26
|
+
resource_class.attribute_names - %w(id created_at updated_at)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module Noa
|
2
|
+
module Resource
|
3
|
+
module BaseHelper
|
4
|
+
# Returns humanized and localized name for a current resource model
|
5
|
+
def resource_human_name
|
6
|
+
resource_class.model_name.human
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns humanized and localized name for a specified resource class
|
10
|
+
def resource_human_name_for(resource_class_name)
|
11
|
+
eval("#{resource_class_name.to_s.classify}.model_name.human")
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns an unique title for a resource
|
15
|
+
def resource_title
|
16
|
+
"#{resource_human_name} #{resource.id}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns a title for a collection
|
20
|
+
def collection_title
|
21
|
+
I18n.t("activemodel.models.#{controller_name.singularize}.other",
|
22
|
+
default: controller_name.humanize)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns all attributes for a resource
|
26
|
+
def resource_attributes
|
27
|
+
resource_class.attribute_names
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns attributes that should be invisible for end-users
|
31
|
+
def non_human_attributes
|
32
|
+
%w(id updated_at created_at)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns attributes for a resource without non-human attributes
|
36
|
+
def resource_human_attributes
|
37
|
+
human_attributes = resource_attributes - non_human_attributes
|
38
|
+
if respond_to?("parent?")
|
39
|
+
parent_attribute = "#{parent.class.name.underscore}_id"
|
40
|
+
human_attributes = human_attributes - ["#{parent_attribute}"]
|
41
|
+
end
|
42
|
+
human_attributes
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns humanized and localized attribute name
|
46
|
+
def attribute_human_name(attribute_name)
|
47
|
+
attribute_name = attribute_name.to_s
|
48
|
+
I18n.t("activerecord.attributes.#{controller_name.singularize}.#{attribute_name}",
|
49
|
+
default: attribute_name.humanize)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns truncated attribute value
|
53
|
+
def attribute_value(resource, attribute_name, truncation = 50)
|
54
|
+
value = resource.send(attribute_name).to_s.truncate(truncation)
|
55
|
+
if attribute_name.to_s.match(/_id$/)
|
56
|
+
model_name = attribute_name.gsub(/_id$/, "").classify
|
57
|
+
begin
|
58
|
+
value = eval(model_name).find(value).to_s
|
59
|
+
rescue ActiveRecord::RecordNotFound
|
60
|
+
value = ""
|
61
|
+
end
|
62
|
+
end
|
63
|
+
value
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns a text based on action and resource names
|
67
|
+
#
|
68
|
+
# Example:
|
69
|
+
#
|
70
|
+
# resource_action(:new)
|
71
|
+
# # => "New Product"
|
72
|
+
def resource_action(action_name)
|
73
|
+
I18n.t("noa.resource.resource_actions.#{action_name}",
|
74
|
+
resource_name: resource_human_name,
|
75
|
+
default: "#{action_name.to_s.titleize} #{resource_human_name}")
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns a link for a resource
|
79
|
+
#
|
80
|
+
# Examples:
|
81
|
+
#
|
82
|
+
# resource_link(:new)
|
83
|
+
# # => <a href="/products/new">New Product</a>
|
84
|
+
# resource_link(:edit)
|
85
|
+
# # => <a href="/products/1/edit">Edit Product</a>
|
86
|
+
# resource_link(:edit, row)
|
87
|
+
# # => <a href="/products/1/edit">Edit</a>
|
88
|
+
# resource_link(:edit, text: "Make changes")
|
89
|
+
# # => <a href="/products/1/edit">Make changes</a>
|
90
|
+
def resource_link(action_name)
|
91
|
+
text ||= resource_action(action_name)
|
92
|
+
|
93
|
+
eval("resource_link_for_#{action_name.to_s}(text)")
|
94
|
+
|
95
|
+
case action_name.to_sym
|
96
|
+
when :new
|
97
|
+
link_to(text, new_resource_path)
|
98
|
+
when :edit
|
99
|
+
link_to(text, edit_resource_path(resource))
|
100
|
+
when :delete
|
101
|
+
link_to
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Returns form path for a resource
|
106
|
+
def resource_form_path
|
107
|
+
resource.new_record? ? collection_path : resource_path
|
108
|
+
end
|
109
|
+
|
110
|
+
# Renders form using selected form builder
|
111
|
+
def render_form(form_builder = "form_for")
|
112
|
+
fields = resource_human_attributes
|
113
|
+
fields.map! do |arg|
|
114
|
+
arg.to_s.sub("_id", "").to_sym
|
115
|
+
end
|
116
|
+
render "noa/resource/builders/#{form_builder}", fields: fields
|
117
|
+
end
|
118
|
+
|
119
|
+
# Renders collection table
|
120
|
+
def render_collection_table(custom_attributes = nil)
|
121
|
+
render "collection",
|
122
|
+
collection: collection,
|
123
|
+
attributes: custom_attributes || resource_human_attributes
|
124
|
+
end
|
125
|
+
|
126
|
+
# Renders action links for a resource
|
127
|
+
def render_actions_for(resource)
|
128
|
+
render "actions", resource: resource
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def resource_link_for_index(text)
|
134
|
+
link_to(text, collection_path)
|
135
|
+
end
|
136
|
+
|
137
|
+
def resource_link_for_show(text)
|
138
|
+
link_to(text, resource_path(resource))
|
139
|
+
end
|
140
|
+
|
141
|
+
def resource_link_for_new(text)
|
142
|
+
link_to(text, new_resource_path)
|
143
|
+
end
|
144
|
+
|
145
|
+
def resource_link_for_edit(text)
|
146
|
+
link_to(text, edit_resource_path(resource))
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<% @title ||= collection_title %>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<% attributes.each do |attribute_name| %>
|
7
|
+
<th><%= attribute_human_name(attribute_name) %></th>
|
8
|
+
<% end %>
|
9
|
+
<th> </th>
|
10
|
+
</tr>
|
11
|
+
</thead>
|
12
|
+
<tbody>
|
13
|
+
<% collection.each do |resource| %>
|
14
|
+
<tr>
|
15
|
+
<% attributes.each do |attribute_name| %>
|
16
|
+
<td><%= attribute_value(resource, attribute_name) %></td>
|
17
|
+
<% end %>
|
18
|
+
<td class="actions"><%= render_actions_for(resource) %></td>
|
19
|
+
</tr>
|
20
|
+
<% end %>
|
21
|
+
</tbody>
|
22
|
+
</table>
|
23
|
+
|
24
|
+
<%=
|
25
|
+
if defined?(Kaminari)
|
26
|
+
paginate(collection)
|
27
|
+
end
|
28
|
+
%>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render_form %>
|
data/lib/noa/resource.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "noa/resource/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "noa-resource"
|
8
|
+
spec.version = Noa::Resource::VERSION
|
9
|
+
spec.authors = ["Jari Jokinen"]
|
10
|
+
spec.email = ["info@jarijokinen.com"]
|
11
|
+
spec.description = "Resource module for Noa"
|
12
|
+
spec.summary = "Resource module for Noa"
|
13
|
+
spec.homepage = "https://github.com/jarijokinen/noa-resource"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.platform = Gem::Platform::RUBY
|
17
|
+
spec.required_ruby_version = ">= 2.0.0"
|
18
|
+
|
19
|
+
spec.files = `git ls-files`.split($/)
|
20
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "noa-core"
|
24
|
+
spec.add_dependency "inherited_resources"
|
25
|
+
|
26
|
+
spec.add_development_dependency "noa-developer"
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED