publinator 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -1
- data/app/assets/javascripts/publinator/manage/sections.js +2 -0
- data/app/assets/stylesheets/publinator/manage/sections.css +4 -0
- data/app/controllers/publinator/application_controller.rb +5 -5
- data/app/controllers/publinator/home_controller.rb +4 -4
- data/app/controllers/publinator/manage/publishable_controller.rb +14 -10
- data/app/controllers/publinator/manage/sections_controller.rb +29 -0
- data/app/controllers/publinator/publishable_controller.rb +3 -3
- data/app/controllers/publinator/section_controller.rb +36 -0
- data/app/helpers/publinator/manage/sections_helper.rb +4 -0
- data/app/models/publinator/domain_name.rb +13 -0
- data/app/models/publinator/page.rb +7 -0
- data/app/models/publinator/publication.rb +19 -16
- data/app/models/publinator/publishable.rb +52 -11
- data/app/models/publinator/publishable_type.rb +1 -1
- data/app/models/publinator/section.rb +25 -0
- data/app/models/publinator/site.rb +5 -4
- data/app/views/publinator/home/index.html.erb +1 -1
- data/app/views/publinator/manage/publishable/_form.html.erb +4 -1
- data/app/views/publinator/manage/sections/_form.html.erb +10 -0
- data/app/views/publinator/manage/sections/edit.html.erb +3 -0
- data/app/views/publinator/manage/sections/index.html.erb +16 -0
- data/app/views/publinator/manage/sections/new.html.erb +3 -0
- data/app/views/publinator/manage/sections/show.html.erb +2 -0
- data/config/routes.rb +41 -25
- data/db/migrate/20121011191348_create_publinator_sections.rb +13 -0
- data/db/migrate/20121017134533_create_publinator_pages.rb +14 -0
- data/lib/generators/publishable/publishable_generator.rb +1 -1
- data/lib/generators/publishable/templates/app/models/publishable_migration.rb.erb +5 -3
- data/lib/publinator/engine.rb +1 -0
- data/lib/publinator/version.rb +1 -1
- metadata +68 -228
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/models/article.rb +0 -5
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config/application.rb +0 -56
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -37
- data/test/dummy/config/environments/production.rb +0 -67
- data/test/dummy/config/environments/test.rb +0 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -3
- data/test/dummy/config.ru +0 -4
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20120725204706_create_publinator_sites.publinator.rb +0 -17
- data/test/dummy/db/migrate/20120725204707_create_publinator_domain_names.publinator.rb +0 -14
- data/test/dummy/db/migrate/20120725204708_create_publinator_publications.publinator.rb +0 -16
- data/test/dummy/db/migrate/20120725204709_create_publinator_publication_states.publinator.rb +0 -10
- data/test/dummy/db/migrate/20120725204710_create_publinator_workflows.publinator.rb +0 -10
- data/test/dummy/db/migrate/20120725204711_create_publinator_workflow_steps.publinator.rb +0 -15
- data/test/dummy/db/migrate/20120725204712_create_publinator_site_workflows.publinator.rb +0 -12
- data/test/dummy/db/migrate/20120725204713_create_publinator_publishables.publinator.rb +0 -10
- data/test/dummy/db/migrate/20120727005853_create_versions.publinator.rb +0 -19
- data/test/dummy/db/migrate/20120727005854_create_publinator_publishable_types.publinator.rb +0 -10
- data/test/dummy/db/migrate/20120824145846_create_articles.rb +0 -19
- data/test/dummy/db/schema.rb +0 -113
- data/test/dummy/db/seeds.rb +0 -39
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/features/multiple_home_pages.feature +0 -14
- data/test/dummy/log/development.log +0 -40231
- data/test/dummy/log/test.log +0 -7
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/dummy/tmp/cache/assets/C4F/360/sprockets%2F8f1f223e5a170f82017965822b6f7430 +0 -0
- data/test/dummy/tmp/cache/assets/C50/CE0/sprockets%2F76132a75085ce5f547460e8535ca5340 +0 -0
- data/test/dummy/tmp/cache/assets/C63/990/sprockets%2F11618b29357ca8c1c450722c20c91a00 +0 -0
- data/test/dummy/tmp/cache/assets/C72/990/sprockets%2F8be9281634a42c7a01308b333b17737b +0 -0
- data/test/dummy/tmp/cache/assets/C85/060/sprockets%2F95985a6ff38f2781686e6429e569778b +0 -0
- data/test/dummy/tmp/cache/assets/CA9/470/sprockets%2F0407014b0507e7755ef657d61f712ebc +0 -0
- data/test/dummy/tmp/cache/assets/CC0/FC0/sprockets%2F3c56105da246486092d2bbe0a4a0d033 +0 -0
- data/test/dummy/tmp/cache/assets/CC2/7B0/sprockets%2Fc4c32d2ab19d396689f357ef76364436 +0 -0
- data/test/dummy/tmp/cache/assets/CDE/040/sprockets%2Fba0451e56a8d59da297777a7280ab063 +0 -0
- data/test/dummy/tmp/cache/assets/D03/310/sprockets%2F525cf5b3d9e3504ba06702b64e0c681e +0 -0
- data/test/dummy/tmp/cache/assets/D08/DE0/sprockets%2Ff4a1d4922a38c27425da2e144e59c6d3 +0 -0
- data/test/dummy/tmp/cache/assets/D0B/2F0/sprockets%2Ff8b70628b691a6a3ecb709217a326a8b +0 -0
- data/test/dummy/tmp/cache/assets/D0C/310/sprockets%2Ffadeb95307575f00dda19890ec423415 +0 -0
- data/test/dummy/tmp/cache/assets/D12/780/sprockets%2F89400fbaf52d569e932128a538e6bf0a +0 -0
- data/test/dummy/tmp/cache/assets/D13/710/sprockets%2Fa59760c5818192f8007fec314febb7b3 +0 -0
- data/test/dummy/tmp/cache/assets/D17/C20/sprockets%2F706c0f4966a7c7fdd66a074d94a57d11 +0 -0
- data/test/dummy/tmp/cache/assets/D32/E40/sprockets%2F7ced78249d4c98d883ae91f492668a6b +0 -0
- data/test/dummy/tmp/cache/assets/D34/C20/sprockets%2Fed4da822bde7632ba05dae4472824813 +0 -0
- data/test/dummy/tmp/cache/assets/D39/EA0/sprockets%2F81ec8f71e453a02b8c9a40157afe0f71 +0 -0
- data/test/dummy/tmp/cache/assets/D3A/FA0/sprockets%2F6d1270d85395029a2c06c5c2eb4dece8 +0 -0
- data/test/dummy/tmp/cache/assets/D3B/EA0/sprockets%2F539fc0d8da407130f2f1f2bf088b85d3 +0 -0
- data/test/dummy/tmp/cache/assets/D42/9F0/sprockets%2F5eca1a27a78455737f92e6af1ade0448 +0 -0
- data/test/dummy/tmp/cache/assets/D42/B60/sprockets%2Fac22072df4e4aeae78d396f60468d227 +0 -0
- data/test/dummy/tmp/cache/assets/D42/DE0/sprockets%2Faadf8c86a222ee8e83d2821583ea0593 +0 -0
- data/test/dummy/tmp/cache/assets/D43/F50/sprockets%2Fc5e61a881bfc3b9e25f72694535ec40a +0 -0
- data/test/dummy/tmp/cache/assets/D4D/390/sprockets%2Ffe227bf86af573e51927e4d2e7436c4c +0 -0
- data/test/dummy/tmp/cache/assets/D5E/540/sprockets%2F00723322beecdc3eea7481c3ca15683f +0 -0
- data/test/dummy/tmp/cache/assets/D61/700/sprockets%2Ff5caf7e7779724575d9ad98e18e9c1e0 +0 -0
- data/test/dummy/tmp/cache/assets/D64/970/sprockets%2Fc82da8e1a6ea89aa065031be36b2c576 +0 -0
- data/test/dummy/tmp/cache/assets/D68/2E0/sprockets%2F0c4374b9e9b2aaaaa263b17b9a77f088 +0 -0
- data/test/dummy/tmp/cache/assets/D6C/C50/sprockets%2F712fd91829ab4f5c53bb6fa3b3d245a9 +0 -0
- data/test/dummy/tmp/cache/assets/D70/C60/sprockets%2Fca98bff3da133a465c5b4748a3b38f37 +0 -0
- data/test/dummy/tmp/cache/assets/D7B/730/sprockets%2Fa90b20db3a5c66c85d7986f4d91c9eb6 +0 -0
- data/test/dummy/tmp/cache/assets/D81/D70/sprockets%2F6a010131cebe8c0543864eba3cc3fdb0 +0 -0
- data/test/dummy/tmp/cache/assets/DA4/020/sprockets%2Fb7f430f48a4573d8975b2fb4b2ba5def +0 -0
- data/test/dummy/tmp/cache/assets/DA6/300/sprockets%2Fb8cef7a3ac9c4221e9c5bc582c86e149 +0 -0
- data/test/dummy/tmp/cache/assets/DAA/5B0/sprockets%2F9ac396884b5f7f4085dbfbf1f3bd82b0 +0 -0
- data/test/dummy/tmp/cache/assets/DAB/000/sprockets%2F3c9acfeb145fc77ef7932bc7b498a118 +0 -0
- data/test/dummy/tmp/cache/assets/DD7/DB0/sprockets%2F2e3dee6c113e8b9d5c3ffd508ea3e829 +0 -0
- data/test/dummy/tmp/cache/assets/DDC/610/sprockets%2Fb7e49f851b32a93fa0af9cf7be9fc283 +0 -0
- data/test/dummy/tmp/cache/assets/E08/B70/sprockets%2F682afca4b65d8e03784ff5da7fae4e6a +0 -0
- data/test/dummy/tmp/cache/assets/E38/BE0/sprockets%2Ffb2fafc55f60fd5d9a99e12a0fc53f9d +0 -0
- data/test/dummy/tmp/restart.txt +0 -0
- data/test/fixtures/publinator/publication_states.yml +0 -7
- data/test/fixtures/publinator/publications.yml +0 -19
- data/test/fixtures/publinator/publishable_types.yml +0 -7
- data/test/fixtures/publinator/publishables.yml +0 -7
- data/test/fixtures/publinator/site_workflows.yml +0 -11
- data/test/fixtures/publinator/workflow_steps.yml +0 -17
- data/test/fixtures/publinator/workflows.yml +0 -7
- data/test/functional/publinator/home_controller_test.rb +0 -16
- data/test/integration/navigation_test.rb +0 -10
- data/test/publinator_test.rb +0 -7
- data/test/test_helper.rb +0 -10
- data/test/unit/helpers/publinator/home_helper_test.rb +0 -6
- data/test/unit/publinator/domain_name_test.rb +0 -9
- data/test/unit/publinator/publication_state_test.rb +0 -9
- data/test/unit/publinator/publication_test.rb +0 -9
- data/test/unit/publinator/publishable_test.rb +0 -9
- data/test/unit/publinator/publishable_type_test.rb +0 -9
- data/test/unit/publinator/site_test.rb +0 -9
- data/test/unit/publinator/site_workflow_test.rb +0 -9
- data/test/unit/publinator/workflow_step_test.rb +0 -9
- data/test/unit/publinator/workflow_test.rb +0 -9
data/README.rdoc
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
module Publinator
|
2
2
|
class ApplicationController < ActionController::Base
|
3
3
|
layout :current_layout
|
4
|
-
|
4
|
+
|
5
5
|
helper_method :current_site, :current_domain, :current_layout, :current_site_name
|
6
|
-
|
6
|
+
|
7
7
|
def current_site_name
|
8
8
|
return "Publinator" if current_site.nil?
|
9
9
|
@current_site_name ||= current_site.name
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def current_site
|
13
13
|
return nil if current_domain.nil?
|
14
14
|
@current_site ||= current_domain.site
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def current_domain
|
18
18
|
@current_domain ||= DomainName.get_by_domain_name(request)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def current_layout
|
22
22
|
if current_site.nil?
|
23
23
|
"publinator/publinator"
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require_dependency "publinator/application_controller"
|
2
2
|
|
3
3
|
module Publinator
|
4
|
-
class HomeController < ApplicationController
|
4
|
+
class HomeController < Publinator::ApplicationController
|
5
5
|
def index
|
6
6
|
begin
|
7
7
|
render "home/index"
|
8
8
|
rescue ActionView::MissingTemplate
|
9
|
-
render "publinator/home/index"
|
10
|
-
end
|
9
|
+
render "publinator/home/index", :layout => current_layout
|
10
|
+
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def page
|
14
14
|
@publication = Publinator::Publication.get_by_slug(params[:slug])
|
15
15
|
if @publication.nil?
|
@@ -3,16 +3,16 @@ require_dependency "publinator/application_controller"
|
|
3
3
|
module Publinator
|
4
4
|
class Manage::PublishableController < ApplicationController
|
5
5
|
layout "publinator/manage"
|
6
|
-
|
6
|
+
|
7
7
|
def index
|
8
8
|
@publishables = Publinator::Publication.for_site(current_site.id).where(:publishable_type => params["publishable_type"].singularize.capitalize).order("updated_at desc")
|
9
9
|
begin
|
10
|
-
render "
|
10
|
+
render "manage/#{params[:publishable_type]}/index"
|
11
11
|
rescue ActionView::MissingTemplate
|
12
12
|
render "publinator/manage/publishable/index"
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def show
|
17
17
|
@publication = Publinator::Publication.find_by_publishable_type_and_slug(params[:publishable_type].singularize.capitalize, params[:id])
|
18
18
|
@publishable = @publication.publishable_type.singularize.capitalize.constantize.send(:find, @publication.publishable_id)
|
@@ -22,23 +22,26 @@ module Publinator
|
|
22
22
|
render "publinator/manage/publishable/show"
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def new
|
27
|
+
publishable_class = params['publishable_type'].singularize.capitalize.constantize
|
27
28
|
#@publication = Publinator::Publication.find_by_publishable_type_and_publishable_id(params[:publishable_type].singularize.capitalize, params[:id])
|
28
|
-
@publishable =
|
29
|
+
@publishable = publishable_class.send(:new, {
|
29
30
|
:publication => Publinator::Publication.new(
|
30
31
|
:publish_at => 1.day.from_now.beginning_of_day + 8.hours,
|
31
32
|
:archive_at => 31.days.from_now.beginning_of_day,
|
32
|
-
:site_id => current_site.id
|
33
|
+
:site_id => current_site.id,
|
34
|
+
:publishable_type => params['publishable_type'].singularize.capitalize
|
33
35
|
)
|
34
36
|
})
|
37
|
+
@field_names = (publishable_class.attribute_names - ["id", "created_at", "updated_at"]).collect{ |an| an.to_sym }
|
35
38
|
begin
|
36
39
|
render "#{params[:publishable_type]}/new"
|
37
40
|
rescue ActionView::MissingTemplate
|
38
41
|
render "publinator/manage/publishable/new"
|
39
42
|
end
|
40
43
|
end
|
41
|
-
|
44
|
+
|
42
45
|
def edit
|
43
46
|
@publication = Publinator::Publication.find_by_publishable_type_and_slug(params[:publishable_type].singularize.capitalize, params[:id])
|
44
47
|
@publishable = @publication.publishable_type.singularize.capitalize.constantize.send(:find, @publication.publishable_id)
|
@@ -46,18 +49,19 @@ module Publinator
|
|
46
49
|
render "#{params[:publishable_type]}/edit"
|
47
50
|
rescue ActionView::MissingTemplate
|
48
51
|
render "publinator/manage/publishable/edit"
|
49
|
-
end
|
52
|
+
end
|
50
53
|
end
|
51
|
-
|
54
|
+
|
52
55
|
def create
|
53
56
|
@publishable_type = PublishableType.find_by_name(params['publishable_type'].singularize.capitalize)
|
54
57
|
@publishable_class = @publishable_type.name.capitalize.constantize
|
55
58
|
publishable_params = params[@publishable_type.name.downcase.to_sym]
|
56
59
|
publication_params = publishable_params.delete('publication').merge({ :site_id => current_site.id, :publishable_type => @publishable_type.name.capitalize })
|
60
|
+
publication_params.merge({:section_id => publishable_params[:section_id]}) if publishable_params[:section_id]
|
57
61
|
@publication = Publinator::Publication.create!(publication_params)
|
58
62
|
@publishable = @publishable_type.name.capitalize.constantize.send(:new, publishable_params, :publication => @publication)
|
59
63
|
|
60
|
-
if @publishable.save
|
64
|
+
if @publishable.save
|
61
65
|
@publication.publishable_id = @publishable.id
|
62
66
|
@publication.save
|
63
67
|
redirect_to "/manage/#{params[:publishable_type]}", :notice => "#{@publishable_type.name} created."
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_dependency "publinator/application_controller"
|
2
|
+
|
3
|
+
module Publinator
|
4
|
+
class Manage::SectionsController < ApplicationController
|
5
|
+
|
6
|
+
before_filter :get_section, :except => [:index, :new]
|
7
|
+
|
8
|
+
def index
|
9
|
+
@sections = current_site.sections
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
end
|
14
|
+
|
15
|
+
def edit
|
16
|
+
end
|
17
|
+
|
18
|
+
def new
|
19
|
+
@section = Section.new(:site_id => current_site.id)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_section
|
25
|
+
@section = current_site.sections.find_by_id(params[:id])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require_dependency "publinator/application_controller"
|
2
2
|
|
3
3
|
module Publinator
|
4
|
-
class PublishableController < ApplicationController
|
4
|
+
class PublishableController < Publinator::ApplicationController
|
5
5
|
def index
|
6
6
|
@publishables = current_site.publications('published', 'updated_at desc', params["publishable_type"].singularize.capitalize)
|
7
7
|
begin
|
@@ -10,9 +10,9 @@ module Publinator
|
|
10
10
|
render "publinator/publishable/index"
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def show
|
15
|
-
@publication = Publinator::Publication.
|
15
|
+
@publication = Publinator::Publication.find_by_publishable_type_and_slug(params[:publishable_type].singularize.capitalize, params[:id])
|
16
16
|
@publishable = @publication.publishable
|
17
17
|
begin
|
18
18
|
render "#{params[:publishable_type]}/index"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_dependency "publinator/application_controller"
|
2
|
+
|
3
|
+
module Publinator
|
4
|
+
class SectionController < ApplicationController
|
5
|
+
before_filter :get_section
|
6
|
+
|
7
|
+
def index
|
8
|
+
@publication = Publinator::Publication.find_by_section_id_and_slug(@section.id, 'index')
|
9
|
+
@publishable = @publication.publishable
|
10
|
+
begin
|
11
|
+
render "#{params[:section]}/index"
|
12
|
+
rescue ActionView::MissingTemplate
|
13
|
+
render "publinator/publishable/show"
|
14
|
+
end
|
15
|
+
rescue Exception => e
|
16
|
+
logger.info e.to_yaml
|
17
|
+
# redirect_to root_url, :notice => "Page not found." if @publication.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
@publication = Publinator::Publication.find(:first, :conditions => ["section_id = ? and slug = ?", @section.id, params[:id]])
|
22
|
+
@publishable = @publication.publishable
|
23
|
+
begin
|
24
|
+
render "#{params[:section]}/show"
|
25
|
+
rescue ActionView::MissingTemplate
|
26
|
+
render "publinator/publishable/show"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def get_section
|
33
|
+
@section = Publinator::Section.find(:first, :conditions => ["site_id = ? AND name = ?", current_site.id, params[:section]])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -10,7 +10,14 @@ module Publinator
|
|
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
|
+
|
13
19
|
if request.env['x-forwarded-for']
|
20
|
+
logger.info "processing forwarded request..."
|
14
21
|
origin = request.env['x-forwarded-for'].to_s
|
15
22
|
domain_array = origin.split('.')
|
16
23
|
domain_array_length = origin.length
|
@@ -22,20 +29,26 @@ module Publinator
|
|
22
29
|
request_domain = "#{domain_array[domain_array_length - 2]}.#{domain_array[domain_array_length - 1]}"
|
23
30
|
end
|
24
31
|
else
|
32
|
+
logger.info "processing direct request..."
|
25
33
|
request_subdomain = request.subdomain
|
26
34
|
request_domain = request.domain
|
27
35
|
end
|
28
36
|
if request_domain.present?
|
37
|
+
logger.info "request_domain is #{request_domain}..."
|
29
38
|
if request_subdomain.blank? || request_subdomain == 'www'
|
39
|
+
logger.info "request_subdomain is #{request_subdomain}..."
|
30
40
|
@domain = self.find(:first, :conditions => ["name = ? AND (subdomain is null or subdomain = '')", request_domain])
|
31
41
|
elsif request_subdomain.present? && request_subdomain != 'www'
|
42
|
+
logger.info "non-www request_subdomain is #{request_subdomain}..."
|
32
43
|
@domain = self.find(:first, :conditions => ["name = ? AND subdomain = ?", request_domain, request_subdomain])
|
33
44
|
else
|
34
45
|
@domain = self.find(:first, :conditions => ["name = ? AND subdomain = 'www' AND anchor = ?", request_domain, true])
|
35
46
|
end
|
36
47
|
else
|
48
|
+
logger.info "request_domain was not found. finding default site..."
|
37
49
|
@domain = Site.default.domain_names.detect { |d| d.default }
|
38
50
|
end
|
51
|
+
logger.info @domain.to_yaml
|
39
52
|
return @domain
|
40
53
|
end
|
41
54
|
end
|
@@ -1,34 +1,37 @@
|
|
1
1
|
module Publinator
|
2
2
|
class Publication < ActiveRecord::Base
|
3
3
|
# has_paper_trail
|
4
|
-
attr_accessible :custom_slug, :parent_id, :publication_state_id,
|
4
|
+
attr_accessible :custom_slug, :parent_id, :publication_state_id,
|
5
5
|
:publishable_id, :publishable_type, :site_id, :slug, :publish_at,
|
6
|
-
:unpublish_at, :archive_at
|
6
|
+
:unpublish_at, :archive_at, :section_id, :default, :publishable
|
7
7
|
belongs_to :publishable, :polymorphic => true
|
8
|
+
belongs_to :section
|
8
9
|
belongs_to :site
|
9
|
-
|
10
|
+
|
10
11
|
validates_uniqueness_of :custom_slug, :scope => :site_id, :allow_blank => true
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
validates_presence_of :slug
|
13
|
+
validates_uniqueness_of :slug, :scope => [:site_id, :publishable_type, :section_id]
|
14
|
+
validates_presence_of :site_id
|
14
15
|
|
16
|
+
before_validation :generate_slug
|
17
|
+
|
15
18
|
scope :published, where(:publication_state_id => 1)
|
16
19
|
scope :for_site, lambda { |site_id| where("site_id = ?", site_id) }
|
17
|
-
|
18
|
-
before_validation :generate_slug
|
19
|
-
|
20
|
+
|
20
21
|
def generate_slug
|
21
|
-
if
|
22
|
-
if
|
23
|
-
self.slug =
|
24
|
-
elsif publishable.present?
|
25
|
-
self.slug = title.
|
22
|
+
if slug.blank? || slug == "temporary_slug"
|
23
|
+
if custom_slug.present?
|
24
|
+
self.slug = custom_slug
|
25
|
+
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'
|
26
29
|
else
|
27
|
-
self.slug = "
|
30
|
+
self.slug = "temporary_slug"
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
31
|
-
|
34
|
+
|
32
35
|
def self.get_by_slug(slug)
|
33
36
|
self.published.where(:slug => slug)
|
34
37
|
end
|
@@ -1,23 +1,64 @@
|
|
1
1
|
module Publinator
|
2
2
|
class Publishable < ActiveRecord::Base
|
3
|
-
|
4
|
-
|
5
|
-
has_one :publication, :class_name => 'Publinator::Publication'
|
3
|
+
has_one :publication, :as => :publishable, :class_name => "Publinator::Publication"
|
4
|
+
|
6
5
|
accepts_nested_attributes_for :publication
|
7
|
-
|
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
|
8
11
|
|
12
|
+
before_validation :prepare_publication
|
13
|
+
|
9
14
|
def editable_fields
|
10
|
-
attribute_names - ["id", "created_at", "updated_at"]
|
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
|
11
37
|
end
|
12
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
|
13
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
|
14
56
|
|
57
|
+
private
|
15
58
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# end
|
21
|
-
# end
|
59
|
+
def add_publication
|
60
|
+
logger.info "creating publication"
|
61
|
+
self.publication = Publinator::Publication.new(:publishable => self)
|
62
|
+
end
|
22
63
|
end
|
23
64
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# TODO Validate new sections - can't conflict with publishable_types
|
2
|
+
module Publinator
|
3
|
+
class Section < ActiveRecord::Base
|
4
|
+
attr_accessible :layout, :name, :parent_id, :site_id
|
5
|
+
belongs_to :site
|
6
|
+
has_many :publications
|
7
|
+
before_create :generate_slug
|
8
|
+
|
9
|
+
def self.matches?(request)
|
10
|
+
pt = self.find(:first, :conditions => ["slug = ?", request.path_parameters[:section]])
|
11
|
+
return pt.present?
|
12
|
+
end
|
13
|
+
|
14
|
+
# current_site.id, params[:section]
|
15
|
+
def self.get_by_site_id_and_slug(site_id, section_name)
|
16
|
+
Section.find(:first, :conditions => ["site_id = ? and name = ?", site_id, section_name])
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def generate_slug
|
22
|
+
self.slug = name.downcase.gsub(" ", "_")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -2,9 +2,10 @@ module Publinator
|
|
2
2
|
class Site < ActiveRecord::Base
|
3
3
|
attr_accessible :abbr, :description, :name, :parent_id, :state, :title, :default
|
4
4
|
has_many :domain_names
|
5
|
-
|
5
|
+
has_many :sections
|
6
|
+
|
6
7
|
# get the layout for the site
|
7
|
-
#
|
8
|
+
#
|
8
9
|
# @todo add ability to use a custom layout
|
9
10
|
def layout
|
10
11
|
begin
|
@@ -13,12 +14,12 @@ module Publinator
|
|
13
14
|
"publinator/site"
|
14
15
|
end
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
def parent
|
18
19
|
return nil unless parent_id.present?
|
19
20
|
Site.find(self.parent_id)
|
20
21
|
end
|
21
|
-
|
22
|
+
|
22
23
|
def publications(scope = 'published', sort = 'updated_at desc', publishable_type)
|
23
24
|
if publishable_type.nil?
|
24
25
|
pubs = Publication.for_site(self.id).send(scope).order(sort)
|
@@ -1,2 +1,2 @@
|
|
1
1
|
<h1>Home Page</h1>
|
2
|
-
<p>Welcome to
|
2
|
+
<p>Welcome to <%= current_site.name %>!</p>
|
@@ -6,7 +6,9 @@
|
|
6
6
|
<% end %>
|
7
7
|
<% end %>
|
8
8
|
<%= form.inputs @publishable.class.to_s do %>
|
9
|
-
|
9
|
+
<% @field_names.each do |field| %>
|
10
|
+
<%= form.input field %>
|
11
|
+
<% end %>
|
10
12
|
<% end %>
|
11
13
|
<%= form.semantic_fields_for @publishable.publication do |pub| %>
|
12
14
|
<%= pub.inputs "Publication Settings" do %>
|
@@ -14,6 +16,7 @@
|
|
14
16
|
<%= pub.input :publish_at, :as => :datetime_select, :required => false %>
|
15
17
|
<%= pub.input :unpublish_at, :as => :datetime_select, :required => false %>
|
16
18
|
<%= pub.input :archive_at, :as => :datetime_select, :required => false %>
|
19
|
+
<%= pub.input :section_id, :as => :select, :required => false, :collection => current_site.sections unless current_site.sections.length == 0 %>
|
17
20
|
<% end %>
|
18
21
|
<% end %>
|
19
22
|
<%= form.actions do %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= semantic_form_for [:manage, @section], :method => :post do |form| %>
|
2
|
+
<%= form.inputs do %>
|
3
|
+
<%= form.input :name %>
|
4
|
+
<%= form.input :layout %>
|
5
|
+
<% end %>
|
6
|
+
<%= form.actions do %>
|
7
|
+
<%= form.action :submit, :as => :button %>
|
8
|
+
<%= form.action :cancel, :as => :link %>
|
9
|
+
<% end %>
|
10
|
+
<% end %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<h1>Manage Sections </h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<% @sections.each do |section| %>
|
5
|
+
<tr>
|
6
|
+
<td>
|
7
|
+
<%= section.name %>
|
8
|
+
</td>
|
9
|
+
<td>
|
10
|
+
<%= link_to 'edit', edit_manage_section_path(section) %>
|
11
|
+
</td>
|
12
|
+
</tr>
|
13
|
+
<% end %>
|
14
|
+
</table>
|
15
|
+
|
16
|
+
<%= link_to "Add Section", new_manage_section_path %>
|
data/config/routes.rb
CHANGED
@@ -1,52 +1,68 @@
|
|
1
1
|
Publinator::Engine.routes.draw do
|
2
|
-
|
3
|
-
|
4
|
-
root :to => "home#index"
|
5
2
|
|
6
|
-
|
7
|
-
|
3
|
+
root :to => "home#index"
|
4
|
+
match '/' => 'home#index'
|
5
|
+
|
8
6
|
namespace :manage do
|
9
7
|
match "/" => 'manage#index'
|
10
8
|
resources :sites
|
9
|
+
resources :sections
|
11
10
|
constraints(Publinator::PublishableType) do
|
12
11
|
match '/:publishable_type/' => "publishable#index", :requirements => {
|
13
|
-
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
12
|
+
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
14
13
|
}, :as => "publishables"
|
15
|
-
|
14
|
+
|
16
15
|
match '/:publishable_type/new' => "publishable#new", :requirements => {
|
17
|
-
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
16
|
+
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
18
17
|
}
|
19
|
-
|
18
|
+
|
20
19
|
match '/:publishable_type/create' => "publishable#create", :requirements => {
|
21
|
-
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
20
|
+
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
22
21
|
}, :as => "create_publishable"
|
23
|
-
|
22
|
+
|
24
23
|
match '/:publishable_type/:id/edit' => "publishable#edit", :requirements => {
|
25
|
-
:id => /\A\d*\z/i,
|
26
|
-
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
24
|
+
:id => /\A\d*\z/i,
|
25
|
+
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
27
26
|
}, :as => "edit_publishable"
|
28
|
-
|
27
|
+
|
29
28
|
match '/:publishable_type/:id' => "publishable#show", :requirements => {
|
30
|
-
:id => /\A\d*\z/i,
|
31
|
-
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
29
|
+
:id => /\A\d*\z/i,
|
30
|
+
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
32
31
|
}, :as => "publishable"
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
34
|
+
|
35
|
+
constraints(Publinator::Section) do
|
36
|
+
match '/:section/' => "section#index", :requirements => {
|
37
|
+
:section => /\A([a-zA-Z0-9]+[a-zA-Z0-9\-_]*)\z/i
|
38
|
+
}
|
39
|
+
|
40
|
+
match '/:section/:id' => "section#show", :requirements => {
|
41
|
+
:id => /\A\d*\z/i,
|
42
|
+
:section => /\A([a-zA-Z0-9]+[a-zA-Z0-9\-_]*)\z/i
|
43
|
+
}, :as => "publishable"
|
44
|
+
end
|
45
|
+
|
46
|
+
|
36
47
|
constraints(Publinator::PublishableType) do
|
37
48
|
match '/:publishable_type/' => "publishable#index", :requirements => {
|
38
|
-
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
49
|
+
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
39
50
|
}
|
40
|
-
|
51
|
+
|
41
52
|
match '/:publishable_type/:id' => "publishable#show", :requirements => {
|
42
|
-
:id => /\A\d*\z/i,
|
43
|
-
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
53
|
+
:id => /\A\d*\z/i,
|
54
|
+
:publishable_type => /\A([a-zA-Z]+[a-zA-Z_]*)\z/i
|
44
55
|
}, :as => "publishable"
|
45
|
-
|
46
56
|
end
|
47
|
-
|
48
|
-
match "/:slug", :controller => :
|
49
|
-
:
|
57
|
+
|
58
|
+
match "/:section/:slug", :controller => :sections, :action => :page, :requirements => {
|
59
|
+
:section => /\A([a-zA-Z0-9]+[a-zA-Z0-9\-_]*)\z/i,
|
60
|
+
:slug => /\A([a-zA-Z]+[a-zA-Z\-_]*)\z/i
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
match "/:slug", :controller => :home, :action => :page, :requirements => {
|
65
|
+
:slug => /\A([a-zA-Z]+[a-zA-Z\-_]*)\z/i
|
50
66
|
}
|
51
67
|
|
52
68
|
end
|