smug 0.1.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 +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/app/assets/images/.keep +0 -0
- data/app/assets/javascripts/smug/admin/application.js +17 -0
- data/app/assets/stylesheets/smug/admin/application.scss +12 -0
- data/app/assets/stylesheets/smug/admin/list.scss +5 -0
- data/app/assets/stylesheets/smug/admin/space.scss +7 -0
- data/app/controllers/concerns/model_inspection.rb +27 -0
- data/app/controllers/concerns/route_inspection.rb +15 -0
- data/app/controllers/smug/admin/base_controller.rb +9 -0
- data/app/controllers/smug/admin/crud_controller.rb +67 -0
- data/app/controllers/smug/admin/dashboards_controller.rb +8 -0
- data/app/controllers/smug/admin/passwords_controller.rb +7 -0
- data/app/controllers/smug/admin/sessions_controller.rb +6 -0
- data/app/decorators/smug/admin/decorator.rb +25 -0
- data/app/decorators/smug/admin/index_decorator.rb +6 -0
- data/app/decorators/smug/admin/new_decorator.rb +6 -0
- data/app/decorators/smug/admin/pagination_decorator.rb +13 -0
- data/app/decorators/smug/admin/show_decorator.rb +6 -0
- data/app/models/smug/administrator.rb +5 -0
- data/app/views/layouts/smug/_flash.html.slim +4 -0
- data/app/views/layouts/smug/_nav.html.slim +8 -0
- data/app/views/layouts/smug/admin.html.slim +15 -0
- data/app/views/layouts/smug/admin_no_nav.html.slim +15 -0
- data/app/views/smug/admin/crud/_form.html.slim +4 -0
- data/app/views/smug/admin/crud/edit.html.slim +8 -0
- data/app/views/smug/admin/crud/index.html.slim +39 -0
- data/app/views/smug/admin/crud/new.html.slim +8 -0
- data/app/views/smug/admin/crud/show.html.slim +10 -0
- data/app/views/smug/admin/dashboards/show.html.slim +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/initializers/devise.rb +267 -0
- data/config/locales/devise.en.yml +62 -0
- data/config/locales/en.yml +4 -0
- data/config/routes.rb +16 -0
- data/db/migrate/1_create_smug_administrators.rb +32 -0
- data/lib/smug/configuration.rb +9 -0
- data/lib/smug/engine.rb +8 -0
- data/lib/smug/plugin.rb +32 -0
- data/lib/smug/version.rb +3 -0
- data/lib/smug.rb +30 -0
- data/smug.gemspec +38 -0
- data/spec/smug_spec.rb +7 -0
- data/spec/spec_helper.rb +20 -0
- metadata +292 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45cb8eb3d75b11d44a888fa799c426385c620c5f
|
4
|
+
data.tar.gz: 4f10d7737c629d5f4d52a57e4bbf601b13f00486
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b79eb2a00149c4a9d33d288dfcdb5cb5d7bc44e080697d4979c4ab9587617c4ece4850e35b31db0cb4569c4c3845a33cba5e302ec05e830ffb3972f1f90574a
|
7
|
+
data.tar.gz: a578bdc011764430aa2000c5725997c6fe51e4d214cecba5d02e9da4270469a9b3dd3eb4357ff829f959d6269d1dd68dae74dea54bc83af24088f8a731853574
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Nick Bolt
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Smug
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/smug`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'smug'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install smug
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/smug.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,17 @@
|
|
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 jquery
|
14
|
+
//= require bootstrap-sprockets
|
15
|
+
//= require jquery_ujs
|
16
|
+
//= require turbolinks
|
17
|
+
//= require_tree .
|
@@ -0,0 +1,12 @@
|
|
1
|
+
@import "bootstrap-sprockets";
|
2
|
+
@import "bootswatch/yeti/variables";
|
3
|
+
@import "bootstrap";
|
4
|
+
@import "devise_bootstrap_views";
|
5
|
+
|
6
|
+
// Bootstrap body padding for fixed navbar
|
7
|
+
body { padding-top: 60px; }
|
8
|
+
|
9
|
+
@import "bootswatch/yeti/bootswatch";
|
10
|
+
|
11
|
+
@import "space";
|
12
|
+
@import "list";
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module ModelInspection
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def model
|
8
|
+
controller_name.classify.constantize
|
9
|
+
end
|
10
|
+
|
11
|
+
def model_name
|
12
|
+
model.model_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def index_attrs
|
16
|
+
model.persistable_attribute_names - %w{ id updated_at created_at }
|
17
|
+
end
|
18
|
+
|
19
|
+
def show_attrs
|
20
|
+
model.persistable_attribute_names
|
21
|
+
end
|
22
|
+
|
23
|
+
def edit_attrs
|
24
|
+
model.persistable_attribute_names - %w{ id updated_at created_at }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module RouteInspection
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def route_options
|
8
|
+
{ only: item_actions }
|
9
|
+
end
|
10
|
+
|
11
|
+
def item_actions
|
12
|
+
[:new, :create, :edit, :update, :destroy, :index]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Smug
|
2
|
+
module Admin
|
3
|
+
class CrudController < BaseController
|
4
|
+
include ModelInspection
|
5
|
+
include RouteInspection
|
6
|
+
|
7
|
+
before_action :find_items, only: :index
|
8
|
+
before_action :find_item, only: [:show, :edit, :update, :destroy]
|
9
|
+
|
10
|
+
def index
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
def new
|
17
|
+
@item = NewDecorator.decorate(self.class.model.new)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
@item = self.class.model.new(item_params)
|
22
|
+
if @item.save
|
23
|
+
flash[:notice] = t ".created", default: "Record created"
|
24
|
+
redirect_to [:admin, self.class.model_name.route_key]
|
25
|
+
else
|
26
|
+
@item = NewDecorator.decorate(@item)
|
27
|
+
render action: :new
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def edit
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
if @item.update(item_params)
|
36
|
+
flash[:notice] = t ".updated", default: "Record updated"
|
37
|
+
redirect_to [:admin, self.class.model_name.route_key]
|
38
|
+
else
|
39
|
+
render :edit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def destroy
|
44
|
+
@item.destroy
|
45
|
+
flash[:notice] = t ".destroyed", default: "Record destroyed"
|
46
|
+
redirect_to [:admin, self.class.model_name.route_key]
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def find_items
|
52
|
+
@items = self.class.model.all
|
53
|
+
@items = @items.paginate(page: params[:page])
|
54
|
+
@items = PaginationDecorator.decorate(@items)
|
55
|
+
end
|
56
|
+
|
57
|
+
def find_item
|
58
|
+
@item = self.class.model.find(params[:id])
|
59
|
+
@item = ShowDecorator.decorate(@item)
|
60
|
+
end
|
61
|
+
|
62
|
+
def item_params
|
63
|
+
params.require(self.class.model_name.param_key).permit!
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
module Smug
|
3
|
+
module Admin
|
4
|
+
class Decorator < Draper::Decorator
|
5
|
+
delegate_all
|
6
|
+
|
7
|
+
LOCALIZABLE_CLASSES = [Date, ActiveSupport::TimeWithZone]
|
8
|
+
TRUNCATABLE_CLASSES = [String]
|
9
|
+
|
10
|
+
def render_attr(attr)
|
11
|
+
output = model.send(attr)
|
12
|
+
|
13
|
+
if output.class.in?(LOCALIZABLE_CLASSES)
|
14
|
+
return h.l(output)
|
15
|
+
end
|
16
|
+
|
17
|
+
if output.class.in?(TRUNCATABLE_CLASSES)
|
18
|
+
return h.truncate(output, length: 140)
|
19
|
+
end
|
20
|
+
|
21
|
+
output
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Smug
|
2
|
+
module Admin
|
3
|
+
class PaginationDecorator < Draper::CollectionDecorator
|
4
|
+
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
|
5
|
+
|
6
|
+
def decorator_class
|
7
|
+
# TODO: Need ability to have an item use a different decorator here
|
8
|
+
# easily
|
9
|
+
IndexDecorator
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
doctype html
|
2
|
+
html
|
3
|
+
head
|
4
|
+
meta content=("text/html; charset=UTF-8") http-equiv="Content-Type" /
|
5
|
+
title Admin
|
6
|
+
= stylesheet_link_tag 'smug/admin/application',
|
7
|
+
media: 'all',
|
8
|
+
'data-turbolinks-track' => true
|
9
|
+
= javascript_include_tag 'smug/admin/application',
|
10
|
+
'data-turbolinks-track' => true
|
11
|
+
= csrf_meta_tags
|
12
|
+
body
|
13
|
+
= render "layouts/smug/nav"
|
14
|
+
= render "layouts/smug/flash"
|
15
|
+
= yield
|
@@ -0,0 +1,15 @@
|
|
1
|
+
doctype html
|
2
|
+
html
|
3
|
+
head
|
4
|
+
meta content=("text/html; charset=UTF-8") http-equiv="Content-Type" /
|
5
|
+
title Admin
|
6
|
+
= stylesheet_link_tag 'smug/admin/application',
|
7
|
+
media: 'all',
|
8
|
+
'data-turbolinks-track' => true
|
9
|
+
= javascript_include_tag 'smug/admin/application',
|
10
|
+
'data-turbolinks-track' => true
|
11
|
+
= csrf_meta_tags
|
12
|
+
body
|
13
|
+
= render "layouts/smug/flash"
|
14
|
+
.container
|
15
|
+
= yield
|
@@ -0,0 +1,39 @@
|
|
1
|
+
.container
|
2
|
+
h1.mb-2.text-center
|
3
|
+
= controller.class.model_name.human(count: 2)
|
4
|
+
|
5
|
+
.text-center
|
6
|
+
- if controller.class.item_actions.include?(:new)
|
7
|
+
= link_to t("smug.admin.new", model: controller.class.model_name.human),
|
8
|
+
[:new, :admin, controller.class.model_name.singular_route_key],
|
9
|
+
class: "btn btn-default mb-2"
|
10
|
+
|
11
|
+
table.table.table-striped
|
12
|
+
thead
|
13
|
+
- controller.class.index_attrs.each do |attr|
|
14
|
+
th = controller.class.model.human_attribute_name(attr)
|
15
|
+
- if (controller.class.item_actions && [:edit, :destroy, :show]).any?
|
16
|
+
th
|
17
|
+
|
18
|
+
tbody
|
19
|
+
- @items.each do |item|
|
20
|
+
tr
|
21
|
+
- controller.class.index_attrs.each do |attr|
|
22
|
+
td = item.render_attr(attr)
|
23
|
+
- if (controller.class.item_actions && [:edit, :destroy, :show]).any?
|
24
|
+
td
|
25
|
+
.btn-group
|
26
|
+
- if controller.class.item_actions.include?(:show)
|
27
|
+
= link_to [:admin, item.object], class: "btn btn-xs btn-default" do
|
28
|
+
i.glyphicon.glyphicon-eye-open>
|
29
|
+
= t(".show", default: "Show")
|
30
|
+
- if controller.class.item_actions.include?(:edit)
|
31
|
+
= link_to [:edit, :admin, item.object], class: "btn btn-xs btn-default" do
|
32
|
+
i.glyphicon.glyphicon-edit>
|
33
|
+
= t(".edit", default: "Edit")
|
34
|
+
- if controller.class.item_actions.include?(:destroy)
|
35
|
+
= link_to [:admin, item.object], class: "btn btn-xs btn-default", method: :delete, data: { confirm: t(".confirm", default: "Are you sure?") }
|
36
|
+
i.glyphicon.glyphicon-trash>
|
37
|
+
= t(".destroy", default: "Destroy")
|
38
|
+
.text-center
|
39
|
+
= will_paginate @items, renderer: BootstrapPagination::Rails
|
@@ -0,0 +1,10 @@
|
|
1
|
+
.container
|
2
|
+
h1.mb-2.text-center = controller.class.model_name.human
|
3
|
+
.text-center.mb-2
|
4
|
+
= link_to :back do
|
5
|
+
i.glyphicon.glyphicon-arrow-left>
|
6
|
+
= t(".back", default: "Back")
|
7
|
+
dl
|
8
|
+
- controller.class.show_attrs.each do |attr|
|
9
|
+
dt = controller.class.model.human_attribute_name(attr)
|
10
|
+
dd = @item.render_attr(attr)
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "smug"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|