tkh_content 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/app/assets/javascripts/page.js.coffee +2 -0
- data/app/controllers/blog_controller.rb +5 -1
- data/app/controllers/pages_controller.rb +8 -0
- data/app/helpers/blog_helper.rb +11 -0
- data/app/models/page.rb +46 -5
- data/app/models/tag.rb +23 -0
- data/app/models/tagging.rb +6 -0
- data/app/views/pages/_form.html.erb +10 -2
- data/config/routes.rb +2 -1
- data/lib/generators/tkh_content/create_or_update_migrations/create_or_update_migrations_generator.rb +2 -0
- data/lib/generators/tkh_content/create_or_update_migrations/templates/create_taggings.rb +18 -0
- data/lib/generators/tkh_content/create_or_update_migrations/templates/create_tags.rb +17 -0
- data/lib/tkh_content/version.rb +1 -1
- metadata +10 -4
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
class BlogController < ApplicationController
|
2
2
|
|
3
3
|
def index
|
4
|
-
|
4
|
+
unless params[:tag]
|
5
|
+
@posts = Page.for_blog.published.order('published_at desc').paginate(:page => params[:page], :per_page => 20)
|
6
|
+
else
|
7
|
+
@posts = Page.for_blog.published.tagged_with(params[:tag]).order('published_at desc').paginate(:page => params[:page], :per_page => 20)
|
8
|
+
end
|
5
9
|
# respond_to
|
6
10
|
render :layout => 'blog'
|
7
11
|
end
|
@@ -15,11 +15,13 @@ class PagesController < ApplicationController
|
|
15
15
|
|
16
16
|
def new
|
17
17
|
@page = Page.new
|
18
|
+
page_autocomplete_items
|
18
19
|
switch_to_admin_layout
|
19
20
|
end
|
20
21
|
|
21
22
|
def edit
|
22
23
|
@page = Page.find(params[:id])
|
24
|
+
page_autocomplete_items
|
23
25
|
switch_to_admin_layout
|
24
26
|
end
|
25
27
|
|
@@ -74,4 +76,10 @@ class PagesController < ApplicationController
|
|
74
76
|
redirect_to pages_path notice: "The blog status of the page has been changed"
|
75
77
|
end
|
76
78
|
|
79
|
+
private
|
80
|
+
|
81
|
+
def page_autocomplete_items
|
82
|
+
@autocomplete_items = Page.published.not_for_blog.by_title.map(&:title)
|
83
|
+
end
|
84
|
+
|
77
85
|
end
|
data/app/models/page.rb
CHANGED
@@ -7,7 +7,10 @@ class Page < ActiveRecord::Base
|
|
7
7
|
|
8
8
|
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
|
9
9
|
|
10
|
-
attr_accessible :title, :short_title, :description, :body, :for_blog, :parent_id
|
10
|
+
attr_accessible :title, :short_title, :description, :body, :for_blog, :parent_id, :tag_list, :parent_page_title
|
11
|
+
|
12
|
+
has_many :taggings
|
13
|
+
has_many :tags, through: :taggings
|
11
14
|
|
12
15
|
validates_presence_of :title
|
13
16
|
validates_presence_of :description
|
@@ -28,21 +31,24 @@ class Page < ActiveRecord::Base
|
|
28
31
|
# tree scopes
|
29
32
|
scope :orphans, where('parent_id IS ?', nil)
|
30
33
|
scope :with_parent_id, lambda { |id| where('parent_id = ?', id) }
|
34
|
+
scope :by_title, order('title')
|
31
35
|
|
32
36
|
def nickname
|
33
37
|
short_title || title
|
34
38
|
end
|
35
39
|
|
40
|
+
### menu related instance methods
|
41
|
+
|
36
42
|
def orphan?
|
37
43
|
parent_id == nil
|
38
44
|
end
|
39
45
|
|
40
46
|
def has_children?
|
41
|
-
Page.with_parent_id(id).count >= 1
|
47
|
+
Page.with_parent_id(id).published.count >= 1
|
42
48
|
end
|
43
49
|
|
44
50
|
def children
|
45
|
-
Page.with_parent_id(id)
|
51
|
+
Page.published.with_parent_id(id)
|
46
52
|
end
|
47
53
|
|
48
54
|
def parent
|
@@ -50,11 +56,46 @@ class Page < ActiveRecord::Base
|
|
50
56
|
end
|
51
57
|
|
52
58
|
def has_siblings?
|
53
|
-
Page.with_parent_id(parent_id).count >= 1
|
59
|
+
Page.with_parent_id(parent_id).published.count >= 1
|
54
60
|
end
|
55
61
|
|
56
62
|
def siblings
|
57
|
-
Page.with_parent_id(parent_id)
|
63
|
+
Page.published.with_parent_id(parent_id)
|
64
|
+
end
|
65
|
+
|
66
|
+
### tagging related methods
|
67
|
+
|
68
|
+
def self.tagged_with(name)
|
69
|
+
Tag.find_by_name!(name).pages
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.tag_counts
|
73
|
+
Tag.select("tags.*, count(taggings.tag_id) as count").
|
74
|
+
joins(:taggings).group("taggings.tag_id")
|
75
|
+
end
|
76
|
+
|
77
|
+
def tag_list
|
78
|
+
tags.map(&:name).join(" ")
|
79
|
+
end
|
80
|
+
|
81
|
+
def tag_list=(names)
|
82
|
+
self.tags = names.split(" ").map do |n|
|
83
|
+
Tag.where(name: n.strip).first_or_create!
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
### autocomplete related instance methods
|
88
|
+
|
89
|
+
def parent_page_title
|
90
|
+
parent.try(:title) unless self.orphan?
|
91
|
+
end
|
92
|
+
|
93
|
+
def parent_page_title=(title)
|
94
|
+
if title.present? && Page.find_by_title(title)
|
95
|
+
self.parent_id = Page.find_by_title(title).id
|
96
|
+
else
|
97
|
+
self.parent_id = nil
|
98
|
+
end
|
58
99
|
end
|
59
100
|
|
60
101
|
end
|
data/app/models/tag.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# this is needed for now to make mass assignment security compatible with the translation of globalize3
|
2
|
+
Globalize::ActiveRecord::Translation.class_eval do
|
3
|
+
attr_accessible :locale
|
4
|
+
end
|
5
|
+
|
6
|
+
class Tag < ActiveRecord::Base
|
7
|
+
|
8
|
+
attr_accessible :name
|
9
|
+
|
10
|
+
has_many :taggings
|
11
|
+
has_many :pages, through: :taggings
|
12
|
+
|
13
|
+
translates :name
|
14
|
+
|
15
|
+
scope :alphabetically, order('name')
|
16
|
+
|
17
|
+
def to_param
|
18
|
+
name ? "#{id}-#{name.to_url}" : id
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
@@ -3,9 +3,17 @@
|
|
3
3
|
|
4
4
|
<div class="form-inputs">
|
5
5
|
<%= f.input :title, hint: 'nice and descriptive' %><br />
|
6
|
-
<%= f.input :short_title, hint: 'ideally one word only, used for the menu' %><br />
|
7
|
-
<%= f.input :parent_id %><br />
|
8
6
|
<%= f.input :for_blog %><br />
|
7
|
+
<%= f.input :tag_list, hint: 'space separated' %>
|
8
|
+
<%= f.input :short_title, hint: 'ideally one word only, used for the menu' %><br />
|
9
|
+
<%# = javascript_tag "var autocomplete_items = #{ @autocomplete_items.to_json };" %>
|
10
|
+
<%= f.input :parent_page_title,
|
11
|
+
as: :string,
|
12
|
+
label: 'parent page title',
|
13
|
+
:input_html => { class: 'typeahead',
|
14
|
+
:data => { provide: 'typeahead',
|
15
|
+
source: @autocomplete_items.to_json }
|
16
|
+
} %><br />
|
9
17
|
<%= f.input :description, :input_html => { :rows => 3 } %>
|
10
18
|
<%= f.input :body, :input_html => { :rows => 25, :id => 'editable' } %>
|
11
19
|
</div>
|
data/config/routes.rb
CHANGED
data/lib/generators/tkh_content/create_or_update_migrations/create_or_update_migrations_generator.rb
CHANGED
@@ -20,6 +20,8 @@ module TkhContent
|
|
20
20
|
migration_template "create_pages.rb", "db/migrate/create_pages.rb"
|
21
21
|
migration_template "add_author_to_pages.rb", "db/migrate/add_author_to_pages.rb"
|
22
22
|
migration_template "add_parent_id_to_pages.rb", "db/migrate/add_parent_id_to_pages.rb"
|
23
|
+
migration_template "create_tags.rb", "db/migrate/create_tags.rb"
|
24
|
+
migration_template "create_taggings.rb", "db/migrate/create_taggings.rb"
|
23
25
|
end
|
24
26
|
|
25
27
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateTaggings < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :taggings do |t|
|
5
|
+
t.integer :page_id
|
6
|
+
t.integer :tag_id
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
add_index :taggings, :page_id
|
10
|
+
add_index :taggings, :tag_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :taggings
|
15
|
+
remove_index :taggings, :page_id
|
16
|
+
remove_index :taggings, :tag_id
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateTags < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :tags do |t|
|
5
|
+
t.string :name
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
add_index :tags, :name
|
9
|
+
Tag.create_translation_table! :name => :string
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :tags
|
14
|
+
remove_index :tags, :name
|
15
|
+
Tag.drop_translation_table!
|
16
|
+
end
|
17
|
+
end
|
data/lib/tkh_content/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tkh_content
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -162,9 +162,13 @@ executables: []
|
|
162
162
|
extensions: []
|
163
163
|
extra_rdoc_files: []
|
164
164
|
files:
|
165
|
+
- app/assets/javascripts/page.js.coffee
|
165
166
|
- app/controllers/blog_controller.rb
|
166
167
|
- app/controllers/pages_controller.rb
|
168
|
+
- app/helpers/blog_helper.rb
|
167
169
|
- app/models/page.rb
|
170
|
+
- app/models/tag.rb
|
171
|
+
- app/models/tagging.rb
|
168
172
|
- app/views/blog/index.html.erb
|
169
173
|
- app/views/blog/index.rss.builder
|
170
174
|
- app/views/pages/_form.html.erb
|
@@ -185,6 +189,8 @@ files:
|
|
185
189
|
- lib/generators/tkh_content/create_or_update_migrations/templates/add_author_to_pages.rb
|
186
190
|
- lib/generators/tkh_content/create_or_update_migrations/templates/add_parent_id_to_pages.rb
|
187
191
|
- lib/generators/tkh_content/create_or_update_migrations/templates/create_pages.rb
|
192
|
+
- lib/generators/tkh_content/create_or_update_migrations/templates/create_taggings.rb
|
193
|
+
- lib/generators/tkh_content/create_or_update_migrations/templates/create_tags.rb
|
188
194
|
- lib/tasks/tkh_content_tasks.rake
|
189
195
|
- lib/tkh_content/version.rb
|
190
196
|
- lib/tkh_content.rb
|
@@ -236,7 +242,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
236
242
|
version: '0'
|
237
243
|
segments:
|
238
244
|
- 0
|
239
|
-
hash:
|
245
|
+
hash: -3697178061325346543
|
240
246
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
247
|
none: false
|
242
248
|
requirements:
|
@@ -245,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
251
|
version: '0'
|
246
252
|
segments:
|
247
253
|
- 0
|
248
|
-
hash:
|
254
|
+
hash: -3697178061325346543
|
249
255
|
requirements: []
|
250
256
|
rubyforge_project:
|
251
257
|
rubygems_version: 1.8.23
|