acts_as_indexable 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +38 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +197 -0
- data/Guardfile +42 -0
- data/LICENSE +22 -0
- data/README.md +95 -0
- data/Rakefile +23 -0
- data/acts_as_indexable.gemspec +31 -0
- data/app/helpers/acts_as_indexable/acts_as_indexable_helper.rb +12 -0
- data/app/views/acts_as_indexable/_index.html.erb +9 -0
- data/app/views/acts_as_indexable/_row.html.erb +15 -0
- data/app/views/acts_as_indexable/_thead.html.erb +7 -0
- data/lib/acts_as_indexable.rb +7 -0
- data/lib/acts_as_indexable/attribute.rb +59 -0
- data/lib/acts_as_indexable/engine.rb +4 -0
- data/lib/acts_as_indexable/version.rb +3 -0
- data/lib/acts_as_indexable/view.rb +26 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/widgets.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/widgets.css +4 -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/widgets_controller.rb +18 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/widgets_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/widget.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +17 -0
- data/spec/dummy/app/views/widgets/_date.html.erb +1 -0
- data/spec/dummy/app/views/widgets/index.html.erb +4 -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/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +32 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -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 +4 -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 +25 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/migrate/20151123200106_create_widgets.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/seeds.rb +6 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/widget.rb +8 -0
- data/spec/features/acts_as_indexable/view_spec.rb +90 -0
- data/spec/helpers/acts_as_indexable_helper_spec.rb +16 -0
- data/spec/models/attribute_spec.rb +39 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/database_cleaner.rb +13 -0
- data/spec/support/indexable_views.rb +3 -0
- metadata +402 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "acts_as_indexable/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "acts_as_indexable"
|
6
|
+
s.version = ActsAsIndexable::VERSION
|
7
|
+
s.authors = ["Taylor C. MacDonald"]
|
8
|
+
s.email = ["tcmacdonald@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/tcmacdonald/acts_as_indexable"
|
10
|
+
s.summary = "Utilities for building and extending table views in your Rails application."
|
11
|
+
s.description = "ActsAsIndexable is a Rails engine that provides a configurable DSL for rendering tables in index views of your application. It works with any collection of enumerable objects, ActiveRecord or otherwise."
|
12
|
+
s.license = "MIT"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.require_paths = ['lib','app']
|
17
|
+
|
18
|
+
s.add_runtime_dependency 'rails', '~> 4.2', '>= 4.2.3'
|
19
|
+
|
20
|
+
s.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.11'
|
21
|
+
s.add_development_dependency 'rspec-rails', '~> 3.4', '>= 3.4.0'
|
22
|
+
s.add_development_dependency 'shoulda-matchers', '~> 3.0', '>= 3.0.1'
|
23
|
+
s.add_development_dependency 'database_cleaner', '~> 1.4', '>= 1.5.1'
|
24
|
+
s.add_development_dependency 'guard-rspec', '~> 4.6', '>= 4.6.4'
|
25
|
+
s.add_development_dependency 'launchy', '~> 2.4', '>= 2.4.3'
|
26
|
+
s.add_development_dependency 'capybara', '~> 2.5', '>= 2.5.0'
|
27
|
+
s.add_development_dependency 'capybara-webkit', '~> 1.7', '>= 1.7.1'
|
28
|
+
s.add_development_dependency 'factory_girl_rails', '~> 4.5', '>= 4.5.0'
|
29
|
+
s.add_development_dependency 'pry', '~> 0.10', '>= 0.10.3'
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%= content_tag :table, local_assigns.try(:[], :opts) do %>
|
2
|
+
<%= render 'acts_as_indexable/thead' %>
|
3
|
+
<% if local_assigns[:collection].present? %>
|
4
|
+
<tbody>
|
5
|
+
<%= render partial: 'acts_as_indexable/row', collection: local_assigns[:collection] %>
|
6
|
+
</tbody>
|
7
|
+
<% end %>
|
8
|
+
<% end %>
|
9
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<tr id="<%= dom_id(row) %>">
|
2
|
+
<% decorated_attrs.each do |attr| %>
|
3
|
+
<%= content_tag :td, class: attr.try(:klass) do %>
|
4
|
+
<% if attr.partial.present? %>
|
5
|
+
<%= render partial: attr.partial, object: row %>
|
6
|
+
<% else %>
|
7
|
+
<% if attr.key == :actions %>
|
8
|
+
<%= attr.link_to_actions(row) %>
|
9
|
+
<% else %>
|
10
|
+
<%= link_to_if attr.path.present?, attr.l(row), attr.href(row) %>
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
13
|
+
<% end %>
|
14
|
+
<% end %>
|
15
|
+
</tr>
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ActsAsIndexable
|
2
|
+
class Attribute
|
3
|
+
include ActionView::Helpers::UrlHelper
|
4
|
+
|
5
|
+
attr_accessor :key,
|
6
|
+
:label,
|
7
|
+
:attrs,
|
8
|
+
:format,
|
9
|
+
:partial,
|
10
|
+
:path
|
11
|
+
|
12
|
+
def initialize(key, attrs={})
|
13
|
+
@key = key
|
14
|
+
@attrs = attrs
|
15
|
+
@label = @attrs.try(:[], :label) || @key.to_s.humanize
|
16
|
+
@path = @attrs.try(:[], :link_to)
|
17
|
+
@format = @attrs.try(:[], :format)
|
18
|
+
@partial = @attrs.try(:[], :partial)
|
19
|
+
end
|
20
|
+
|
21
|
+
def l(ctx)
|
22
|
+
if @format.present?
|
23
|
+
I18n.l ctx.send(@key), format: @format
|
24
|
+
else
|
25
|
+
ctx.send(@key)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def href(ctx, href=nil)
|
30
|
+
path = href || @path
|
31
|
+
if path.present?
|
32
|
+
if path.to_s == 'self'
|
33
|
+
ctx
|
34
|
+
else
|
35
|
+
path.scan(/:[a-z_]*/).each do |attr|
|
36
|
+
path = path.gsub(/#{attr}/, ctx.send(attr[1..-1].to_sym).to_s)
|
37
|
+
end
|
38
|
+
path
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def link_to_actions(ctx)
|
44
|
+
@attrs.to_h.collect do |k,v|
|
45
|
+
label = v.try(:[], :label) || k.to_s.humanize
|
46
|
+
opts = {}
|
47
|
+
if k == :delete
|
48
|
+
opts[:data] = { method: :delete, confirm: 'Are you sure?' }
|
49
|
+
path = v.try(:[], :link_to) || "/#{ctx.class.name.underscore.pluralize}/:id"
|
50
|
+
else
|
51
|
+
path = v.try(:[], :link_to) || "/#{ctx.class.name.underscore.pluralize}/:id/#{k}"
|
52
|
+
end
|
53
|
+
|
54
|
+
link_to label, href(ctx, path), opts.merge(v.except(:link_to, :label))
|
55
|
+
end.join().html_safe
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActsAsIndexable
|
2
|
+
module View
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
helper_method :decorated_attrs
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def current_attrs
|
12
|
+
@current_attrs ||= {
|
13
|
+
id: {},
|
14
|
+
to_s: {},
|
15
|
+
created_at: {},
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def decorated_attrs
|
20
|
+
@decorated_attrs ||= current_attrs.collect do |k,v|
|
21
|
+
Attribute.new k, OpenStruct.new(v)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
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
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
|
6
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
7
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
8
|
+
<%= csrf_meta_tags %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<div class="container">
|
13
|
+
<%= yield %>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= date.created_at.strftime('%B %Y') %>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
Dir.chdir APP_ROOT do
|
8
|
+
# This script is a starting point to setup your application.
|
9
|
+
# Add necessary setup steps to this file:
|
10
|
+
|
11
|
+
puts "== Installing dependencies =="
|
12
|
+
system "gem install bundler --conservative"
|
13
|
+
system "bundle check || bundle install"
|
14
|
+
|
15
|
+
# puts "\n== Copying sample files =="
|
16
|
+
# unless File.exist?("config/database.yml")
|
17
|
+
# system "cp config/database.yml.sample config/database.yml"
|
18
|
+
# end
|
19
|
+
|
20
|
+
puts "\n== Preparing database =="
|
21
|
+
system "bin/rake db:setup"
|
22
|
+
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
24
|
+
system "rm -f log/*"
|
25
|
+
system "rm -rf tmp/cache"
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system "touch tmp/restart.txt"
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "action_view/railtie"
|
8
|
+
require "sprockets/railtie"
|
9
|
+
# require "rails/test_unit/railtie"
|
10
|
+
|
11
|
+
Bundler.require(*Rails.groups)
|
12
|
+
require "acts_as_indexable"
|
13
|
+
|
14
|
+
module Dummy
|
15
|
+
class Application < Rails::Application
|
16
|
+
# Settings in config/environments/* take precedence over those specified here.
|
17
|
+
# Application configuration should go into files in config/initializers
|
18
|
+
# -- all .rb files in that directory are automatically loaded.
|
19
|
+
|
20
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
21
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
22
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
23
|
+
|
24
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
25
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
26
|
+
# config.i18n.default_locale = :de
|
27
|
+
|
28
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
29
|
+
config.active_record.raise_in_transactional_callbacks = true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
#
|
7
|
+
default: &default
|
8
|
+
adapter: sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *default
|
14
|
+
database: db/development.sqlite3
|
15
|
+
|
16
|
+
# Warning: The database defined as "test" will be erased and
|
17
|
+
# re-generated from your development database when you run "rake".
|
18
|
+
# Do not set this db to the same as development or production.
|
19
|
+
test:
|
20
|
+
<<: *default
|
21
|
+
database: db/test.sqlite3
|
22
|
+
|
23
|
+
production:
|
24
|
+
<<: *default
|
25
|
+
database: db/production.sqlite3
|