sunrise-posts 0.1.0

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.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = Sunrise Posts
2
+
3
+ == Install
4
+
5
+ rails generate sunrise:posts:install
6
+
7
+ rake db:migrate
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require File.join(File.dirname(__FILE__), 'lib', 'sunrise', 'posts', 'version')
6
+
7
+ desc 'Default: run unit tests.'
8
+ task :default => :test
9
+
10
+ desc 'Test the sunrise plugin.'
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = true
16
+ end
17
+
18
+ desc 'Generate documentation for the sunrise plugin.'
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'Sunrise Posts'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+ begin
28
+ require 'jeweler'
29
+ Jeweler::Tasks.new do |s|
30
+ s.name = "sunrise-posts"
31
+ s.version = Sunrise::Posts::VERSION.dup
32
+ s.summary = "Rails CMS"
33
+ s.description = "Sunrise is a Aimbulance CMS"
34
+ s.email = "galeta.igor@gmail.com"
35
+ s.homepage = "https://github.com/galetahub/sunrise-posts"
36
+ s.authors = ["Igor Galeta", "Pavlo Galeta"]
37
+ s.files = FileList["[A-Z]*", "{app,config,lib}/**/*"]
38
+ s.extra_rdoc_files = FileList["[A-Z]*"] - %w(Gemfile Rakefile)
39
+
40
+ s.add_dependency('sunrise')
41
+ end
42
+
43
+ Jeweler::GemcutterTasks.new
44
+ rescue LoadError
45
+ puts "Jeweler not available. Install it with: gem install jeweler"
46
+ end
@@ -0,0 +1,38 @@
1
+ class Manage::PostsController < Manage::BaseController
2
+ inherit_resources
3
+ defaults :route_prefix => 'manage'
4
+ actions :all, :except => [:show]
5
+ belongs_to :structure
6
+
7
+ load_and_authorize_resource :post, :through => :structure
8
+
9
+ before_filter :make_filter, :only => [:index]
10
+ cache_sweeper :post_sweeper, :only => [:create, :update, :destroy]
11
+
12
+ def create
13
+ create!{ manage_structure_posts_path(@structure.id) }
14
+ end
15
+
16
+ def update
17
+ update!{ manage_structure_posts_path(@structure.id) }
18
+ end
19
+
20
+ def destroy
21
+ destroy!{ manage_structure_posts_path(@structure.id) }
22
+ end
23
+
24
+ protected
25
+
26
+ def begin_of_association_chain
27
+ @structure
28
+ end
29
+
30
+ def collection
31
+ @posts = (@posts || end_of_association_chain).merge(@search.scoped).page(params[:page])
32
+ end
33
+
34
+ def make_filter
35
+ @search = Sunrise::ModelFilter.new(Post, :attributes=>[ :title, :kind ] )
36
+ @search.update_attributes(params[:search])
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ class PostSweeper < ActionController::Caching::Sweeper
2
+ observe Post
3
+
4
+ def after_create(item)
5
+ expire(item)
6
+ end
7
+
8
+ def after_update(item)
9
+ expire(item)
10
+ end
11
+
12
+ def after_destroy(item)
13
+ expire(item)
14
+ end
15
+
16
+ private
17
+
18
+ def expire(item=nil)
19
+ expire_fragment(%r{/posts})
20
+ StructureSweeper.sweep!
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ <%= manage_form_for @post, :url => @post.new_record? ? manage_structure_posts_path(@structure.id) : manage_structure_post_path(@structure.id, @post.id) do |f| %>
2
+ <div class="edit-cont">
3
+ <div class="inputs-bl">
4
+ <%= f.input :title, :input_html => { :class => "text name" } %>
5
+
6
+ <%= f.input :published_at %>
7
+
8
+ <%= f.ckeditor :content, :input_html => options_for_ckeditor(:width => 860) %>
9
+ </div>
10
+ </div>
11
+
12
+ <%= f.button :submit, :url => manage_structure_posts_path(@structure.id) %>
13
+ <% end %>
@@ -0,0 +1,29 @@
1
+ <div class="bot-bg">
2
+ <div class="filt-bl">
3
+ <%= link_to_function t('manage.model_filter.title'), "Manage.toggle_element('block_filter')", :class=>"dark-arr" %>
4
+
5
+ <%= cookie_content_tag(:div, :id=>"block_filter", :class=>"filt") do %>
6
+ <%= form_for @search, :as => :search, :url=>manage_structure_posts_path(@structure.id), :html=>{:method=>:get, :id=>"form_filter"} do |f| %>
7
+ <%= f.label :title, t('activerecord.attributes.post.title') %>
8
+ <%= f.text_field :title, :class=>"text" %>
9
+
10
+ <div class="buts">
11
+ <%= f.submit t('manage.model_filter.search'), :style=>"display:none;" %>
12
+ <%= link_to_function content_tag(:span, t('manage.model_filter.search')), "$('#form_filter').submit()", :class=>"gr" %>
13
+ <%= link_to t('manage.model_filter.clear'), manage_structure_posts_path(@structure.id), :class=>"erase" %>
14
+ </div>
15
+ <% end %>
16
+ <% end %>
17
+ </div>
18
+ <div class="sort">
19
+ <label><%= t('manage.sort') %></label>
20
+ <div class="select-input"><%= link_to_function t("manage.posts.sort.#{@search.order_column}_#{@search.next_order_type}"), "SelectList.toggle(event)", :class=>"corn", :id=>'sort_select' %></div>
21
+ <div id='sort_select_list' class="select-list" style='display:none;'>
22
+ <%= link_to_sort(t('manage.posts.sort.created_at_desc'), :name => "created_at", :order_type => 'desc') %>
23
+ <%= link_to_sort(t('manage.posts.sort.created_at_asc'), :name=>"created_at", :order_type=>'asc') %>
24
+
25
+ <%= link_to_sort(t('manage.posts.sort.title_desc'), :name=>"title", :order_type=>'desc') %>
26
+ <%= link_to_sort(t('manage.posts.sort.title_asc'), :name=>"title", :order_type=>'asc') %>
27
+ </div>
28
+ </div>
29
+ </div>
@@ -0,0 +1,31 @@
1
+ <%= content_tag(:div, :id => dom_id(post), :class=>"dinamic-bl") do %>
2
+ <div class="act-bl" style="display:none;">
3
+ <% if can? :update, post, :context => :manage %>
4
+ <%= link_to image_tag("manage/ico_edit.gif", :title=>t('manage.edit')), edit_manage_structure_post_path(@structure.id, post.id), :class=>"icons" %>
5
+ <% end %>
6
+
7
+ <% if can? :delete, post, :context => :manage %>
8
+ <%= link_to image_tag("manage/ico_del.gif", :title=>t('manage.delete')), manage_structure_post_path(@structure.id, post.id),
9
+ :method=>:delete, :confirm=>t("manage.confirm_delete"), :class=>"icons" %>
10
+ <% end %>
11
+ </div>
12
+
13
+ <div class="bot-bg">
14
+ <div class="dinamic-container">
15
+ <div class="right-data">
16
+ <div class="right-data-cont">
17
+ <div class="dinamic-inner">
18
+ <div class="r-block">
19
+ <div class="r-block-cont">
20
+ <%= link_to post.title, edit_manage_structure_post_path(@structure.id, post.id), :class=>"title" %>
21
+ </div>
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <div class="left-data">
27
+ <span class="data"><%= raw I18n.l(post.created_at, :format=>"<span>%d/%m</span>%Y") %></span>
28
+ </div>
29
+ </div>
30
+ </div>
31
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <div class="edit-bl">
2
+ <div class="bot-bg">
3
+ <div class="block-title"><%= t('manage.edit') %>:</div>
4
+ <%= render :partial => 'manage/posts/form' %>
5
+ </div>
6
+ </div>
@@ -0,0 +1,37 @@
1
+ <div class="duo-bl">
2
+ <div class="left-part">
3
+ <div class="content">
4
+ <div class="row-container">
5
+ <div class="white-row">
6
+ <div class="r-corn">
7
+ <%= link_to @structure.title, manage_structure_posts_path(@structure.id), :class=>"dark-text" %>
8
+
9
+ <div class="act-bl">
10
+ <% if can? :create, Post, :context => :manage %>
11
+ <%= link_to t('manage.add'), new_manage_structure_post_path(@structure.id), :class=>"create" %>
12
+ <% end %>
13
+ </div>
14
+ </div>
15
+ </div>
16
+ </div>
17
+
18
+ <div id="posts" class="stage">
19
+ <%= render :partial=>"manage/posts/post", :collection=>@posts %>
20
+ <%= paginate @posts %>
21
+ </div>
22
+
23
+ <script type='text/javascript'>
24
+ $(document).ready(function(){
25
+ Manage.init_collection('posts', 'dinamic-bl');
26
+ });
27
+ </script>
28
+
29
+ </div>
30
+ </div>
31
+
32
+ <div class="right-part">
33
+ <div class="filter-right">
34
+ <%= render :partial=>"manage/posts/model_filter" %>
35
+ </div>
36
+ </div>
37
+ </div>
@@ -0,0 +1,6 @@
1
+ <div class="edit-bl">
2
+ <div class="bot-bg">
3
+ <div class="block-title"><%= t('manage.add') %>:</div>
4
+ <%= render :partial => 'manage/posts/form' %>
5
+ </div>
6
+ </div>
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+ namespace :manage do
3
+ resources :structures do
4
+ resources :posts
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ Usage:
2
+ rails generate sunrise:posts:install [options]
3
+
4
+ Options:
5
+ [--migrations] # Indicates when to generate migrations
6
+ # Default: true
7
+
8
+ Example:
9
+ rails g sunrise:posts:install
10
+
11
+ rails g sunrise:posts:install --skip-migrations
@@ -0,0 +1,34 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module Sunrise
5
+ module Posts
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
10
+ class_option :migrations, :type => :boolean, :default => true, :description => "Generate migrations files"
11
+
12
+ desc "Generates post migration and model"
13
+
14
+ def self.current_time
15
+ @current_time ||= Time.now
16
+ @current_time += 1.minute
17
+ end
18
+
19
+ def self.next_migration_number(dirname)
20
+ current_time.strftime("%Y%m%d%H%M%S")
21
+ end
22
+
23
+ def create_model
24
+ copy_file('post.rb', 'app/models/post.rb')
25
+ end
26
+
27
+ def create_migration
28
+ if options.migrations
29
+ migration_template "create_posts.rb", File.join('db/migrate', "sunrise_create_posts.rb")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,24 @@
1
+ class SunriseCreatePosts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :posts do |t|
4
+ t.integer :structure_id
5
+ t.string :title, :null => false
6
+ # t.string :slug, :limit=>40, :null=>false
7
+ t.text :content
8
+
9
+ t.integer :kind, :limit => 1, :default => 0
10
+ t.integer :comments_count, :default=>0
11
+ t.integer :year, :limit => 4
12
+
13
+ t.datetime :published_at
14
+ t.timestamps
15
+ end
16
+
17
+ add_index :posts, :structure_id
18
+ add_index :posts, :year
19
+ end
20
+
21
+ def self.down
22
+ drop_table :posts
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ class Post < ActiveRecord::Base
2
+ include Sunrise::Models::Post
3
+
4
+ attr_accessible :published_at, :content, :title
5
+
6
+ # scope :visible, where(:is_visible => true)
7
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ module Sunrise
3
+ module Models
4
+ module Post
5
+ def self.included(base)
6
+ base.send :include, InstanceMethods
7
+ base.send :extend, ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def self.extended(base)
12
+ base.send(:include, Utils::Header)
13
+ base.class_eval do
14
+ belongs_to :structure
15
+ has_many :comments, :as => :commentable, :dependent => :delete_all
16
+
17
+ validates_presence_of :title, :content
18
+
19
+ before_save :make_date
20
+ end
21
+ end
22
+ end
23
+
24
+ module InstanceMethods
25
+
26
+ def content_without_html
27
+ return nil if self.content.blank?
28
+ self.content.no_html
29
+ end
30
+
31
+ protected
32
+
33
+ def make_date
34
+ self.published_at ||= Time.now
35
+
36
+ self.year = self.published_at.year if respond_to?(:year)
37
+ self.month = self.published_at.month if respond_to?(:month)
38
+ self.day = self.published_at.day if respond_to?(:day)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails'
2
+ require 'sunrise-posts'
3
+
4
+ module Sunrise
5
+ module Posts
6
+ class Engine < ::Rails::Engine
7
+ config.after_initialize do
8
+ Sunrise::Plugin.register :posts do |plugin|
9
+ plugin.model = 'sunrise/models/post'
10
+ plugin.menu = false
11
+ plugin.version = Sunrise::Posts::VERSION.dup
12
+ end
13
+
14
+ Sunrise::Plugins.activate(:posts)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Sunrise
2
+ module Posts
3
+ VERSION = "0.1.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ module Sunrise
3
+ module Posts
4
+ # Default way to setup Sunrise.
5
+ def self.setup
6
+ yield self
7
+ end
8
+ end
9
+ end
10
+
11
+ require 'sunrise/posts/version'
12
+ require 'sunrise/posts/engine'
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require 'sunrise/posts'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sunrise-posts
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Igor Galeta
14
+ - Pavlo Galeta
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-05-18 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: sunrise
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Sunrise is a Aimbulance CMS
36
+ email: galeta.igor@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ files:
44
+ - README.rdoc
45
+ - Rakefile
46
+ - app/controllers/manage/posts_controller.rb
47
+ - app/sweepers/post_sweeper.rb
48
+ - app/views/manage/posts/_form.html.erb
49
+ - app/views/manage/posts/_model_filter.html.erb
50
+ - app/views/manage/posts/_post.html.erb
51
+ - app/views/manage/posts/edit.html.erb
52
+ - app/views/manage/posts/index.html.erb
53
+ - app/views/manage/posts/new.html.erb
54
+ - config/routes.rb
55
+ - lib/generators/sunrise/posts/USAGE
56
+ - lib/generators/sunrise/posts/install_generator.rb
57
+ - lib/generators/sunrise/posts/templates/create_posts.rb
58
+ - lib/generators/sunrise/posts/templates/post.rb
59
+ - lib/sunrise-posts.rb
60
+ - lib/sunrise/models/post.rb
61
+ - lib/sunrise/posts.rb
62
+ - lib/sunrise/posts/engine.rb
63
+ - lib/sunrise/posts/version.rb
64
+ homepage: https://github.com/galetahub/sunrise-posts
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.2
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Rails CMS
97
+ test_files: []
98
+