publinator 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ module Publinator
4
4
  class PublishableController < Publinator::ApplicationController
5
5
  def index
6
6
  @publication = Publinator::Publication.find_by_publishable_type_and_slug(params[:publishable_type].classify, 'index')
7
+ @publishable_type = Publinator::PublishableType.find_by_name(params[:publishable_type].classify)
7
8
  if @publication
8
9
  @publishable = @publication.publishable
9
10
  begin
@@ -24,8 +25,9 @@ module Publinator
24
25
  def show
25
26
  @publication = Publinator::Publication.find_by_publishable_type_and_slug(params[:publishable_type].classify, params[:id])
26
27
  @publishable = @publication.publishable
28
+ @publishable_type = Publinator::PublishableType.find_by_name(params[:publishable_type].classify)
27
29
  begin
28
- render "#{params[:publishable_type]}/index"
30
+ render "#{params[:publishable_type]}/show"
29
31
  rescue ActionView::MissingTemplate
30
32
  render "publinator/publishable/show"
31
33
  end
@@ -7,7 +7,10 @@ module Publinator
7
7
  def index
8
8
  @publication = Publinator::Publication.find_by_section_id_and_slug(@section.id, 'index')
9
9
  @publishable = @publication.publishable
10
+ @publishable_type = Publinator::PublishableType.find_by_name(@publication.publishable_type.classify)
10
11
  begin
12
+ render "#{@publishable_type.tableize}/index"
13
+ rescue ActionView::MissingTemplate
11
14
  render "#{params[:section]}/index"
12
15
  rescue ActionView::MissingTemplate
13
16
  render "publinator/publishable/show"
@@ -17,7 +20,14 @@ module Publinator
17
20
  def show
18
21
  @publication = Publinator::Publication.find(:first, :conditions => ["section_id = ? and slug = ?", @section.id, params[:id]])
19
22
  @publishable = @publication.publishable
23
+ @publishable_type = Publinator::PublishableType.find_by_name(@publication.publishable_type.classify)
20
24
  begin
25
+ if @publishable_type
26
+ render "#{@publishable_type.tableize}/show"
27
+ else
28
+ render "#{params[:section]}/#{@publication.slug}"
29
+ end
30
+ rescue ActionView::MissingTemplate
21
31
  render "#{params[:section]}/show"
22
32
  rescue ActionView::MissingTemplate
23
33
  render "publinator/publishable/show"
@@ -27,11 +27,11 @@ module Publinator
27
27
  end
28
28
  if request_domain.present?
29
29
  if request_subdomain.blank? || request_subdomain == 'www'
30
- @domain = self.find(:first, :conditions => ["name = ? AND (subdomain is null or subdomain = '')", request_domain])
30
+ @domain = self.find(:first, :conditions => ["name = ? AND (subdomain is null or subdomain = '')", request_domain.downcase])
31
31
  elsif request_subdomain.present? && request_subdomain != 'www'
32
- @domain = self.find(:first, :conditions => ["name = ? AND subdomain = ?", request_domain, request_subdomain])
32
+ @domain = self.find(:first, :conditions => ["name = ? AND subdomain = ?", request_domain.downcase, request_subdomain.downcase])
33
33
  else
34
- @domain = self.find(:first, :conditions => ["name = ? AND subdomain = 'www' AND anchor = ?", request_domain, true])
34
+ @domain = self.find(:first, :conditions => ["name = ? AND subdomain = 'www' AND anchor = ?", request_domain.downcase, true])
35
35
  end
36
36
  else
37
37
  @domain = Site.default.domain_names.detect { |d| d.default }
@@ -1,6 +1,6 @@
1
1
  module Publinator
2
2
  class PublishableType < ActiveRecord::Base
3
- attr_accessible :name, :sluggable, :layout
3
+ attr_accessible :name, :sluggable, :layout, :use_layout
4
4
 
5
5
  def self.matches?(request)
6
6
  pt = self.find_by_name(request.path_parameters[:publishable_type].singularize.capitalize)
@@ -4,6 +4,7 @@ class CreatePublinatorPublishableTypes < ActiveRecord::Migration
4
4
  t.string :name
5
5
  t.boolean :sluggable, :default => true
6
6
  t.boolean :layout, :default => false
7
+ t.string :use_layout
7
8
  t.timestamps
8
9
  end
9
10
  end
@@ -1,12 +1,12 @@
1
1
  class PublishableGenerator < Rails::Generators::NamedBase
2
2
  source_root File.expand_path('../templates', __FILE__)
3
- argument :class_name, :type => :string, :default => "article"
3
+ # argument :class_name, :type => :string, :default => "article"
4
4
 
5
5
  def create_publishable_initializer
6
6
  # create file for class
7
- template "app/models/publishable_model.rb.erb", "app/models/#{file_name}.rb"
7
+ template "app/models/publishable_model.rb.erb", "app/models/#{name.underscore}.rb"
8
8
 
9
9
  # create migration
10
- template "app/models/publishable_migration.rb.erb", "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S").to_i}_create_#{class_name.pluralize}.rb"
10
+ template "app/models/publishable_migration.rb.erb", "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S").to_i}_create_#{ActiveSupport::Inflector.tableize(name)}.rb"
11
11
  end
12
12
  end
@@ -1,10 +1,10 @@
1
- class Create<%= class_name.capitalize %> < ActiveRecord::Migration
1
+ class Create<%= name.classify.pluralize %> < ActiveRecord::Migration
2
2
  def self.up
3
- create_table :<%= class_name.pluralize.to_sym %> do |t|
3
+ create_table :<%= ActiveSupport::Inflector.tableize(name) %> do |t|
4
4
  t.string :title
5
- t.string :teaser
6
5
  t.text :body
7
6
  t.integer :site_id
7
+ t.integer :position
8
8
 
9
9
  # t.string :author_name
10
10
  # t.text :extra_body
@@ -13,10 +13,10 @@ class Create<%= class_name.capitalize %> < ActiveRecord::Migration
13
13
  t.timestamps
14
14
  end
15
15
 
16
- Publinator::PublishableType.new(:name => "<%= class_name %>", :sluggable => "true")
16
+ Publinator::PublishableType.create!(:name => "<%= name.classify %>", :sluggable => "true")
17
17
  end
18
18
 
19
19
  def self.down
20
- drop_table :<%= class_name.pluralize.to_sym %>
20
+ drop_table :<%= ActiveSupport::Inflector.tableize(name) %>
21
21
  end
22
22
  end
@@ -1,5 +1,5 @@
1
- class <%= class_name.capitalize %> < ActiveRecord::Base
2
- self.table_name = '<%= class_name.downcase.pluralize %>'
1
+ class <%= name.classify %> < ActiveRecord::Base
2
+ self.table_name = '<%= name.tableize %>'
3
3
  acts_as_publishable
4
- attr_accessible :title, :body, :section
5
- end
4
+ attr_accessible :title, :body, :position, :site
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Publinator
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.20"
3
3
  end
data/lib/publinator.rb CHANGED
@@ -9,7 +9,8 @@ module Publinator
9
9
  has_one :publication,
10
10
  :as => :publishable,
11
11
  :class_name => "Publinator::Publication",
12
- :foreign_key => :publishable_id
12
+ :foreign_key => :publishable_id,
13
+ :dependent => :destroy
13
14
 
14
15
  accepts_nested_attributes_for :publication
15
16
  validates_presence_of :publication
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.19
4
+ version: 0.0.20
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -352,7 +352,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
352
352
  version: '0'
353
353
  segments:
354
354
  - 0
355
- hash: 2863941966361980414
355
+ hash: -1771471465118943363
356
356
  required_rubygems_version: !ruby/object:Gem::Requirement
357
357
  none: false
358
358
  requirements:
@@ -361,7 +361,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
361
361
  version: '0'
362
362
  segments:
363
363
  - 0
364
- hash: 2863941966361980414
364
+ hash: -1771471465118943363
365
365
  requirements: []
366
366
  rubyforge_project:
367
367
  rubygems_version: 1.8.24