publinator 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/publinator/section_controller.rb +11 -8
- data/app/helpers/publinator/application_helper.rb +50 -0
- data/app/models/publinator/domain_name.rb +3 -16
- data/app/models/publinator/page.rb +3 -3
- data/app/models/publinator/publication.rb +20 -14
- data/app/models/publinator/section.rb +22 -11
- data/app/models/publinator/site.rb +1 -0
- data/app/views/publinator/publishable/show.html.erb +1 -1
- data/db/migrate/20120725201842_create_publinator_publications.rb +11 -11
- data/db/migrate/20121011191348_create_publinator_sections.rb +1 -1
- data/db/migrate/20121017134533_create_publinator_pages.rb +7 -6
- data/lib/publinator/version.rb +1 -1
- data/lib/publinator.rb +54 -0
- data/lib/tasks/publinator_tasks.rake +2 -2
- metadata +4 -6
- data/app/models/publinator/publishable.rb +0 -64
- data/db/migrate/20120725204133_create_publinator_publishables.rb +0 -9
@@ -3,18 +3,21 @@ require_dependency "publinator/application_controller"
|
|
3
3
|
module Publinator
|
4
4
|
class SectionController < ApplicationController
|
5
5
|
before_filter :get_section
|
6
|
-
|
6
|
+
|
7
7
|
def index
|
8
|
+
logger.info "#{@section.id}"
|
8
9
|
@publication = Publinator::Publication.find_by_section_id_and_slug(@section.id, 'index')
|
9
|
-
|
10
|
+
logger.info Publication.all.collect{ |p| "/#{@section.section_slug}/#{p.slug}" }
|
11
|
+
logger.info @publication.to_yaml
|
12
|
+
@publishable = @publication.content
|
10
13
|
begin
|
11
14
|
render "#{params[:section]}/index"
|
12
15
|
rescue ActionView::MissingTemplate
|
13
16
|
render "publinator/publishable/show"
|
14
17
|
end
|
15
|
-
rescue Exception => e
|
16
|
-
|
17
|
-
|
18
|
+
# rescue Exception => e
|
19
|
+
# logger.info e.to_yaml
|
20
|
+
# redirect_to root_url, :notice => "Page not found." if @publication.nil?
|
18
21
|
end
|
19
22
|
|
20
23
|
def show
|
@@ -26,11 +29,11 @@ module Publinator
|
|
26
29
|
render "publinator/publishable/show"
|
27
30
|
end
|
28
31
|
end
|
29
|
-
|
32
|
+
|
30
33
|
private
|
31
|
-
|
34
|
+
|
32
35
|
def get_section
|
33
|
-
@section = Publinator::Section.find(:first, :conditions => ["site_id = ? AND
|
36
|
+
@section = Publinator::Section.find(:first, :conditions => ["site_id = ? AND section_slug = ?", current_site.id, params[:section]])
|
34
37
|
end
|
35
38
|
end
|
36
39
|
end
|
@@ -1,4 +1,54 @@
|
|
1
1
|
module Publinator
|
2
|
+
require 'rdiscount'
|
3
|
+
|
2
4
|
module ApplicationHelper
|
5
|
+
def link_to_page(link_text, section, slug)
|
6
|
+
link_to link_text, "/#{section}/#{slug}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def m(markdown_text)
|
10
|
+
RDiscount.new(markdown_text).to_html.html_safe
|
11
|
+
end
|
12
|
+
|
13
|
+
def menu(array)
|
14
|
+
menu = content_tag(:ul, :class => 'nav_menu') do
|
15
|
+
menu_content = ""
|
16
|
+
array.each do |obj|
|
17
|
+
menu_content += menu_item(obj)
|
18
|
+
end
|
19
|
+
menu_content.html_safe
|
20
|
+
end
|
21
|
+
menu.html_safe
|
22
|
+
end
|
23
|
+
|
24
|
+
def menu_item(obj)
|
25
|
+
logger.info "ready to create entry for #{obj.class} #{obj.id}"
|
26
|
+
if obj.class == Publinator::Publication
|
27
|
+
logger.info "publication's publishable is #{obj.publishable.class} #{obj.publishable.id}"
|
28
|
+
end
|
29
|
+
raise "No publishable found for #{obj.class} #{obj.id}" if !obj.publishable
|
30
|
+
tag_content = content_tag(:li) do
|
31
|
+
li_content = link_to obj.publishable.title, obj.publishable.path
|
32
|
+
if obj.respond_to? :publications
|
33
|
+
li_content += content_tag(:div, :class => "submenu") do
|
34
|
+
if obj.publications && obj.publications.length && obj.publications.length > 0
|
35
|
+
submenu_content = content_tag(:ul) do
|
36
|
+
sub_content = ""
|
37
|
+
obj.publications.each do |pub|
|
38
|
+
logger.info "ready to create entry for #{pub.publishable_type} #{pub.publishable_id} #{pub.slug}"
|
39
|
+
unless pub.slug == 'index'
|
40
|
+
sub_content += menu_item(pub)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
sub_content.html_safe
|
44
|
+
end
|
45
|
+
li_content += submenu_content
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
li_content.html_safe
|
50
|
+
end
|
51
|
+
tag_content
|
52
|
+
end
|
3
53
|
end
|
4
54
|
end
|
@@ -2,22 +2,15 @@ module Publinator
|
|
2
2
|
# Ideas:
|
3
3
|
# * after_create adds link in ~/.pow in development
|
4
4
|
class DomainName < ActiveRecord::Base
|
5
|
-
attr_accessible :default, :name, :shared, :
|
5
|
+
attr_accessible :default, :name, :shared, :site, :subdomain
|
6
6
|
belongs_to :site
|
7
|
-
|
7
|
+
|
8
8
|
# lookup site based on the request
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# @param [Request]
|
11
11
|
# @return [Domain]
|
12
12
|
def self.get_by_domain_name(request)
|
13
|
-
@sites = Site.all.collect{ |s| s.name }
|
14
|
-
logger.info "Sites (#{Site.count}) -- #{@sites}"
|
15
|
-
|
16
|
-
@domain_names = DomainName.all.collect{ |dn| "#{dn.subdomain}.#{dn.name}"}
|
17
|
-
logger.info "DomainNames (#{DomainName.count}) -- #{@domain_names}"
|
18
|
-
|
19
13
|
if request.env['x-forwarded-for']
|
20
|
-
logger.info "processing forwarded request..."
|
21
14
|
origin = request.env['x-forwarded-for'].to_s
|
22
15
|
domain_array = origin.split('.')
|
23
16
|
domain_array_length = origin.length
|
@@ -29,26 +22,20 @@ module Publinator
|
|
29
22
|
request_domain = "#{domain_array[domain_array_length - 2]}.#{domain_array[domain_array_length - 1]}"
|
30
23
|
end
|
31
24
|
else
|
32
|
-
logger.info "processing direct request..."
|
33
25
|
request_subdomain = request.subdomain
|
34
26
|
request_domain = request.domain
|
35
27
|
end
|
36
28
|
if request_domain.present?
|
37
|
-
logger.info "request_domain is #{request_domain}..."
|
38
29
|
if request_subdomain.blank? || request_subdomain == 'www'
|
39
|
-
logger.info "request_subdomain is #{request_subdomain}..."
|
40
30
|
@domain = self.find(:first, :conditions => ["name = ? AND (subdomain is null or subdomain = '')", request_domain])
|
41
31
|
elsif request_subdomain.present? && request_subdomain != 'www'
|
42
|
-
logger.info "non-www request_subdomain is #{request_subdomain}..."
|
43
32
|
@domain = self.find(:first, :conditions => ["name = ? AND subdomain = ?", request_domain, request_subdomain])
|
44
33
|
else
|
45
34
|
@domain = self.find(:first, :conditions => ["name = ? AND subdomain = 'www' AND anchor = ?", request_domain, true])
|
46
35
|
end
|
47
36
|
else
|
48
|
-
logger.info "request_domain was not found. finding default site..."
|
49
37
|
@domain = Site.default.domain_names.detect { |d| d.default }
|
50
38
|
end
|
51
|
-
logger.info @domain.to_yaml
|
52
39
|
return @domain
|
53
40
|
end
|
54
41
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Publinator
|
2
|
-
class Page <
|
2
|
+
class Page < ActiveRecord::Base
|
3
3
|
self.table_name = 'publinator_pages'
|
4
|
-
|
5
|
-
|
4
|
+
acts_as_publishable
|
5
|
+
attr_accessible :body, :kicker, :subtitle, :teaser, :title, :section
|
6
6
|
end
|
7
7
|
end
|
@@ -2,34 +2,40 @@ module Publinator
|
|
2
2
|
class Publication < ActiveRecord::Base
|
3
3
|
# has_paper_trail
|
4
4
|
attr_accessible :custom_slug, :parent_id, :publication_state_id,
|
5
|
-
:publishable_id, :publishable_type, :
|
6
|
-
:unpublish_at, :archive_at, :
|
5
|
+
:publishable_id, :publishable_type, :slug, :publish_at,
|
6
|
+
:unpublish_at, :archive_at, :section, :default, :publishable, :site
|
7
7
|
belongs_to :publishable, :polymorphic => true
|
8
|
-
belongs_to :section
|
8
|
+
belongs_to :section, :class_name => "Publinator::Section"
|
9
9
|
belongs_to :site
|
10
10
|
|
11
|
-
validates_uniqueness_of :custom_slug, :scope => :site_id, :allow_blank => true
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
validates_uniqueness_of :custom_slug, :scope => [:site_id, :section_id, :publishable_type], :allow_blank => true
|
12
|
+
validates_uniqueness_of :slug, :scope => [:site_id, :section_id, :publishable_type]
|
13
|
+
validates_presence_of :site
|
14
|
+
|
16
15
|
before_validation :generate_slug
|
16
|
+
before_save :generate_slug
|
17
17
|
|
18
18
|
scope :published, where(:publication_state_id => 1)
|
19
19
|
scope :for_site, lambda { |site_id| where("site_id = ?", site_id) }
|
20
20
|
|
21
|
+
def content
|
22
|
+
publishable_type.constantize.find(publishable_id)
|
23
|
+
end
|
24
|
+
|
21
25
|
def generate_slug
|
22
|
-
|
23
|
-
|
26
|
+
logger.info "generating slug"
|
27
|
+
if self.slug.blank? || slug =~ /temporary_slug\d?/
|
28
|
+
if default
|
29
|
+
self.slug = 'index'
|
30
|
+
elsif custom_slug.present?
|
24
31
|
self.slug = custom_slug
|
25
32
|
elsif publishable.present? && publishable.title.present?
|
26
|
-
self.slug = publishable.title.strip.downcase.gsub(
|
27
|
-
elsif publishable.present? && publishable.section_id.present?
|
28
|
-
self.slug = 'index'
|
33
|
+
self.slug = self.publishable.title.strip.downcase.gsub(/[^a-zA-Z0-9\-\_]/, '_')
|
29
34
|
else
|
30
|
-
self.slug = "
|
35
|
+
self.slug = "temporary_slug_#{rand(100000)}"
|
31
36
|
end
|
32
37
|
end
|
38
|
+
logger.info "slug is #{ slug }"
|
33
39
|
end
|
34
40
|
|
35
41
|
def self.get_by_slug(slug)
|
@@ -1,25 +1,36 @@
|
|
1
1
|
# TODO Validate new sections - can't conflict with publishable_types
|
2
2
|
module Publinator
|
3
3
|
class Section < ActiveRecord::Base
|
4
|
-
attr_accessible :layout, :name, :parent_id, :
|
5
|
-
belongs_to :site
|
6
|
-
has_many :publications
|
7
|
-
before_create :
|
4
|
+
attr_accessible :layout, :name, :parent_id, :site, :section_slug
|
5
|
+
belongs_to :site, :class_name => "Publinator::Site"
|
6
|
+
has_many :publications, :class_name => "Publinator::Publication"
|
7
|
+
before_create :generate_section_slug
|
8
|
+
alias_attribute :title, :name
|
8
9
|
|
9
10
|
def self.matches?(request)
|
10
|
-
pt = self.find(:first, :conditions => ["
|
11
|
+
pt = self.find(:first, :conditions => ["section_slug = ?", request.path_parameters[:section]])
|
11
12
|
return pt.present?
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
# current_site.id, params[:section]
|
15
16
|
def self.get_by_site_id_and_slug(site_id, section_name)
|
16
17
|
Section.find(:first, :conditions => ["site_id = ? and name = ?", site_id, section_name])
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def index_item
|
21
|
+
Publinator::Publication.find_by_section_id_and_slug(id, 'index')
|
22
|
+
end
|
23
|
+
|
24
|
+
def path
|
25
|
+
"/#{section_slug}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def publishable
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate_section_slug
|
33
|
+
self.section_slug = name.strip.downcase.gsub(/[^a-zA-Z0-9\-\_]/, '_') if section_slug.blank?
|
34
|
+
end
|
24
35
|
end
|
25
36
|
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
class CreatePublinatorPublications < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :publinator_publications do |t|
|
4
|
-
t.integer
|
5
|
-
t.integer
|
6
|
-
t.integer
|
7
|
-
t.
|
8
|
-
t.string
|
9
|
-
t.
|
10
|
-
t.datetime
|
11
|
-
t.datetime
|
12
|
-
t.
|
13
|
-
t.
|
4
|
+
t.integer :site_id
|
5
|
+
t.integer :publication_state_id
|
6
|
+
t.integer :parent_id
|
7
|
+
t.integer :section_id
|
8
|
+
t.string :custom_slug
|
9
|
+
t.string :slug
|
10
|
+
t.datetime :publish_at
|
11
|
+
t.datetime :unpublish_at
|
12
|
+
t.datetime :archive_at
|
13
|
+
t.references :publishable, :polymorphic => true
|
14
|
+
t.boolean :default
|
14
15
|
|
15
16
|
t.timestamps
|
16
17
|
end
|
17
18
|
add_index :publinator_publications, :site_id
|
18
19
|
add_index :publinator_publications, :publication_state_id
|
19
|
-
add_index :publinator_publications, :publishable_id
|
20
20
|
end
|
21
21
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
class CreatePublinatorPages < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :publinator_pages do |t|
|
4
|
-
t.
|
5
|
-
t.string
|
6
|
-
t.string
|
7
|
-
t.string
|
8
|
-
t.
|
9
|
-
t.
|
4
|
+
t.integer :site_id
|
5
|
+
t.string :title
|
6
|
+
t.string :subtitle
|
7
|
+
t.string :kicker
|
8
|
+
t.string :teaser
|
9
|
+
t.string :custom_slug
|
10
|
+
t.text :body
|
10
11
|
|
11
12
|
t.timestamps
|
12
13
|
end
|
data/lib/publinator/version.rb
CHANGED
data/lib/publinator.rb
CHANGED
@@ -1,4 +1,58 @@
|
|
1
1
|
require "publinator/engine"
|
2
2
|
|
3
3
|
module Publinator
|
4
|
+
module ActsAsPublishable
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def acts_as_publishable(options = {})
|
12
|
+
has_one :publication,
|
13
|
+
:as => :publishable,
|
14
|
+
:class_name => "Publinator::Publication",
|
15
|
+
:foreign_key => :publishable_id
|
16
|
+
|
17
|
+
accepts_nested_attributes_for :publication
|
18
|
+
validates_presence_of :publication
|
19
|
+
validates_associated :publication
|
20
|
+
|
21
|
+
before_validation :verify_publication
|
22
|
+
belongs_to :site, :class_name => "Publinator::Site"
|
23
|
+
belongs_to :section, :class_name => "Publinator::Section"
|
24
|
+
|
25
|
+
attr_accessible :site, :publication, :section, :default
|
26
|
+
attr_accessor :default
|
27
|
+
|
28
|
+
scope :non_index, joins(:publication).where("publication.slug != 'index'")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def editable_fields
|
33
|
+
attribute_names - ["id", "created_at", "updated_at"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def path
|
37
|
+
raise "publication not found" if !self.publication
|
38
|
+
if self.publication.section
|
39
|
+
"/#{self.publication.section.section_slug}/#{self.publication.slug}"
|
40
|
+
else
|
41
|
+
"/#{self.class.to_s.pluralize}/#{self.publication.slug}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def verify_publication
|
46
|
+
logger.info "verifying publication"
|
47
|
+
if publication.nil?
|
48
|
+
self.publication = Publinator::Publication.new(:publishable => self)
|
49
|
+
end
|
50
|
+
self.publication.site = site
|
51
|
+
self.publication.section = section unless !section
|
52
|
+
self.publication.default = default
|
53
|
+
end
|
54
|
+
end
|
4
55
|
end
|
56
|
+
|
57
|
+
ActiveRecord::Base.send :include, Publinator::ActsAsPublishable
|
58
|
+
|
@@ -1,9 +1,9 @@
|
|
1
1
|
namespace :publinator do
|
2
2
|
desc "Dump DB, then repopulate it."
|
3
3
|
task :repopulate => :environment do
|
4
|
-
["db:drop", "
|
4
|
+
["db:drop", "publinator:install:migrations", "db:create", "db:migrate", "db:seed"].each do |t|
|
5
5
|
Rake::Task[t].execute
|
6
6
|
`touch tmp/restart.txt`
|
7
7
|
end
|
8
8
|
end
|
9
|
-
end
|
9
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: publinator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
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-10-
|
12
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -250,7 +250,6 @@ files:
|
|
250
250
|
- app/models/publinator/page.rb
|
251
251
|
- app/models/publinator/publication.rb
|
252
252
|
- app/models/publinator/publication_state.rb
|
253
|
-
- app/models/publinator/publishable.rb
|
254
253
|
- app/models/publinator/publishable_type.rb
|
255
254
|
- app/models/publinator/section.rb
|
256
255
|
- app/models/publinator/site.rb
|
@@ -288,7 +287,6 @@ files:
|
|
288
287
|
- db/migrate/20120725202127_create_publinator_workflows.rb
|
289
288
|
- db/migrate/20120725202425_create_publinator_workflow_steps.rb
|
290
289
|
- db/migrate/20120725202718_create_publinator_site_workflows.rb
|
291
|
-
- db/migrate/20120725204133_create_publinator_publishables.rb
|
292
290
|
- db/migrate/20120726234227_create_versions.rb
|
293
291
|
- db/migrate/20120726234703_create_publinator_publishable_types.rb
|
294
292
|
- db/migrate/20121011191348_create_publinator_sections.rb
|
@@ -319,7 +317,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
319
317
|
version: '0'
|
320
318
|
segments:
|
321
319
|
- 0
|
322
|
-
hash:
|
320
|
+
hash: -1778146319537863038
|
323
321
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
324
322
|
none: false
|
325
323
|
requirements:
|
@@ -328,7 +326,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
328
326
|
version: '0'
|
329
327
|
segments:
|
330
328
|
- 0
|
331
|
-
hash:
|
329
|
+
hash: -1778146319537863038
|
332
330
|
requirements: []
|
333
331
|
rubyforge_project:
|
334
332
|
rubygems_version: 1.8.24
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Publinator
|
2
|
-
class Publishable < ActiveRecord::Base
|
3
|
-
has_one :publication, :as => :publishable, :class_name => "Publinator::Publication"
|
4
|
-
|
5
|
-
accepts_nested_attributes_for :publication
|
6
|
-
attr_accessible :site_id, :section_id, :custom_slug
|
7
|
-
attr_accessor :site_id, :section_id, :custom_slug
|
8
|
-
|
9
|
-
validates_presence_of :publication
|
10
|
-
validates_associated :publication
|
11
|
-
|
12
|
-
before_validation :prepare_publication
|
13
|
-
|
14
|
-
def editable_fields
|
15
|
-
attribute_names - ["id", "created_at", "updated_at"]
|
16
|
-
end
|
17
|
-
|
18
|
-
def section_id=(section_int)
|
19
|
-
@section = Section.find(section_int)
|
20
|
-
add_publication if publication.nil?
|
21
|
-
self.publication.section_id = @section.id if @section
|
22
|
-
self.publication.site_id = @section.site.id if @section.site
|
23
|
-
end
|
24
|
-
|
25
|
-
def section_id
|
26
|
-
publication.section_id if publication
|
27
|
-
end
|
28
|
-
|
29
|
-
def site_id=(site_int)
|
30
|
-
@site = Site.find(site_int)
|
31
|
-
add_publication if publication.nil?
|
32
|
-
self.publication.site_id = @site.id if @site
|
33
|
-
end
|
34
|
-
|
35
|
-
def site_id
|
36
|
-
publication.site_id if publication
|
37
|
-
end
|
38
|
-
|
39
|
-
def prepare_publication
|
40
|
-
logger.info "preparing publication"
|
41
|
-
my_name = self.class.to_s
|
42
|
-
logger.info "My name is #{my_name}"
|
43
|
-
add_publication if publication.nil?
|
44
|
-
publication.generate_slug
|
45
|
-
publication.publishable_type = my_name
|
46
|
-
end
|
47
|
-
|
48
|
-
def custom_slug=(slug_string)
|
49
|
-
add_publication if publication.nil?
|
50
|
-
publication.custom_slug = slug_string
|
51
|
-
end
|
52
|
-
|
53
|
-
def custom_slug
|
54
|
-
publication.custom_slug unless publication.nil?
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def add_publication
|
60
|
-
logger.info "creating publication"
|
61
|
-
self.publication = Publinator::Publication.new(:publishable => self)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|