postage 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1,7 @@
1
+ = Authors
2
+
3
+ Postage was maintained and developed by {Hallison
4
+ Batista}[http://hallisonbatista.com].
5
+
6
+ Please, contributors are most welcome.
7
+
data/CHANGES ADDED
@@ -0,0 +1,10 @@
1
+ = Changes
2
+
3
+ [0.1.0 - July 2009]
4
+ * This version has been extracted from
5
+ {Postview}[http://postview.rubyforge.org] project.
6
+
7
+ * Posts and all attributes are loaded from text files.
8
+
9
+ * All files are found by Finder class.
10
+
data/INFO ADDED
@@ -0,0 +1,16 @@
1
+ :name: postage
2
+ :version: 0.1.1
3
+ :date: 2009-07-11
4
+ :cycle: Development release - Pre-alpha
5
+ :summary:
6
+ Postage API implemented for helper handle text files for posts.
7
+ :description:
8
+ Postage is an API developed for handle text files for posts for blogs
9
+ or anything else.
10
+ :authors:
11
+ - Hallison Batista
12
+ :email: email@hallisonbatista.com
13
+ :homepage: http://postage.rubyforge.org/
14
+ :dependencies:
15
+ maruku: >= 0.6.0
16
+
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ = The MIT License
2
+
3
+ Copyright (c) 2009 Hallison Batista
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included
14
+ in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/MANIFEST ADDED
@@ -0,0 +1,21 @@
1
+ AUTHORS
2
+ CHANGES
3
+ INFO
4
+ LICENSE
5
+ MANIFEST
6
+ README
7
+ Rakefile
8
+ lib/extensions.rb
9
+ lib/postage.rb
10
+ lib/postage/finder.rb
11
+ lib/postage/post.rb
12
+ tasks/package.rake
13
+ tasks/postage.rake
14
+ templates/post.erb
15
+ test/fixtures/20080501-postage_test_post.ruby.postage.mkd
16
+ test/fixtures/20080601-postage_test_post.ruby.postage.mkd
17
+ test/fixtures/20090604-postage_test_post.ruby.postage.mkd
18
+ test/fixtures/20090604143805-postage_test_post.ruby.postage.mkd
19
+ test/fixtures/20090608-creating_new_entry_from_test_unit.ruby.postage.test.mkd
20
+ test/test_finder.rb
21
+ test/test_post.rb
data/README ADDED
@@ -0,0 +1,50 @@
1
+ = Postage - API for write posts in simple text files
2
+
3
+ * {Repository}[http://github.com/hallison/postage]
4
+ * {Project}[http://rubyforge.org/projects/postage]
5
+ * {Documentation}[:link:Postage.html]
6
+ * {Issues}[http://github.com/hallison/postage/issues]
7
+
8
+
9
+ Postage is a simple API which load your text files and handle the
10
+ contents in Markdown syntax.
11
+
12
+ It's useful for _blogwares_, or anything else, that uses flat files
13
+ organized in directories instead databases.
14
+
15
+ Use your post text file in following hierarchy and format:
16
+
17
+ /posts/path/yyyymmdd-name_of_post.tags.filter
18
+
19
+ Real example of use:
20
+
21
+ home
22
+ `-- hallison
23
+ `-- blog
24
+ `-- posts
25
+ |-- 20090604-posting_blog_articles_using_postage.ruby.postage.mkd
26
+ |-- 20090529-postview_blogging_posts_with_sinatra_and_postage.ruby.sinatra.postage.mkd
27
+ |-- archive
28
+ |-- 20080930-bash_condicional_variables.shell.script.mkd
29
+ `-- 20081008-bash_arguments_validation.bash.shell.script.test.mkd
30
+ `-- drafts
31
+
32
+ It's possible uses Markdown Extra syntax because Postage use Maruku for
33
+ converting files.
34
+
35
+ About Markdown lightweight markup language, please, visit
36
+ <http://daringfireball.net/projects/markdown> and Markdown Extra, visit
37
+ <http://michelf.com/projects/php-markdown/extra/>.
38
+
39
+ == Requirements
40
+
41
+ Please, Postage has dependencies and most be installed.
42
+
43
+ * {Maruku}[http://maruku.rubyforge.org/], for convert Maruku in HTML.
44
+
45
+ == More information
46
+
47
+ * {Authors}[:link:AUTHORS.html]
48
+ * {Changes}[:link:CHANGES.html]
49
+ * {License}[:link:LICENSE.html]
50
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
2
+
3
+ require 'lib/postage'
4
+
5
+ Dir["tasks/**.rake"].each do |task_file|
6
+ load task_file
7
+ end
8
+
9
+ task :default => [ :test ]
10
+
data/lib/extensions.rb ADDED
@@ -0,0 +1,47 @@
1
+ class Hash
2
+
3
+ # Only symbolize all keys, including all key in sub-hashes.
4
+ def symbolize_keys
5
+ self.inject({}) do |hash, (key, value)|
6
+ hash[key.to_sym] = if value.kind_of? Hash
7
+ value.symbolize_keys
8
+ else
9
+ value
10
+ end
11
+ hash
12
+ end
13
+ end
14
+
15
+ # Set instance variables by key and value only if object respond
16
+ # to access method for variable.
17
+ def instance_variables_set_to(object)
18
+ collect do |variable, value|
19
+ object.instance_variable_set("@#{variable}", value) if object.respond_to? variable
20
+ end
21
+ object
22
+ end
23
+
24
+ end
25
+
26
+ class Date
27
+
28
+ # Stringify date and split by '-'.
29
+ #
30
+ # date = Date.new(2009,6,9)
31
+ # date.to_s # => 2009-06-09
32
+ # date.to_args # => [ "2009", "06", "09" ]
33
+ def to_args
34
+ to_s.split('-')
35
+ end
36
+
37
+ end
38
+
39
+ class Array
40
+
41
+ # Returns elements between first and the specific limit.
42
+ def limit(size)
43
+ self[0..size]
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,61 @@
1
+ module Postage
2
+
3
+ # This class is a utility for find all posts in specific directory.
4
+ class Finder
5
+
6
+ attr_reader :posts, :tags
7
+
8
+ # Finder most be initialized with the directory that contains post files.
9
+ def initialize(directory)
10
+ @files = Dir[File.join(directory, "**.*")]
11
+ end
12
+
13
+ def load_all_post_files
14
+ @files.sort.collect do |file_name|
15
+ Post.load(file_name)
16
+ end
17
+ end
18
+
19
+ def all_posts
20
+ @posts ||= load_all_post_files
21
+ end
22
+
23
+ def all_posts_by_tag(tag)
24
+ all_posts
25
+ @posts.find_all{ |post| post.tags.include?(tag) }
26
+ end
27
+
28
+ def post(year, month, day, name)
29
+ all_posts
30
+ @posts.find{ |post| post.file.match(%r{#{year}#{month}#{day}-#{name}*.*}i) }
31
+ end
32
+
33
+ def posts(keywords)
34
+ all_posts
35
+ @posts.find_all{ |post| post.matched? search_expresion(keywords) }
36
+ end
37
+
38
+ def all_post_tags
39
+ all_posts
40
+ @tags ||= @posts.collect{ |post| post.tags }.flatten.uniq.sort
41
+ end
42
+
43
+ def all_tags
44
+ all_post_tags
45
+ end
46
+
47
+ def tag(name)
48
+ all_tags
49
+ @tags.find{ |tag| tag == name }
50
+ end
51
+
52
+ private
53
+
54
+ def search_expresion(keywords)
55
+ %r{#{keywords.to_s.split(/[ ,\*]/).join('|')}}i
56
+ end
57
+
58
+ end # class Finder
59
+
60
+ end # module Postage
61
+
@@ -0,0 +1,176 @@
1
+ module Postage
2
+ # Main class for handle text files. The Post class load file and extract all
3
+ # attributes from name. Examples:
4
+ #
5
+ # If you want load a file, use:
6
+ #
7
+ # post = Postage::Post.load("posts/20090710-my_post_file.ruby.postage.mkd")
8
+ # # => post.title : My post file
9
+ # # => post.publish_date : 2009-07-10
10
+ # # => post.tags : ruby, postage
11
+ # # => post.filter : markdown
12
+ #
13
+ # Or, if you want initialize a new post, use:
14
+ #
15
+ # post = Postage::Post.new :title => "Creating new `entry` from test unit",
16
+ # :publish_date => Date.new(2009,7,10),
17
+ # :tags => %w(ruby postage),
18
+ # :filter => :markdown,
19
+ # :content => <<-end_content.gsub(/[ ]{2}/,'')
20
+ # Ok. This is a test for create new `entry` from test unit and this paragraph will be
21
+ # the post summary.
22
+ #
23
+ # In this file, I'll write any content ... only for test.
24
+ # Postage is a lightweight API for load posts from flat file that contains
25
+ # text filtered by [Markdown][] syntax.
26
+ #
27
+ # [markdown]: http://daringfireball.net/projects/markdown/
28
+ # end_content
29
+ class Post
30
+
31
+ # Post publish date, of course.
32
+ attr_reader :publish_date
33
+ # The title accepts Markdown syntax.
34
+ attr_reader :title
35
+ # Tags accepts only one word per tag.
36
+ attr_reader :tags
37
+ # Summary is a first paragraph of content.
38
+ attr_reader :summary
39
+ attr_reader :content
40
+ # Filter for render post file.
41
+ attr_reader :filter
42
+ attr_reader :file
43
+
44
+ # Initialize new post using options.
45
+ def initialize(options = {})
46
+ options.instance_variables_set_to(self)
47
+ end
48
+
49
+ # Load all attributes from file name and read content.
50
+ def self.load(file_name)
51
+ new.extract_attributes(file_name)
52
+ end
53
+
54
+ # Check and extract all attributes from file name.
55
+ def extract_attributes(file_name)
56
+ extract_publish_date(file_name)
57
+ extract_tags(file_name)
58
+ extract_filter(file_name)
59
+ extract_title_and_content(file_name)
60
+ @file = File.basename(file_name)
61
+ @title = @file.gsub('_', ' ').capitalize if @title.to_s.empty?
62
+ @summary = @content.match(%r{<p>.*</p>}).to_s
63
+ self
64
+ end
65
+
66
+ # Return post name formatted ("year/month/day/name").
67
+ def to_s
68
+ @file.scan(%r{(\d{4})(\d{2})(\d{2})(.*?)-(.*?)\..*}) do |year,month,day,time,name|
69
+ return "#{year}/#{month}/#{day}/#{name}"
70
+ end
71
+ end
72
+
73
+ # Build post file name and return following format: yyyymmdd-post_name.tags.separated.by.points.filter
74
+ def build_file
75
+ @file = "#{build_publish_date}-#{build_file_name}.#{build_tags}.#{build_filter}"
76
+ end
77
+
78
+ # Get post file name and creates content and save into directory.
79
+ def create_into(directory)
80
+ File.open(File.join(directory, @file), 'a') do |file|
81
+ post = self
82
+ file << ERB.new(load_template).result(binding)
83
+ end
84
+ end
85
+
86
+ def matched?(regexp)
87
+ @title.match(regexp) || @file.match(regexp)
88
+ end
89
+
90
+ private
91
+
92
+ def extract_publish_date(file_name)
93
+ file_name.scan(%r{/(\d{4})(\d{2})(\d{2})(.*?)-.*}) do |year,month,day,time|
94
+ return extract_publish_datetime(file_name) unless time.empty?
95
+ @publish_date = Date.new(year.to_i, month.to_i, day.to_i)
96
+ end
97
+ end
98
+
99
+ def extract_publish_datetime(file_name)
100
+ file_name.scan(%r{/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})-.*}) do |year,month,day,hour,min,sec|
101
+ @publish_date = DateTime.new(year.to_i, month.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i)
102
+ end
103
+ end
104
+ def extract_title(file_name)
105
+ Maruku.new(title).to_html.gsub(/<[hp]\d{0,1}.*?>(.*)<\/[hp]\d{0,1}>/){$1}
106
+ end
107
+
108
+ def extract_tags(file_name)
109
+ @tags = file_name.scan(%r{.*?-.*?\.(.*)\..*}).to_s.split('.')
110
+ end
111
+
112
+ def extract_filter(file_name)
113
+ file_name.scan(%r{.*\.(.*)}) do |filter|
114
+ @filter = case filter.to_s
115
+ when /md|mkd|mark.*/
116
+ :markdown
117
+ when /tx|txt|text.*/
118
+ :textile
119
+ else
120
+ :text
121
+ end
122
+ end
123
+ end
124
+
125
+ def find_file(year, month, day, name)
126
+ # TODO: check posts directory
127
+ Dir["#{year}#{month}#{day}-#{name}**.*"].first
128
+ end
129
+
130
+ def load_file(file)
131
+ File.read(file)
132
+ end
133
+
134
+ def extract_title_and_content(file_name)
135
+ _content = File.readlines(file_name)
136
+ _title = _content.shift
137
+ _title += _content.shift if (_content.first =~ /==/)
138
+ @title = Maruku.new(_title).to_html.gsub(/<h1.*?>(.*)<\/h1>/){$1}
139
+ @content = Maruku.new(_content.to_s).to_html
140
+ end
141
+
142
+ def build_file_name
143
+ @title.downcase.gsub(/ /, '_').gsub(/[^a-z0-9_]/, '').squeeze('_')
144
+ end
145
+
146
+ def build_tags
147
+ @tags.join('.')
148
+ end
149
+
150
+ def build_publish_date
151
+ @publish_date.strftime('%Y%m%d')
152
+ end
153
+
154
+ def build_filter
155
+ case @filter
156
+ when :markdown
157
+ "mkd"
158
+ when :textile
159
+ "txl"
160
+ else :none
161
+ ""
162
+ end
163
+ end
164
+
165
+ def load_template
166
+ File.read(template)
167
+ end
168
+
169
+ def template
170
+ File.join(ROOT,'templates','post.erb')
171
+ end
172
+
173
+ end # class Post
174
+
175
+ end # module Postage
176
+
data/lib/postage.rb ADDED
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2009, Hallison Vasconcelos Batista
2
+ #
3
+ # Author:: Hallison Batista <email@hallisonbatista.com>
4
+ #
5
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
6
+
7
+ # Main module for API.
8
+ module Postage
9
+
10
+ %w(rubygems maruku erb).map do |dependency|
11
+ require dependency
12
+ end
13
+
14
+ %w(ruby-debug).map do |optional|
15
+ require optional
16
+ end
17
+
18
+ # Root directory for references library.
19
+ ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
20
+ INFO = YAML.load_file(File.join(ROOT, "INFO"))
21
+
22
+ # Postage core extensions.
23
+ require 'extensions'
24
+
25
+ # Auto-load all libraries
26
+ autoload :Post, 'postage/post'
27
+ autoload :Finder, 'postage/finder'
28
+
29
+ class << self
30
+
31
+ # Returns the module formatted name.
32
+ def to_s
33
+ "#{INFO[:name]} v#{INFO[:version]} (#{INFO[:cycle]})"
34
+ end
35
+ alias :info :to_s
36
+
37
+ end
38
+
39
+ end # module Postage
40
+
@@ -0,0 +1,70 @@
1
+ require 'rake/packagetask'
2
+ require 'rake/gempackagetask'
3
+
4
+ def manifest_file
5
+ File.readlines(File.join(Postage::ROOT, "MANIFEST"))
6
+ end
7
+
8
+ def manifest
9
+ manifest_file.map do |file|
10
+ file.strip
11
+ end
12
+ end
13
+
14
+ def spec
15
+ Gem::Specification.new do |spec|
16
+ spec.platform = Gem::Platform::RUBY
17
+ Postage::INFO.each do |info, value|
18
+ spec.send("#{info}=", value) if spec.respond_to? "#{info}="
19
+ end
20
+
21
+ Postage::INFO[:dependencies].each do |name, version|
22
+ spec.add_dependency name, version
23
+ end
24
+
25
+ spec.require_paths = %w[lib]
26
+ spec.files = manifest
27
+ spec.test_files = spec.files.select{ |path| path =~ /^test\/.*_test.rb/ }
28
+
29
+ spec.has_rdoc = true
30
+ spec.extra_rdoc_files = %w[README LICENSE]
31
+ spec.add_development_dependency 'ruby-debug', '>= 0.10.3'
32
+
33
+ spec.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Postage", "--main", "README"]
34
+ spec.rubyforge_project = spec.name
35
+ spec.rubygems_version = '1.1.1'
36
+ end # Gem::Specification
37
+ end
38
+
39
+ def package(ext)
40
+ "pkg/#{spec.name}-#{spec.version}.#{ext}"
41
+ end
42
+
43
+ Rake::GemPackageTask.new(spec) do |pkg|
44
+ pkg.need_tar_bz2 = true
45
+ end
46
+
47
+ desc "Generate MANIFEST file."
48
+ task :manifest do |file|
49
+ File.open(File.join(Postage::ROOT, file.name.upcase), "w+") do |manifest|
50
+ manifest.write(
51
+ `git ls-files`.split("\n").sort.reject do |ignored|
52
+ ignored =~ /^\./ || ignored =~ /rdoc/
53
+ end.join("\n")
54
+ )
55
+ end
56
+ end
57
+
58
+ desc "Install gem file."
59
+ task :install => [ :manifest, :gem ] do
60
+ `gem install pkg/#{spec.name}-#{spec.version}.gem --local`
61
+ end
62
+
63
+ desc 'Publish gem and tarball to rubyforge.org.'
64
+ task :release => [ :gem, :package] do |t|
65
+ sh <<-end_sh.gsub(/^[ ]{4}/,'')
66
+ rubyforge add_release #{spec.name} #{spec.name} #{spec.version} #{package "gem"} &&
67
+ rubyforge add_file #{spec.name} #{spec.name} #{spec.version} #{package("tar.bz2")}
68
+ end_sh
69
+ end
70
+
File without changes
@@ -0,0 +1,5 @@
1
+ <%= post.title %>
2
+ <%= "=" * post.title.size %>
3
+
4
+ <%= post.content || "Input the content." %>
5
+
@@ -0,0 +1,12 @@
1
+ Postage test *post*
2
+ ===================
3
+
4
+ The title os post is a first line of document.
5
+ All attributes are specified in file name.
6
+
7
+ yyyymmdd-name_of_file.tags.filter
8
+
9
+ Simple and easy.
10
+
11
+
12
+
@@ -0,0 +1,12 @@
1
+ Postage test *post*
2
+ ===================
3
+
4
+ The title os post is a first line of document.
5
+ All attributes are specified in file name.
6
+
7
+ yyyymmdd-name_of_file.tags.filter
8
+
9
+ Simple and easy.
10
+
11
+
12
+
@@ -0,0 +1,12 @@
1
+ Postage test *post*
2
+ ===================
3
+
4
+ The title os post is a first line of document.
5
+ All attributes are specified in file name.
6
+
7
+ yyyymmdd-name_of_file.tags.filter
8
+
9
+ Simple and easy.
10
+
11
+
12
+
@@ -0,0 +1,10 @@
1
+ Postage test *post*
2
+ ===================
3
+
4
+ The title os post is a first line of document.
5
+ All attributes are specified in file name.
6
+
7
+ yyyymmdd-name_of_file.tags.filter
8
+
9
+ Simple and easy.
10
+
@@ -0,0 +1,192 @@
1
+ Creating new `entry` from test unit
2
+ ===================================
3
+
4
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
5
+
6
+ In this file, I'll write any content ... only for test.
7
+ Postage is a lightweight API for load posts from flat file that contains
8
+ text filtered by [Markdown][] syntax.
9
+
10
+ [Markdown]: http://daringfireball.net/projects/markdown/
11
+
12
+
13
+ Creating new `entry` from test unit
14
+ ===================================
15
+
16
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
17
+
18
+ In this file, I'll write any content ... only for test.
19
+ Postage is a lightweight API for load posts from flat file that contains
20
+ text filtered by [Markdown][] syntax.
21
+
22
+ [Markdown]: http://daringfireball.net/projects/markdown/
23
+
24
+
25
+ Creating new `entry` from test unit
26
+ ===================================
27
+
28
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
29
+
30
+ In this file, I'll write any content ... only for test.
31
+ Postage is a lightweight API for load posts from flat file that contains
32
+ text filtered by [Markdown][] syntax.
33
+
34
+ [Markdown]: http://daringfireball.net/projects/markdown/
35
+
36
+
37
+ Creating new `entry` from test unit
38
+ ===================================
39
+
40
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
41
+
42
+ In this file, I'll write any content ... only for test.
43
+ Postage is a lightweight API for load posts from flat file that contains
44
+ text filtered by [Markdown][] syntax.
45
+
46
+ [Markdown]: http://daringfireball.net/projects/markdown/
47
+
48
+
49
+ Creating new `entry` from test unit
50
+ ===================================
51
+
52
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
53
+
54
+ In this file, I'll write any content ... only for test.
55
+ Postage is a lightweight API for load posts from flat file that contains
56
+ text filtered by [Markdown][] syntax.
57
+
58
+ [Markdown]: http://daringfireball.net/projects/markdown/
59
+
60
+
61
+ Creating new `entry` from test unit
62
+ ===================================
63
+
64
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
65
+
66
+ In this file, I'll write any content ... only for test.
67
+ Postage is a lightweight API for load posts from flat file that contains
68
+ text filtered by [Markdown][] syntax.
69
+
70
+ [Markdown]: http://daringfireball.net/projects/markdown/
71
+
72
+
73
+ Creating new `entry` from test unit
74
+ ===================================
75
+
76
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
77
+
78
+ In this file, I'll write any content ... only for test.
79
+ Postage is a lightweight API for load posts from flat file that contains
80
+ text filtered by [Markdown][] syntax.
81
+
82
+ [Markdown]: http://daringfireball.net/projects/markdown/
83
+
84
+
85
+ Creating new `entry` from test unit
86
+ ===================================
87
+
88
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
89
+
90
+ In this file, I'll write any content ... only for test.
91
+ Postage is a lightweight API for load posts from flat file that contains
92
+ text filtered by [Markdown][] syntax.
93
+
94
+ [Markdown]: http://daringfireball.net/projects/markdown/
95
+
96
+
97
+ Creating new `entry` from test unit
98
+ ===================================
99
+
100
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
101
+
102
+ In this file, I'll write any content ... only for test.
103
+ Postage is a lightweight API for load posts from flat file that contains
104
+ text filtered by [Markdown][] syntax.
105
+
106
+ [Markdown]: http://daringfireball.net/projects/markdown/
107
+
108
+
109
+ Creating new `entry` from test unit
110
+ ===================================
111
+
112
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
113
+
114
+ In this file, I'll write any content ... only for test.
115
+ Postage is a lightweight API for load posts from flat file that contains
116
+ text filtered by [Markdown][] syntax.
117
+
118
+ [Markdown]: http://daringfireball.net/projects/markdown/
119
+
120
+
121
+ Creating new `entry` from test unit
122
+ ===================================
123
+
124
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
125
+
126
+ In this file, I'll write any content ... only for test.
127
+ Postage is a lightweight API for load posts from flat file that contains
128
+ text filtered by [Markdown][] syntax.
129
+
130
+ [Markdown]: http://daringfireball.net/projects/markdown/
131
+
132
+
133
+ Creating new `entry` from test unit
134
+ ===================================
135
+
136
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
137
+
138
+ In this file, I'll write any content ... only for test.
139
+ Postage is a lightweight API for load posts from flat file that contains
140
+ text filtered by [Markdown][] syntax.
141
+
142
+ [Markdown]: http://daringfireball.net/projects/markdown/
143
+
144
+
145
+ Creating new `entry` from test unit
146
+ ===================================
147
+
148
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
149
+
150
+ In this file, I'll write any content ... only for test.
151
+ Postage is a lightweight API for load posts from flat file that contains
152
+ text filtered by [Markdown][] syntax.
153
+
154
+ [Markdown]: http://daringfireball.net/projects/markdown/
155
+
156
+
157
+ Creating new `entry` from test unit
158
+ ===================================
159
+
160
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
161
+
162
+ In this file, I'll write any content ... only for test.
163
+ Postage is a lightweight API for load posts from flat file that contains
164
+ text filtered by [Markdown][] syntax.
165
+
166
+ [Markdown]: http://daringfireball.net/projects/markdown/
167
+
168
+
169
+ Creating new `entry` from test unit
170
+ ===================================
171
+
172
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
173
+
174
+ In this file, I'll write any content ... only for test.
175
+ Postage is a lightweight API for load posts from flat file that contains
176
+ text filtered by [Markdown][] syntax.
177
+
178
+ [Markdown]: http://daringfireball.net/projects/markdown/
179
+
180
+
181
+ Creating new `entry` from test unit
182
+ ===================================
183
+
184
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
185
+
186
+ In this file, I'll write any content ... only for test.
187
+ Postage is a lightweight API for load posts from flat file that contains
188
+ text filtered by [Markdown][] syntax.
189
+
190
+ [Markdown]: http://daringfireball.net/projects/markdown/
191
+
192
+
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/..")
2
+
3
+ require 'test/unit'
4
+ require 'lib/postage'
5
+
6
+ class TestFinder < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @find = Postage::Finder.new("#{File.dirname(__FILE__)}/fixtures")
10
+ end
11
+
12
+ def test_should_find_post
13
+ date = Date.new(2009,6,4)
14
+ assert_equal date, @find.post(*date.to_args << 'postage').publish_date
15
+ assert_equal date, @find.post(*%w[2009 06 04 postage]).publish_date
16
+ end
17
+
18
+ def test_should_load_all_posts
19
+ assert_equal 5, @find.all_posts.size
20
+ end
21
+
22
+ def test_should_load_all_tags
23
+ assert_equal 3, @find.all_post_tags.size
24
+ end
25
+
26
+ end
27
+
data/test/test_post.rb ADDED
@@ -0,0 +1,62 @@
1
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/..")
2
+
3
+ require 'test/unit'
4
+ require 'lib/postage'
5
+
6
+ class TestPost < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @attributes = {
10
+ :publish_date => Date.new(2009, 06, 04),
11
+ :title => "Postage test <em>post</em>",
12
+ :tags => %w(ruby postage),
13
+ :filter => :markdown,
14
+ :file => "20090604-postage_test_post.ruby.postage.mkd"
15
+ }
16
+ @post = Postage::Post.load("#{File.dirname(__FILE__)}/fixtures/20090604-postage_test_post.ruby.postage.mkd")
17
+ end
18
+
19
+ def test_should_load_attributes_from_file_name_with_simple_date
20
+ @attributes.each do |attribute, value|
21
+ assert_equal value, @post.send(attribute)
22
+ end
23
+ assert_equal "2009/06/04/postage_test_post", "#{@post}"
24
+ end
25
+
26
+ def test_should_load_attributes_from_file_name_with_datetime
27
+ @attributes.update(
28
+ :publish_date => DateTime.new(2009,6,4,14,38,5),
29
+ :file => "20090604143805-postage_test_post.ruby.postage.mkd"
30
+ )
31
+ @post = Postage::Post.load("#{File.dirname(__FILE__)}/fixtures/20090604143805-postage_test_post.ruby.postage.mkd")
32
+ @attributes.each do |attribute, value|
33
+ assert_equal value, @post.send(attribute)
34
+ end
35
+ assert_equal "2009/06/04/postage_test_post", "#{@post}"
36
+ end
37
+
38
+ def test_should_check_html_in_content
39
+ assert_match %r{<p>.*?</p>}, @post.content
40
+ end
41
+
42
+ def test_should_create_new_post_file
43
+ @post = Postage::Post.new :title => "Creating new `entry` from test unit",
44
+ :publish_date => Date.new(2009,6,8),
45
+ :tags => %w(ruby postage test),
46
+ :filter => :markdown,
47
+ :content => <<-end_content.gsub(/[ ]{6}/,'')
48
+ Ok. This is a test for create new `entry` from test unit and this paragraph will summary.
49
+
50
+ In this file, I'll write any content ... only for test.
51
+ Postage is a lightweight API for load posts from flat file that contains
52
+ text filtered by [Markdown][] syntax.
53
+
54
+ [Markdown]: http://daringfireball.net/projects/markdown/
55
+ end_content
56
+
57
+ assert_equal "20090608-creating_new_entry_from_test_unit.ruby.postage.test.mkd", @post.build_file
58
+ @post.create_into "#{File.dirname(__FILE__)}/fixtures"
59
+ assert File.exist?("#{File.dirname(__FILE__)}/fixtures/#{@post.file}")
60
+ end
61
+ end
62
+
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: postage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Hallison Batista
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-11 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: maruku
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.6.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby-debug
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.3
34
+ version:
35
+ description: Postage is an API developed for handle text files for posts for blogs or anything else.
36
+ email: email@hallisonbatista.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ - LICENSE
44
+ files:
45
+ - AUTHORS
46
+ - CHANGES
47
+ - INFO
48
+ - LICENSE
49
+ - MANIFEST
50
+ - README
51
+ - Rakefile
52
+ - lib/extensions.rb
53
+ - lib/postage.rb
54
+ - lib/postage/finder.rb
55
+ - lib/postage/post.rb
56
+ - tasks/package.rake
57
+ - tasks/postage.rake
58
+ - templates/post.erb
59
+ - test/fixtures/20080501-postage_test_post.ruby.postage.mkd
60
+ - test/fixtures/20080601-postage_test_post.ruby.postage.mkd
61
+ - test/fixtures/20090604-postage_test_post.ruby.postage.mkd
62
+ - test/fixtures/20090604143805-postage_test_post.ruby.postage.mkd
63
+ - test/fixtures/20090608-creating_new_entry_from_test_unit.ruby.postage.test.mkd
64
+ - test/test_finder.rb
65
+ - test/test_post.rb
66
+ has_rdoc: true
67
+ homepage: http://postage.rubyforge.org/
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --line-numbers
73
+ - --inline-source
74
+ - --title
75
+ - Postage
76
+ - --main
77
+ - README
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ requirements: []
93
+
94
+ rubyforge_project: postage
95
+ rubygems_version: 1.3.3
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Postage API implemented for helper handle text files for posts.
99
+ test_files: []
100
+