yodel_blog 0.0.1

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.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in yodel_blog.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ xml.instruct!
2
+
3
+ xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
4
+ xml.title self.title
5
+ xml.link "rel" => "self", "href" => request.url
6
+ xml.link "rel" => "alternate", "href" => URI.escape(request.scheme_and_host + self.path)
7
+ xml.id request.url
8
+ xml.updated articles.first.published.strftime "%Y-%m-%dT%H:%M:%SZ" if articles.any?
9
+ xml.summary "" # FIXME: implement
10
+ xml.author do
11
+ xml.name site.name
12
+ end
13
+
14
+ articles.each do |article|
15
+ xml.entry do
16
+ xml.title article.title
17
+ xml.link "rel" => "alternate", "href" => article.path
18
+ xml.id URI.escape(request.scheme_and_host + article.path)
19
+ xml.updated article.published.strftime "%Y-%m-%dT%H:%M:%SZ"
20
+ xml.author { xml.name article.author.name } if !article.author.nil?
21
+ xml.summary article.content #HTML.new(article.content).to_text # FIXME: implement correctly
22
+
23
+ xml.content "type" => "html" do
24
+ xml.text! article.content
25
+ end
26
+
27
+ #unless article.attachment.nil?
28
+ # xml.link "rel" => "enclosure", "type" => article.attachment.mime_type, "href" => URI.escape(request.scheme_and_host + article.attachment.url.to_s), "length" => article.attachment.length
29
+ #end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ class BlogModelMigration < Migration
2
+ def self.up(site)
3
+ site.pages.create_model :blogs do |blogs|
4
+ add_field :articles_per_page, :integer, default: 5
5
+ add_field :blog, :self
6
+ blogs.record_class_name = 'Blog'
7
+ end
8
+ end
9
+
10
+ def self.down(site)
11
+ site.blogs.destroy
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ class ArticleModelMigration < Migration
2
+ def self.up(site)
3
+ site.pages.create_model :articles do |articles|
4
+ add_field :published, :time
5
+ add_field :tags, :tags
6
+ add_field :blog, :alias, of: :parent
7
+ add_field :search_title, :function, fn: 'format("News: {{title}}")'
8
+ add_one :author, model: :user
9
+ articles.allowed_parents = [site.blogs]
10
+ end
11
+
12
+ site.blogs.modify do |blogs|
13
+ blogs.allowed_children = [site.articles]
14
+ end
15
+ end
16
+
17
+ def self.down(site)
18
+ site.articles.destroy
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ class UpdateBlogFieldsForAdminMigration < Migration
2
+ def self.up(site)
3
+ site.blogs.modify do |blogs|
4
+ blogs.modify_field :articles_per_page, section: 'Options'
5
+ end
6
+
7
+ site.articles.modify do |articles|
8
+ articles.modify_field :author, show_blank: true, blank_text: 'None'
9
+ end
10
+ end
11
+
12
+ def self.down(site)
13
+ site.blogs.modify do |blogs|
14
+ blogs.modify_field :articles_per_page, section: nil
15
+ end
16
+
17
+ site.articles.modify do |articles|
18
+ articles.modify_field :author, show_blank: false, blank_text: nil
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,84 @@
1
+ class Blog < Page
2
+ respond_to :get do
3
+ with :atom do |xml|
4
+ @xml = xml
5
+ layout('atom').render(self)
6
+ end
7
+ end
8
+
9
+ def xml
10
+ @xml
11
+ end
12
+
13
+ def articles
14
+ return @articles if @articles
15
+ query = site.articles.where(parent: id).order('published desc')
16
+
17
+ # FIXME: merge in to search page
18
+ if params['tag']
19
+ @tag = params['tag']
20
+ query = query.where(tags: @tag)
21
+ @page_params = "tag=#{params['tag']}&"
22
+ elsif params['month'] && params['year']
23
+ @month = [[params['month'].to_i, 1].max, 12].min # constrain the month between 1..12
24
+ @year = params['year'].to_i
25
+ query = query.where(:published.gte => Time.local(@year, @month, 1), :published.lte => Time.local(@year, @month + 1, 1))
26
+ @page_params = "year=#{params['year']}&month=#{params['month']}&"
27
+ else
28
+ @page_params = ''
29
+ end
30
+
31
+ @total_articles = query.count
32
+ @number_of_pages = (@total_articles.to_f / articles_per_page).ceil
33
+ query.limit(articles_per_page).skip(page_number * articles_per_page).all
34
+ end
35
+
36
+ def first_page?
37
+ page_number == 0
38
+ end
39
+
40
+ def last_page?
41
+ page_number == @number_of_pages - 1
42
+ end
43
+
44
+ def page_number
45
+ @page_number ||= params['page'].to_i
46
+ end
47
+
48
+ def tag_path(tag)
49
+ "#{path}?tag=#{CGI::escape(tag || '')}"
50
+ end
51
+
52
+ def month_path(month, year)
53
+ "#{path}?month=#{month}&year=#{year}"
54
+ end
55
+
56
+ def all_article_months
57
+ counts = Hash.new(0)
58
+
59
+ # generate a count of articles for each month
60
+ children.each do |child|
61
+ date = child.published.at_beginning_of_month
62
+ counts[date] += 1
63
+ end
64
+
65
+ # collect the months into an array of counted values
66
+ months = counts.each_pair.collect {|date, count| OpenStruct.new(date: date, count: count, path: month_path(date.month, date.year))}
67
+ months.sort_by(&:date).reverse
68
+ end
69
+
70
+ def all_article_tags
71
+ counts = Hash.new(0)
72
+
73
+ # count the number of articles each tag appears in
74
+ children.each do |child|
75
+ child.tags.each do |tag|
76
+ counts[tag] += 1
77
+ end
78
+ end
79
+
80
+ # collect the tags into an array of counted values
81
+ tags = counts.each_pair.collect {|tag, count| OpenStruct.new(tag: tag, count: count, path: tag_path(tag))}
82
+ tags.sort_by(&:count).reverse
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module YodelBlog
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "yodel_blog"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'yodel_blog'
7
+ s.version = YodelBlog::VERSION
8
+ s.authors = ['Will Cannings']
9
+ s.email = ['me@willcannings.com']
10
+ s.homepage = 'http://yodelcms.com'
11
+ s.summary = 'Yodel CMS Blog Extension'
12
+ s.description = 'Yodel CMS Blog Extension'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ # s.add_development_dependency "rspec"
21
+ # s.add_runtime_dependency "rest-client"
22
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yodel_blog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Will Cannings
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-09 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Yodel CMS Blog Extension
15
+ email:
16
+ - me@willcannings.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Rakefile
24
+ - lib/layouts/blog.atom
25
+ - lib/migrations/01_blog_model.rb
26
+ - lib/migrations/02_article_model.rb
27
+ - lib/migrations/03_update_blog_fields_for_admin.rb
28
+ - lib/models/blog.rb
29
+ - lib/yodel_blog.rb
30
+ - yodel_blog.gemspec
31
+ homepage: http://yodelcms.com
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.10
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Yodel CMS Blog Extension
55
+ test_files: []