petrie 0.1.0
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/MIT-LICENSE +20 -0
- data/README.md +30 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/petrie/application.js +13 -0
- data/app/assets/javascripts/sir-trevor/initializer.js.coffee +6 -0
- data/app/assets/javascripts/sortable_tree/initializer.js.coffee +54 -0
- data/app/assets/stylesheets/petrie/application.css +13 -0
- data/app/assets/stylesheets/petrie/sir-trevor.scss +18 -0
- data/app/assets/stylesheets/petrie/sortable-tree.scss +87 -0
- data/app/controllers/petrie/application_controller.rb +4 -0
- data/app/controllers/petrie/pages_controller.rb +42 -0
- data/app/helpers/petrie/application_helper.rb +4 -0
- data/app/helpers/petrie/pages_helper.rb +17 -0
- data/app/helpers/render_sortable_tree_helper.rb +70 -0
- data/app/helpers/sir_trevor_helper.rb +11 -0
- data/app/models/petrie/page.rb +17 -0
- data/app/views/petrie/pages/home.html.erb +0 -0
- data/app/views/petrie/pages/show.html.erb +0 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20131101143926_create_pages.rb +10 -0
- data/db/migrate/20131102232947_add_slug_to_pages.rb +5 -0
- data/db/migrate/20131102233908_add_nested_set_fields_to_pages.rb +8 -0
- data/lib/generators/petrie/activeadmin/USAGE +8 -0
- data/lib/generators/petrie/activeadmin/activeadmin_generator.rb +51 -0
- data/lib/generators/petrie/activeadmin/templates/_tree.html.erb +5 -0
- data/lib/generators/petrie/activeadmin/templates/page.rb +41 -0
- data/lib/generators/petrie/install/USAGE +11 -0
- data/lib/generators/petrie/install/install_generator.rb +21 -0
- data/lib/generators/petrie/install/templates/home.html.erb +4 -0
- data/lib/generators/petrie/install/templates/page.rb +2 -0
- data/lib/generators/petrie/install/templates/pages_controller.rb +11 -0
- data/lib/generators/petrie/install/templates/show.html.erb +4 -0
- data/lib/petrie.rb +4 -0
- data/lib/petrie/engine.rb +13 -0
- data/lib/petrie/version.rb +3 -0
- data/lib/tasks/petrie_tasks.rake +4 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c2f982b5b6f5fe93469c996c6e85f2a065747275
|
4
|
+
data.tar.gz: 78ac53d9b480a551982299ad6486576070e15ba8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14b9ed395b01bb8a33d335307137eee9f913d5f237e6f09246d6392d66f8cdf45b9b35573f347b3da351c4b76e46a88bf85c572bd8f4a2185f9aa2ff1fa10973
|
7
|
+
data.tar.gz: ea6c1e3c618bfed7761da95523a399d78aad54960126627f022dbac1b1b53d33ff963b6a2ee064be409a5b605170e5a344cc069fb50d6ccadd698f9e67c1e23c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Nic Aitch
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Petrie
|
2
|
+
|
3
|
+
Pages for your Rails app. Includes support for ActiveAdmin and Sir Trevor. Built for Rails 4.
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
gem install petrie
|
10
|
+
|
11
|
+
or add to your Gemfile
|
12
|
+
|
13
|
+
gem 'petrie'
|
14
|
+
|
15
|
+
Then run the installer
|
16
|
+
|
17
|
+
rails g petrie:install
|
18
|
+
rake db:migrate
|
19
|
+
|
20
|
+
## ActiveAdmin
|
21
|
+
|
22
|
+
rails g petrie:activeadmin
|
23
|
+
|
24
|
+
# Caution
|
25
|
+
|
26
|
+
Petrie includes a root route to `pages#home`. Generally, this shouldn't be a problem unless you don't want to use a marketing home page as your root.
|
27
|
+
|
28
|
+
## License
|
29
|
+
|
30
|
+
MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
9
|
+
load 'rails/tasks/engine.rake'
|
10
|
+
|
11
|
+
Bundler::GemHelper.install_tasks
|
12
|
+
|
13
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
14
|
+
|
15
|
+
require 'rspec/core'
|
16
|
+
require 'rspec/core/rake_task'
|
17
|
+
|
18
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
19
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
20
|
+
|
21
|
+
task :default => :spec
|
@@ -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 vendor/assets/javascripts of plugins, if any, 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/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,54 @@
|
|
1
|
+
@rebuild_sortable_tree = (rebuild_url, item_id, parent_id, prev_id, next_id) ->
|
2
|
+
$.ajax
|
3
|
+
type: 'POST'
|
4
|
+
dataType: 'script'
|
5
|
+
url: rebuild_url
|
6
|
+
data:
|
7
|
+
id: item_id
|
8
|
+
parent_id: parent_id
|
9
|
+
prev_id: prev_id
|
10
|
+
next_id: next_id
|
11
|
+
|
12
|
+
beforeSend: (xhr) ->
|
13
|
+
$('.sortable-tree i.handle').hide()
|
14
|
+
|
15
|
+
success: (data, status, xhr) ->
|
16
|
+
$('.sortable-tree i.handle').show()
|
17
|
+
|
18
|
+
error: (xhr, status, error) ->
|
19
|
+
console.log error
|
20
|
+
|
21
|
+
$ ->
|
22
|
+
for sortable_tree in $('ol.sortable-tree')
|
23
|
+
sortable_tree = $ sortable_tree
|
24
|
+
rebuild_url = sortable_tree.data('rebuild_url') || sortable_tree.data('rebuild-url')
|
25
|
+
max_levels = sortable_tree.data('max_levels') || sortable_tree.data('max-levels')
|
26
|
+
|
27
|
+
############################################
|
28
|
+
# Initialize Sortable Tree
|
29
|
+
############################################
|
30
|
+
sortable_tree.nestedSortable
|
31
|
+
items: 'li'
|
32
|
+
helper: 'clone'
|
33
|
+
handle: 'i.handle'
|
34
|
+
tolerance: 'pointer'
|
35
|
+
maxLevels: max_levels
|
36
|
+
revert: 250
|
37
|
+
tabSize: 25
|
38
|
+
opacity: 0.6
|
39
|
+
placeholder: 'placeholder'
|
40
|
+
disableNesting: 'no-nest'
|
41
|
+
toleranceElement: '> div'
|
42
|
+
forcePlaceholderSize: true
|
43
|
+
|
44
|
+
############################################
|
45
|
+
# Sortable Update Event
|
46
|
+
############################################
|
47
|
+
sortable_tree.on "sortupdate", (event, ui) =>
|
48
|
+
item = ui.item
|
49
|
+
item_id = item.attr('id')
|
50
|
+
prev_id = item.prev().attr('id')
|
51
|
+
next_id = item.next().attr('id')
|
52
|
+
parent_id = item.parent().parent().attr('id')
|
53
|
+
|
54
|
+
rebuild_sortable_tree(rebuild_url, item_id, parent_id, prev_id, next_id)
|
@@ -0,0 +1,13 @@
|
|
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 vendor/assets/stylesheets of plugins, if any, 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 top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,18 @@
|
|
1
|
+
.st-outer {
|
2
|
+
padding: 30px;
|
3
|
+
background: #fff;
|
4
|
+
margin-top: -10px;
|
5
|
+
border: 1px solid #eaeaea;
|
6
|
+
font-family: Helvetica;
|
7
|
+
}
|
8
|
+
.st-format-bar {
|
9
|
+
font-size: 16px;
|
10
|
+
}
|
11
|
+
.st-text-block {
|
12
|
+
ul {
|
13
|
+
list-style-type: disc;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
.st-block-control {
|
17
|
+
text-decoration: none;
|
18
|
+
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
.sortable-tree {
|
2
|
+
width: 75%;
|
3
|
+
ol {
|
4
|
+
border-left: 1px dashed silver;
|
5
|
+
margin-left: 20px;
|
6
|
+
padding-left: 20px;
|
7
|
+
}
|
8
|
+
|
9
|
+
p {
|
10
|
+
margin-right: 75px;
|
11
|
+
padding: 5px;
|
12
|
+
}
|
13
|
+
|
14
|
+
.item {
|
15
|
+
position: relative;
|
16
|
+
background-color: #f7f7f7;
|
17
|
+
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #f7f7f7), color-stop(100%, #efefef));
|
18
|
+
background-image: -webkit-linear-gradient(#f7f7f7, #efefef);
|
19
|
+
background-image: linear-gradient(#f7f7f7, #efefef);
|
20
|
+
border-bottom: 1px solid #dedede;
|
21
|
+
border-radius: 3px;
|
22
|
+
margin-bottom: 5px;
|
23
|
+
&:hover {
|
24
|
+
background: #eee;
|
25
|
+
}
|
26
|
+
> a {
|
27
|
+
text-decoration: none;
|
28
|
+
display: block;
|
29
|
+
margin-left: 0;
|
30
|
+
padding: 10px 15px;
|
31
|
+
font-size: 16px;
|
32
|
+
&:hover{
|
33
|
+
background: #eee;
|
34
|
+
text-decoration: underline;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
.placeholder {
|
40
|
+
background-color: #fff8cb;
|
41
|
+
border-bottom: 1px solid #FFF298;
|
42
|
+
margin-bottom: 3px;
|
43
|
+
border-radius: 3px;
|
44
|
+
height: 40px;
|
45
|
+
}
|
46
|
+
|
47
|
+
.ui-nestedSortable-error {
|
48
|
+
background: #FAA;
|
49
|
+
color: #8a1f11;
|
50
|
+
}
|
51
|
+
|
52
|
+
.handle {
|
53
|
+
cursor: move;
|
54
|
+
padding: 10px;
|
55
|
+
color: #ccc;
|
56
|
+
font-size: 16px;
|
57
|
+
text-decoration: none;
|
58
|
+
line-height: 1.2;
|
59
|
+
float: left;
|
60
|
+
&:hover {
|
61
|
+
color: #4e5357;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
.controls {
|
66
|
+
position: absolute;
|
67
|
+
top: 0;
|
68
|
+
bottom: 0;
|
69
|
+
right: 0;
|
70
|
+
|
71
|
+
a {
|
72
|
+
padding: 10px;
|
73
|
+
color: #aaa;
|
74
|
+
font-size: 16px;
|
75
|
+
text-decoration: none;
|
76
|
+
line-height: 1.2;
|
77
|
+
&:hover {
|
78
|
+
color: #4e5357;
|
79
|
+
}
|
80
|
+
&.delete{
|
81
|
+
&:hover {
|
82
|
+
color: red;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_dependency "petrie/application_controller"
|
2
|
+
|
3
|
+
module Petrie
|
4
|
+
class PagesController < ApplicationController
|
5
|
+
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
6
|
+
|
7
|
+
def home
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
@page = find_by_slug
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def find_by_slug
|
17
|
+
page_slugs = params[:page].split(/\//).reverse
|
18
|
+
candidates = Page.where(slug: page_slugs.first)
|
19
|
+
|
20
|
+
return not_found if candidates.empty?
|
21
|
+
return candidates.first if candidates.count == 1
|
22
|
+
|
23
|
+
resolve_duplicates(page_slugs, candidates)
|
24
|
+
end
|
25
|
+
|
26
|
+
def resolve_duplicates(page_slugs, candidates)
|
27
|
+
page_slugs.shift
|
28
|
+
page_slugs.each do |page|
|
29
|
+
parent_candidate = Page.friendly.find(page)
|
30
|
+
|
31
|
+
candidates.each do |c|
|
32
|
+
return c if parent_candidate.is_ancestor_of?(c)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def not_found
|
38
|
+
raise ActionController::RoutingError.new('Not Found')
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Petrie
|
2
|
+
module PagesHelper
|
3
|
+
def ancestor
|
4
|
+
@ancestor ||= @page.top_ancestor
|
5
|
+
end
|
6
|
+
|
7
|
+
def children
|
8
|
+
@children ||= ancestor.children
|
9
|
+
end
|
10
|
+
|
11
|
+
def page_path(page)
|
12
|
+
page.self_and_ancestors.collect { |a|
|
13
|
+
a.slug unless a.slug == 'home'
|
14
|
+
}.unshift('').join('/')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# DOC:
|
2
|
+
# We use Helper Methods for tree building,
|
3
|
+
# because it's faster than View Templates and Partials
|
4
|
+
|
5
|
+
# SECURITY note
|
6
|
+
# Prepare your data on server side for rendering
|
7
|
+
# or use h.html_escape(node.content)
|
8
|
+
# for escape potentially dangerous content
|
9
|
+
module RenderSortableTreeHelper
|
10
|
+
module Render
|
11
|
+
class << self
|
12
|
+
attr_accessor :h, :options
|
13
|
+
|
14
|
+
def render_node(h, options)
|
15
|
+
@h, @options = h, options
|
16
|
+
|
17
|
+
node = options[:node]
|
18
|
+
|
19
|
+
"
|
20
|
+
<li id='#{ node.id }_#{ options[:klass] }'>
|
21
|
+
<div class='item'>
|
22
|
+
<i class='fa fa-ellipsis-vertical handle'></i>
|
23
|
+
#{ edit_link }
|
24
|
+
#{ controls }
|
25
|
+
</div>
|
26
|
+
#{ children }
|
27
|
+
</li>
|
28
|
+
"
|
29
|
+
end
|
30
|
+
|
31
|
+
def edit_link
|
32
|
+
node = options[:node]
|
33
|
+
edit_path = h.url_for(:controller => options[:klass].pluralize, :action => :edit, :id => node)
|
34
|
+
|
35
|
+
"#{ h.link_to node.send(options[:title]), edit_path}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def show_link
|
39
|
+
node = options[:node]
|
40
|
+
ns = options[:namespace]
|
41
|
+
url = h.url_for(ns + [node])
|
42
|
+
title_field = options[:title]
|
43
|
+
|
44
|
+
"#{ h.link_to(node.send(title_field), url) }"
|
45
|
+
end
|
46
|
+
|
47
|
+
def controls
|
48
|
+
node = options[:node]
|
49
|
+
ns = options[:namespace]
|
50
|
+
|
51
|
+
preview_url = h.url_for(ns + [node])
|
52
|
+
show_path = h.url_for(:controller => options[:klass].pluralize, :action => :show, :id => node)
|
53
|
+
|
54
|
+
"
|
55
|
+
<div class='controls'>
|
56
|
+
#{ h.link_to '', preview_url, :class => 'fa fa-external-link-square' }
|
57
|
+
#{ h.link_to '', show_path, :class => 'fa fa-trash-o delete', :method => :delete, :data => { :confirm => 'Are you sure?' } }
|
58
|
+
</div>
|
59
|
+
"
|
60
|
+
end
|
61
|
+
|
62
|
+
def children
|
63
|
+
unless options[:children].blank?
|
64
|
+
"<ol class='nested_set'>#{ options[:children] }</ol>"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Petrie
|
2
|
+
class Page < ActiveRecord::Base
|
3
|
+
extend FriendlyId
|
4
|
+
friendly_id :title, use: [:scoped, :slugged], scope: :parent
|
5
|
+
|
6
|
+
acts_as_nested_set
|
7
|
+
|
8
|
+
def should_generate_new_friendly_id?
|
9
|
+
title_changed?
|
10
|
+
end
|
11
|
+
|
12
|
+
def top_ancestor
|
13
|
+
return parent.top_ancestor if parent
|
14
|
+
self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
File without changes
|
File without changes
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
root to: 'pages#home'
|
3
|
+
|
4
|
+
get 'home', to: redirect('/')
|
5
|
+
get '*page', to: 'pages#show', format: false, as: :page
|
6
|
+
|
7
|
+
if defined? ActiveAdmin
|
8
|
+
namespace :admin do
|
9
|
+
resources :pages do
|
10
|
+
collection do
|
11
|
+
post :rebuild
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Petrie::ActiveadminGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def add_gems
|
5
|
+
gem 'font-awesome-rails'
|
6
|
+
gem "the_sortable_tree", "~> 2.3.0"
|
7
|
+
gem 'sir-trevor-rails', github: 'maxmcd/sir-trevor-rails'
|
8
|
+
end
|
9
|
+
|
10
|
+
def copy_templates
|
11
|
+
copy_file '_tree.html.erb', 'app/views/admin/pages/_tree.html.erb'
|
12
|
+
copy_file 'page.rb', 'app/admin/page.rb'
|
13
|
+
end
|
14
|
+
|
15
|
+
def update_page_model
|
16
|
+
insert_into_file "app/models/page.rb",
|
17
|
+
:after => %Q(class Page < Petrie::Page) do <<-'RUBY'
|
18
|
+
|
19
|
+
include TheSortableTree::Scopes
|
20
|
+
RUBY
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def import_stylesheets
|
25
|
+
insert_into_file "app/assets/stylesheets/active_admin.css.scss",
|
26
|
+
:after => %Q(@import "active_admin/base";) do <<-'RUBY'
|
27
|
+
|
28
|
+
@import "font-awesome";
|
29
|
+
@import "sortable_tree";
|
30
|
+
@import "nested_options";
|
31
|
+
@import "sir-trevor/icons";
|
32
|
+
@import "sir-trevor/sir-trevor";
|
33
|
+
|
34
|
+
@import "petrie/sir-trevor";
|
35
|
+
@import "petrie/sortable-tree";
|
36
|
+
RUBY
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def require_javascripts
|
41
|
+
insert_into_file "app/assets/javascripts/active_admin.js.coffee",
|
42
|
+
:after => %Q(#= require active_admin/base) do <<-'RUBY'
|
43
|
+
|
44
|
+
#= require jquery.ui.nestedSortable
|
45
|
+
#= require sortable_tree/initializer
|
46
|
+
#= require sir-trevor
|
47
|
+
#= require sir-trevor/initializer
|
48
|
+
RUBY
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
ActiveAdmin.register Page do
|
2
|
+
config.filters = false
|
3
|
+
actions :all, :except => [:show]
|
4
|
+
|
5
|
+
form do |f|
|
6
|
+
f.inputs "Details" do
|
7
|
+
f.input :title
|
8
|
+
f.input :parent_id, as: :select,
|
9
|
+
collection: nested_set_options(resource_class, resource) { |i|
|
10
|
+
"#{'—' * i.level} #{i.title}".html_safe
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
f.inputs "Content" do
|
15
|
+
f.sir_trevor_text_area :body
|
16
|
+
end
|
17
|
+
|
18
|
+
f.actions
|
19
|
+
end
|
20
|
+
|
21
|
+
index :download_links => false do
|
22
|
+
render 'tree'
|
23
|
+
end
|
24
|
+
|
25
|
+
controller do
|
26
|
+
include TheSortableTreeController::Rebuild
|
27
|
+
|
28
|
+
def index
|
29
|
+
@resource = Page.nested_set
|
30
|
+
end
|
31
|
+
|
32
|
+
def permitted_params
|
33
|
+
params.permit!
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_resource
|
37
|
+
scoped_collection.friendly.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Petrie::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def copy_models
|
5
|
+
copy_file 'pages_controller.rb', 'app/controllers/pages_controller.rb'
|
6
|
+
end
|
7
|
+
|
8
|
+
def copy_views
|
9
|
+
copy_file 'home.html.erb', 'app/views/pages/home.html.erb'
|
10
|
+
copy_file 'show.html.erb', 'app/views/pages/show.html.erb'
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_controllers
|
14
|
+
copy_file 'page.rb', 'app/models/page.rb'
|
15
|
+
end
|
16
|
+
|
17
|
+
def install_migrations
|
18
|
+
rake "petrie_engine:install:migrations"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/petrie.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'friendly_id'
|
2
|
+
require 'awesome_nested_set'
|
3
|
+
|
4
|
+
module Petrie
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
config.generators do |g|
|
7
|
+
g.test_framework :rspec, :fixture => false
|
8
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
9
|
+
g.assets false
|
10
|
+
g.helper false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: petrie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nic Aitch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: awesome_nested_set
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: friendly_id
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Say 'ptree'
|
70
|
+
email:
|
71
|
+
- nic@nicinabox.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- app/assets/javascripts/petrie/application.js
|
77
|
+
- app/assets/javascripts/sir-trevor/initializer.js.coffee
|
78
|
+
- app/assets/javascripts/sortable_tree/initializer.js.coffee
|
79
|
+
- app/assets/stylesheets/petrie/application.css
|
80
|
+
- app/assets/stylesheets/petrie/sir-trevor.scss
|
81
|
+
- app/assets/stylesheets/petrie/sortable-tree.scss
|
82
|
+
- app/controllers/petrie/application_controller.rb
|
83
|
+
- app/controllers/petrie/pages_controller.rb
|
84
|
+
- app/helpers/petrie/application_helper.rb
|
85
|
+
- app/helpers/petrie/pages_helper.rb
|
86
|
+
- app/helpers/render_sortable_tree_helper.rb
|
87
|
+
- app/helpers/sir_trevor_helper.rb
|
88
|
+
- app/models/petrie/page.rb
|
89
|
+
- app/views/petrie/pages/home.html.erb
|
90
|
+
- app/views/petrie/pages/show.html.erb
|
91
|
+
- config/routes.rb
|
92
|
+
- db/migrate/20131101143926_create_pages.rb
|
93
|
+
- db/migrate/20131102232947_add_slug_to_pages.rb
|
94
|
+
- db/migrate/20131102233908_add_nested_set_fields_to_pages.rb
|
95
|
+
- lib/generators/petrie/activeadmin/activeadmin_generator.rb
|
96
|
+
- lib/generators/petrie/activeadmin/templates/_tree.html.erb
|
97
|
+
- lib/generators/petrie/activeadmin/templates/page.rb
|
98
|
+
- lib/generators/petrie/activeadmin/USAGE
|
99
|
+
- lib/generators/petrie/install/install_generator.rb
|
100
|
+
- lib/generators/petrie/install/templates/home.html.erb
|
101
|
+
- lib/generators/petrie/install/templates/page.rb
|
102
|
+
- lib/generators/petrie/install/templates/pages_controller.rb
|
103
|
+
- lib/generators/petrie/install/templates/show.html.erb
|
104
|
+
- lib/generators/petrie/install/USAGE
|
105
|
+
- lib/petrie/engine.rb
|
106
|
+
- lib/petrie/version.rb
|
107
|
+
- lib/petrie.rb
|
108
|
+
- lib/tasks/petrie_tasks.rake
|
109
|
+
- MIT-LICENSE
|
110
|
+
- Rakefile
|
111
|
+
- README.md
|
112
|
+
homepage: https://github.com/nicinabox/petrie
|
113
|
+
licenses: []
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.0.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Pages for your Rails app
|
135
|
+
test_files: []
|