contents 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/MIT-LICENSE +20 -0
- data/README.md +3 -0
- data/Rakefile +37 -0
- data/app/controllers/contents/application_controller.rb +4 -0
- data/app/controllers/contents/pages_controller.rb +14 -0
- data/app/helpers/contents/application_helper.rb +4 -0
- data/app/models/concerns/contents/rails_admin.rb +42 -0
- data/app/models/contents/page.rb +42 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20160128160241_create_contents_pages.rb +20 -0
- data/lib/contents.rb +6 -0
- data/lib/contents/engine.rb +5 -0
- data/lib/contents/version.rb +3 -0
- data/lib/generators/contents/demo_generator.rb +26 -0
- data/lib/tasks/contents_tasks.rake +4 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f92bbe3d6587b08aacc0e8812f8f5350aa9ad9c7
|
4
|
+
data.tar.gz: 2e5be58898fcc8c27b93331c74c4c8c53bdd54ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74dba5c17c8f54d6a2ad9caee3dfed4a5f941f5d9e743b866d2378ec7683beb217b9e7fe53b4c46e50835ba5d32166eb1d9fab9ab4108332a543e654d11e253c
|
7
|
+
data.tar.gz: 01ebca9ecb4f1d24591948eed639db2527d7874105c556c3eb9e840a174c9e253740331d13e21d21d95f0b8695f56b2a848e5725569634620a46ebd2aa29ed9c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Sergey Novikov
|
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
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Contents'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Contents
|
2
|
+
class PagesController < ApplicationController
|
3
|
+
def index
|
4
|
+
params[:page].split('/').each do |slug|
|
5
|
+
@page = Contents::Page.find_by!(slug: slug, contents_page_id: (@page.try(:id) || nil))
|
6
|
+
@page.superpage = @next_superpage
|
7
|
+
|
8
|
+
@next_superpage = @page
|
9
|
+
end
|
10
|
+
|
11
|
+
render @page.template, layout: @page.layout
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Contents
|
4
|
+
module RailsAdmin
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
def layout_enum
|
9
|
+
Dir["#{layouts_paths}/*"].flat_map do |layout_path|
|
10
|
+
Pathname.new(layout_path).basename.to_s.split('.').first
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def template_enum
|
15
|
+
Dir["#{Rails.root.join('app', 'views')}/*/**"].reject { |f| f[layouts_paths.to_s] }.map do |template_path|
|
16
|
+
template_path.split('/').split do |path|
|
17
|
+
path === 'views'
|
18
|
+
end.last.join('/').split('.').first
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
rails_admin do
|
23
|
+
list do
|
24
|
+
field :id
|
25
|
+
field :title
|
26
|
+
end
|
27
|
+
|
28
|
+
edit do
|
29
|
+
field :title
|
30
|
+
field :slug
|
31
|
+
field :description
|
32
|
+
field :keywords
|
33
|
+
field :body
|
34
|
+
field :layout
|
35
|
+
field :template
|
36
|
+
field :superpage
|
37
|
+
field :subpages
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Contents
|
2
|
+
class Page < ActiveRecord::Base
|
3
|
+
include Contents::RailsAdmin if defined?(RailsAdmin)
|
4
|
+
|
5
|
+
belongs_to :superpage, class_name: 'Contents::Page', foreign_key: :contents_page_id
|
6
|
+
has_many :subpages, class_name: 'Contents::Page', foreign_key: :contents_page_id
|
7
|
+
|
8
|
+
before_save :set_layout, :set_template, :set_slug
|
9
|
+
|
10
|
+
scope :orphans, -> { where(contents_page_id: nil) }
|
11
|
+
|
12
|
+
def path
|
13
|
+
path = [self.slug]
|
14
|
+
page = self
|
15
|
+
|
16
|
+
while page.superpage do
|
17
|
+
path << page.superpage.slug
|
18
|
+
page = page.superpage
|
19
|
+
end
|
20
|
+
|
21
|
+
path.reverse.join('/')
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def layouts_paths
|
27
|
+
Rails.root.join('app', 'views', 'layouts')
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_layout
|
31
|
+
self.layout = 'application' if self.layout.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_template
|
35
|
+
self.template = 'application/index' if self.template.empty?
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_slug
|
39
|
+
self.slug = self.title.to_slug.transliterate.normalize if self.slug.empty?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class CreateContentsPages < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :contents_pages do |t|
|
4
|
+
t.string :title
|
5
|
+
t.string :slug
|
6
|
+
t.string :description
|
7
|
+
t.string :keywords
|
8
|
+
t.references :contents_page, index: true, foreign_key: true
|
9
|
+
t.text :body
|
10
|
+
t.string :layout
|
11
|
+
t.string :template
|
12
|
+
|
13
|
+
t.timestamps null: false
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :contents_pages, :slug
|
17
|
+
add_index :contents_pages, :layout
|
18
|
+
add_index :contents_pages, :template
|
19
|
+
end
|
20
|
+
end
|
data/lib/contents.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'faker'
|
3
|
+
|
4
|
+
module Contents
|
5
|
+
module Generators
|
6
|
+
class DemoGenerator < Rails::Generators::Base
|
7
|
+
def seed
|
8
|
+
5.times do
|
9
|
+
page = Contents::Page.create(page_params)
|
10
|
+
page.subpages.create(page_params)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def page_params
|
17
|
+
{
|
18
|
+
title: Faker::Lorem.words.join(' ').to_s.titleize,
|
19
|
+
description: Faker::Lorem.sentence,
|
20
|
+
keywords: Faker::Lorem.words.join(', '),
|
21
|
+
body: Faker::Lorem.paragraph
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: contents
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Novikov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-29 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.2.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faker
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: babosa
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.2
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails_admin
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.8.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.8.1
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- novikov359@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- MIT-LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- app/controllers/contents/application_controller.rb
|
94
|
+
- app/controllers/contents/pages_controller.rb
|
95
|
+
- app/helpers/contents/application_helper.rb
|
96
|
+
- app/models/concerns/contents/rails_admin.rb
|
97
|
+
- app/models/contents/page.rb
|
98
|
+
- config/routes.rb
|
99
|
+
- db/migrate/20160128160241_create_contents_pages.rb
|
100
|
+
- lib/contents.rb
|
101
|
+
- lib/contents/engine.rb
|
102
|
+
- lib/contents/version.rb
|
103
|
+
- lib/generators/contents/demo_generator.rb
|
104
|
+
- lib/tasks/contents_tasks.rake
|
105
|
+
homepage: https://github.com/droptheplot/contents
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.8
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Rails statis pages with slugs, nestings and templates.
|
129
|
+
test_files: []
|
130
|
+
has_rdoc:
|