pipin 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -12,18 +12,20 @@
12
12
  cd myblog
13
13
  rake
14
14
 
15
- == todo
15
+ == development
16
+
17
+ 開発環境についてのメモ。
18
+
19
+ 以下で新規blogを生成。
16
20
 
17
- * 原稿の入力
18
- * html, txt(hd)
19
- * to_html
21
+ script/pipin new myblog
20
22
 
21
- * 原稿の検索
22
- * カテゴリ
23
+ myblog/Rakefile 先頭のコメントアウトを解除して$LOAD_PATHに'../lib'を追加すれば rake できる。
23
24
 
24
- * html出力
25
- * ページ一覧
26
- * 月別ページ
25
+ == todo
26
+
27
+ * viewをローカルにコピーしてくるpipinコマンドオプション
28
+ * カテゴリ
27
29
 
28
30
  == trap
29
31
 
@@ -39,4 +41,3 @@
39
41
  * exportはレンダリングされたhtmlから
40
42
  * todo: コメント...
41
43
  * todo: カテゴリなどの付属情報はxml的に...
42
-
data/lib/pipin.rb CHANGED
@@ -5,10 +5,12 @@ require 'fileutils'
5
5
  # todo: move in Pipin
6
6
  def rootdir() File.join(File.dirname(File.expand_path(__FILE__)), 'pipin') end
7
7
  def html_extname() config[:html_extname] or '.html' end
8
+ def load_plugins(dir) Dir.glob("#{dir}/*.rb").sort.each {|e| load e } end
8
9
 
9
10
  module Pipin
10
11
  Diary_pattern = '[0-9]' * 8 + '*'
11
- Post_pattern = '[0-9a-zA-Z]*'
12
+ Post_pattern = '[_0-9a-zA-Z]*'
13
+ Sitemap_pattern = '[0-9a-zA-Z]*'
12
14
 
13
15
  class Exec
14
16
  def initialize(*args)
@@ -31,12 +33,10 @@ module Pipin
31
33
  class Builder
32
34
  def initialize(dist_dir)
33
35
  @dist_dir = dist_dir
34
- load './pipinrc'
35
- setup_environment
36
36
  end
37
37
 
38
38
  def render_sitemap
39
- posts = Post.find(Post_pattern)
39
+ posts = Post.find(Sitemap_pattern)
40
40
  write_html 'sitemap', render_with_layout(:sitemap, binding)
41
41
  end
42
42
 
@@ -45,26 +45,11 @@ module Pipin
45
45
  write_html 'archives', render_with_layout(:archives, binding)
46
46
  end
47
47
 
48
- #def render_months
49
- # years = Post.year_months
50
- # years.each do |year, months|
51
- # months.each do |month|
52
- # render_month(year, month)
53
- # end
54
- # end
55
- #end
56
-
57
48
  def render_month(year, month)
58
49
  name = year + month
59
50
  render_list(name, name + '*')
60
51
  end
61
52
 
62
- #def render_posts
63
- # Post.find(Post_pattern).each do |post|
64
- # write_html post.label, render_with_layout(:post, binding)
65
- # end
66
- #end
67
-
68
53
  def render_post(label)
69
54
  post = Post.find(label).first
70
55
  write_html label, render_with_layout(:post, binding)
@@ -80,9 +65,14 @@ module Pipin
80
65
  end
81
66
 
82
67
  def write_html(label, html)
68
+ filename = label + '.html'
69
+ create_dist_file(filename, html)
70
+ end
71
+
72
+ def create_dist_file(filename, text)
83
73
  Dir.mkdir @dist_dir unless File.exist?(@dist_dir)
84
- filename = File.join(@dist_dir, label + '.html')
85
- File.open(filename, 'w') {|f| f.write html }
74
+ filename = File.join(@dist_dir, filename)
75
+ File.open(filename, 'w') {|f| f.write text }
86
76
  puts ' create ' + filename
87
77
  end
88
78
 
@@ -97,6 +87,9 @@ module Pipin
97
87
  end
98
88
 
99
89
  class Post
90
+ def self.posts_dir=(dir) @@posts_dir = dir end
91
+ def self.posts_dir() @@posts_dir end
92
+
100
93
  def self.find(pattern, options = {})
101
94
  self.find_srcs(pattern, options).map {|e| Post.new(e) }
102
95
  end
@@ -122,11 +115,6 @@ module Pipin
122
115
  @@compilers.unshift [extname, block]
123
116
  end
124
117
 
125
- @@posts_dir = 'data'
126
- def self.posts_dir=(dir)
127
- @@posts_dir = dir
128
- end
129
-
130
118
  attr_reader :filename, :header, :body
131
119
  def initialize(filename)
132
120
  @filename = filename
@@ -139,6 +127,11 @@ module Pipin
139
127
  File.basename(filename, '.*')
140
128
  end
141
129
 
130
+ def date
131
+ m = label.match(/^(\d{4})(\d{2})(\d{2})/)
132
+ m ? "#{m[1]}-#{m[2]}-#{m[3]}" : nil
133
+ end
134
+
142
135
  def to_html
143
136
  (@@compilers.assoc(File.extname filename) || @@compilers.last)[1].call(self)
144
137
  rescue
@@ -5,7 +5,9 @@ def dst_html(label)
5
5
  File.join DSTDIR, "#{label}.html"
6
6
  end
7
7
 
8
- SRCDIR = 'data'
8
+ setup_environment
9
+
10
+ SRCDIR = Pipin::Post.posts_dir
9
11
  DSTDIR = 'public'
10
12
  SRC_EXTNAMES = %w(html txt)
11
13
  EXTS = SRC_EXTNAMES.join(',')
@@ -17,7 +19,11 @@ MONTH_DSTS = Pipin::Post.year_months.map {|year, months|
17
19
  months.map {|month| dst_html(year + month) }
18
20
  }.flatten
19
21
 
20
- task :default => [:index, :archives, :months, :sitemap] + DSTS.sort.reverse
22
+ task :default => [:index, :archives, :months, :sitemap] + DSTS.sort.reverse + [:after_build]
23
+
24
+ task :after_build do
25
+ after_build
26
+ end
21
27
 
22
28
  # posts
23
29
  SRC_EXTNAMES.each do |extname|
@@ -1,3 +1,3 @@
1
1
  #$LOAD_PATH.unshift '../lib'
2
- require 'rubygems'
2
+ load './pipinrc'
3
3
  require 'pipin/build_tasks'
@@ -7,7 +7,7 @@ end
7
7
  def config
8
8
  {
9
9
  # ブログのURLに書き換えてください
10
- #:base_url => 'http://dgames.jp/pipin', # for pipinrss
10
+ :base_url => 'http://exsample.com', # for rss
11
11
  :title => 'Thie Pipin Diary',
12
12
  #:description => 'Please set config[:description] in pipinrc',
13
13
  :dir => {
@@ -53,5 +53,10 @@ def setup_environment
53
53
  $KCODE = 'UTF-8' # 1.8
54
54
  end
55
55
  add_compilers
56
- #Pipin::Post.posts_dir = config[:dir][:posts]
56
+ Pipin::Post.posts_dir = config[:dir][:posts] || './data'
57
+ load_plugins config[:dir][:plugins] || './plugins'
58
+ end
59
+
60
+ def after_build
61
+ Pipin::Exec.new('rss').build
57
62
  end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: UTF-8 -*-
2
+ def amazon(asin, opts = {})
3
+ if opts[:text]
4
+ amazon_text(asin, opts[:text])
5
+ else
6
+ amazon_img(asin)
7
+ end
8
+ end
9
+
10
+ def amazon_img(asin)
11
+ <<-HTML
12
+ <div class="amazon">
13
+ <iframe src="http://rcm-jp.amazon.co.jp/e/cm?t=#{config[:amazonid] or 'bilbo-22'}&o=9&p=8&l=as1&asins=#{asin}&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
14
+ </div>
15
+ HTML
16
+ end
17
+
18
+ def amazon_text(asin, text)
19
+ <<-HTML
20
+ <a href="http://www.amazon.co.jp/o/ASIN/#{asin}/#{config[:amazonid] or 'bilbo-22'}">#{text}</a>
21
+ HTML
22
+ end
@@ -0,0 +1,57 @@
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'rss/maker'
3
+
4
+ module Pipin
5
+ class Builder
6
+ def render_rss(options = {})
7
+ options[:limit] ||= 20
8
+ posts = Post.find(Diary_pattern, :limit => options[:limit])
9
+ rss = generate_rss(posts, options)
10
+ create_dist_file('rss', rss)
11
+ end
12
+
13
+ def generate_rss(entries, options = {})
14
+ top = config[:base_url].sub(/\/\z/, '')
15
+ RSS::Maker.make("1.0") do |maker|
16
+ entries.each do |entry|
17
+ item = maker.items.new_item
18
+ item.link = "#{top}/permalink/#{entry.label + html_extname}"
19
+ item.description = entry.rss_description
20
+ item.title = entry.rss_tile
21
+ item.content_encoded = entry.rss_body
22
+ item.date = entry.time
23
+ end
24
+ maker.channel.link = top
25
+ maker.channel.about = options[:about] || "abaout"
26
+ maker.channel.title = options[:title] || config[:title]
27
+ maker.channel.description = options[:description] || config[:description] || 'Please set config[:description] in pipinrc'
28
+ end.to_s
29
+ end
30
+ end
31
+
32
+ class Post
33
+ def rss_description(n = 128)
34
+ /^.{0,#{n}}/m.match(to_html.gsub(/(.*<\/h3>)|(<[^>]*>)|(\s+)/mi, '')).to_s + '...'
35
+ end
36
+
37
+ def rss_tile
38
+ to_html[/<h2>.*<\/h2>/i].to_s.gsub(/<[^>]*>/, '')
39
+ end
40
+
41
+ def rss_body
42
+ to_html
43
+ end
44
+
45
+ def time
46
+ Time.parse(date.to_s)
47
+ end
48
+ end
49
+ end
50
+
51
+ if __FILE__ == $0
52
+ $LOAD_PATH.unshift '../lib'
53
+ require 'pipin'
54
+ load './pipinrc'
55
+ setup_environment
56
+ Pipin::Exec.new("rss").build
57
+ end
@@ -0,0 +1,3 @@
1
+ def eval_hiki_plugin(html)
2
+ html.gsub(/<(div|span) class=\"plugin\">\{\{(.+)\}\}<\/(div|span)>/) { eval($2) }
3
+ end
@@ -46,12 +46,12 @@ div.footer {
46
46
  text-align: center;
47
47
  }
48
48
 
49
- div.entry {
49
+ div.post {
50
50
  margin: 2em 0;
51
51
  }
52
52
 
53
- div.before_entry,
54
- div.after_entry {
53
+ div.before_post,
54
+ div.after_post {
55
55
  margin: 0;
56
56
  padding: 0;
57
57
  text-align: right;
@@ -101,6 +101,7 @@ blockquote {
101
101
  div.date {
102
102
  font-weight: bold;
103
103
  color: #666;
104
+ text-align: right;
104
105
  }
105
106
 
106
107
  a { color: #04f; }
data/lib/pipin/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pipin
2
- VERSION = "0.1.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -11,10 +11,11 @@
11
11
  %body
12
12
  .header
13
13
  %h1&= config[:title]
14
+ .description= config[:description]
14
15
  .menus
15
- %a{:href => '' + html_extname} Latest
16
- %a{:href => 'archives' + html_extname} Archives
17
- %a{:href => 'about' + html_extname} About
16
+ %a{:href => './'} Latest
17
+ %a{:href => './archives' + html_extname} Archives
18
+ %a{:href => './about' + html_extname} About
18
19
  .main
19
20
  =# render_plugin_hook(:flavour_header, self)
20
21
  .content
@@ -1,7 +1,7 @@
1
1
  .before_entries
2
2
  - posts.each do |post|
3
3
  .post
4
- .date 2000-00-00
4
+ .date= post.date
5
5
  .body~ post.to_html
6
6
  .permalink
7
7
  %a{:href => post.label + html_extname} permalink
@@ -1,7 +1,8 @@
1
1
  .post
2
2
  .before_post
3
- .date 2000-00-00
3
+ - if post.date
4
+ .date= post.date
4
5
  .body~ post.to_html
5
- .permalink
6
- %a{:href => post.label + html_extname} permalink
7
6
  .after_post
7
+ .permalink
8
+ %a{:href => post.label + html_extname} permalink
data/script/pipin ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'pipin'
5
+ rescue LoadError # for development
6
+ $LOAD_PATH.unshift File.dirname(File.expand_path(__FILE__)) + '/../lib'
7
+ require 'pipin'
8
+ end
9
+
10
+ case ARGV.shift
11
+ when '--version', '-v'
12
+ puts "Pipin #{Pipin::VERSION}"
13
+ when 'new', 'n'
14
+ dir = ARGV.shift || raise("Options should be given after the application name")
15
+ Pipin::Exec.new(dir).create_from_template
16
+ else
17
+ puts <<__USAGE__
18
+ Usage:
19
+ pipin new BLOG_PATH [options]
20
+
21
+ Options:
22
+
23
+ Pipin options:
24
+ -v, [--version] # Show Pipin version number and quit
25
+
26
+ Example:
27
+ pipin new ~/myblog
28
+
29
+ Create a new pipin blog. "pipin new ~/myblog" creates a
30
+ new blog files in "~/myblog".
31
+ __USAGE__
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-15 00:00:00.000000000Z
12
+ date: 2012-03-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: simple blog system
15
15
  email:
@@ -33,6 +33,9 @@ files:
33
33
  - lib/pipin/templates/data/about.txt
34
34
  - lib/pipin/templates/data/hello.src
35
35
  - lib/pipin/templates/pipinrc
36
+ - lib/pipin/templates/plugins/amazon.rb
37
+ - lib/pipin/templates/plugins/genarate_rss.rb
38
+ - lib/pipin/templates/plugins/use_hiki_plugin.rb
36
39
  - lib/pipin/templates/public/stylesheets/pipin.css
37
40
  - lib/pipin/version.rb
38
41
  - lib/pipin/views/archives.haml
@@ -41,6 +44,7 @@ files:
41
44
  - lib/pipin/views/post.haml
42
45
  - lib/pipin/views/sitemap.haml
43
46
  - pipin.gemspec
47
+ - script/pipin
44
48
  homepage: https://github.com/dan5/pipin
45
49
  licenses: []
46
50
  post_install_message:
@@ -61,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
65
  version: '0'
62
66
  requirements: []
63
67
  rubyforge_project: pipin
64
- rubygems_version: 1.8.5
68
+ rubygems_version: 1.8.11
65
69
  signing_key:
66
70
  specification_version: 3
67
71
  summary: blog