piki_doc 0.0.2.2

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,12 @@
1
+ == 0.0.2.2 / 2011-01-18
2
+
3
+ * fix some HTML output bugs, thanx mayuco.
4
+
5
+ == 0.0.2.1 / 2009-04-30
6
+
7
+ * fake version up to genarate gem on GitHub.
8
+
9
+ == 0.0.1 / 2009-04-20
10
+
11
+ * initial release
12
+
@@ -0,0 +1,71 @@
1
+ ! PikiDocについて
2
+
3
+ !! はじめに
4
+
5
+ [[HikiDoc|http://hikidoc.rubyforge.org/svn/trunk/README.ja]]を拡張し、
6
+ HikiDocの機能の一つである「プラグイン」機能を簡単にを追加できるようにした
7
+ ライブラリです。
8
+
9
+ 本家HikiDocライブラリもバンドルしているため、このライブラリを入れるだけで
10
+ 使えます。
11
+
12
+ !! 使い方
13
+
14
+ プラグインを追加する部分以外は、本家の機能がそのまま使えます。
15
+
16
+ require 'piki_doc'
17
+ PikiDoc.to_xhtml(<<-EOS
18
+ ! PikiDocについて
19
+
20
+ !! はじめに
21
+ EOS
22
+
23
+ !!! プラグインの使い方
24
+
25
+ あらかじめPikiDoc.register()にプラグインを指定してください。今のところ、Gist
26
+ プラグインとASINプラグインがバンドルされています。
27
+
28
+ PikiDoc.register(PikiDoc::Bundles::Gist.new, PikiDoc::Bundles::Asin.new)
29
+ PikiDoc.to_xhtml(<<-HTML)
30
+ !!!! ASIN
31
+
32
+ インライン {{asin('4797336625', 'morodiary05-22')}}
33
+
34
+ {{asin('4797336625', 'morodiary05-22')}}
35
+
36
+ !!!! Gist
37
+
38
+ インライン {{gist('88086')}}
39
+
40
+ {{gist('88086')}}
41
+ HTML
42
+
43
+ 次のように出力されます
44
+
45
+ !!!! ASIN
46
+
47
+ インライン {{asin('4797336625', 'morodiary05-22')}}
48
+
49
+ {{asin('4797336625', 'morodiary05-22')}}
50
+
51
+ !!!! Gist
52
+
53
+ インライン {{gist(88086)}}
54
+
55
+ {{gist(88086)}}
56
+
57
+ !! プラグインの自作方法
58
+
59
+ lib/piki_doc/bundles/内のサンプルと、features/*内の外部仕様を参考にしてください。
60
+
61
+ !! Thanks
62
+
63
+ !!! HikiDoc authors
64
+
65
+ - 2005, Kazuhiko <kazuhiko@fdiary.net>
66
+ - 2007, Minero Aoki
67
+
68
+ !! ライセンス
69
+
70
+ HikiDoc本家と同じ修正BSDライセンスです。
71
+
@@ -0,0 +1,98 @@
1
+ $: << "./lib"
2
+ require 'rubygems'
3
+ require 'piki_doc'
4
+
5
+ require 'rake/clean'
6
+ require 'rake/testtask'
7
+ require 'rake/packagetask'
8
+ require 'rake/gempackagetask'
9
+ require 'rspec/core/rake_task'
10
+ require 'cucumber/rake/task'
11
+
12
+ NAME = ENV["GEMNAME"] || "piki_doc"
13
+ HOMEPAGE = "http://github.com/moro/#{NAME}/"
14
+ AUTHOR = "MOROHASHI Kyosuke"
15
+ EMAIL = "moronatural@gmail.com"
16
+ DESCRIPTION = "extended HikiDoc to able to plug plugins."
17
+ VERS = PikiDoc::Version
18
+
19
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
20
+ RDOC_OPTS = [
21
+ '--title', "#{NAME} documentation",
22
+ "--charset", "utf-8",
23
+ "--opname", "index.html",
24
+ "--line-numbers",
25
+ "--main", "README.ja.hiki",
26
+ "--inline-source",
27
+ ]
28
+
29
+ RSpec::Core::RakeTask.new do |t|
30
+ t.ruby_opts = "-w"
31
+ t.rspec_opts = %w[--format progress --color]
32
+ end
33
+
34
+ Cucumber::Rake::Task.new do |t|
35
+ t.cucumber_opts = "--format progress"
36
+ end
37
+
38
+ gemspec = Gem::Specification.new do |s|
39
+ s.name = NAME
40
+ s.version = VERS
41
+ s.platform = Gem::Platform::RUBY
42
+ s.has_rdoc = false
43
+ s.extra_rdoc_files = ["README.ja.hiki", "Changelog"]
44
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
45
+ s.summary = DESCRIPTION
46
+ s.description = DESCRIPTION
47
+ s.author = AUTHOR
48
+ s.email = EMAIL
49
+ s.homepage = HOMEPAGE
50
+ s.executables = []
51
+ s.require_path = "lib"
52
+ s.test_files = Dir["spec/**/*_spec.rb"] + Dir["features/**/*.rb"] + Dir["features/*.feature"]
53
+
54
+ s.files = %w(README.ja.hiki Changelog Rakefile) +
55
+ Dir.glob("{bin,doc,lib,templates,generators,extras,website,script}/**/*") +
56
+ Dir.glob("ext/**/*.{h,c,rb}") +
57
+ Dir.glob("examples/**/*.rb") +
58
+ Dir.glob("tools/*.rb") +
59
+ Dir.glob("rails/*.rb")
60
+
61
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
62
+ end
63
+
64
+ Rake::GemPackageTask.new(gemspec) do |p|
65
+ p.need_tar = true
66
+ p.gem_spec = gemspec
67
+ end
68
+
69
+ task :install do
70
+ name = "#{NAME}-#{VERS}.gem"
71
+ sh %{rake package}
72
+ sh %{gem install pkg/#{name}}
73
+ end
74
+
75
+ task :uninstall => [:clean] do
76
+ sh %{gem uninstall #{NAME}}
77
+ end
78
+
79
+ desc 'Show information about the gem.'
80
+ task :debug_gem do
81
+ puts gemspec.to_ruby
82
+ end
83
+
84
+ desc 'Update gem spec'
85
+ task :gemspec do
86
+ open("#{NAME}.gemspec", 'w').write gemspec.to_ruby
87
+ end
88
+
89
+ desc "output example from README.ja.hiki"
90
+ task "readme_example" do
91
+ require 'piki_doc'
92
+ require 'piki_doc/bundles/gist'
93
+ require 'piki_doc/bundles/asin'
94
+
95
+ PikiDoc.register(PikiDoc::Bundles::Gist.new, PikiDoc::Bundles::Asin.new)
96
+ puts PikiDoc.to_xhtml(File.read("README.ja.hiki"))
97
+ end
98
+
@@ -0,0 +1,25 @@
1
+ # language: ja
2
+ フィーチャ: Asinプラグインを試す
3
+ プラグイン作者として
4
+ Asinプラグインがちゃんと動いていることを確認したい
5
+
6
+ 背景:
7
+ 前提 "Asin"プラグインを登録する
8
+
9
+ シナリオ: ブロックプラグイン
10
+ もし 以下のHiki記法テキストをXHTMLにする
11
+ """
12
+ ! ASIN Railsレシピブック
13
+ {{asin('4797336625', 'morodiary05-22')}}
14
+ """
15
+ # かつ 結果を目視
16
+ ならば "div.plugin.asin > iframe"要素が含まれること
17
+
18
+ シナリオ: インラインプラグイン
19
+ もし 以下のHiki記法テキストをXHTMLにする
20
+ """
21
+ Railsレシピブック {{asin('4797336625', 'morodiary05-22')}}を書きました。
22
+ """
23
+ # かつ 結果を目視
24
+ ならば "span.plugin.asin > a[href='http://www.amazon.co.jp/exec/obidos/ASIN/4797336625/morodiary05-22/ref=nosim']"要素が含まれること
25
+
@@ -0,0 +1,28 @@
1
+ # language: ja
2
+ フィーチャ: Gistプラグインを試す
3
+ プラグイン作者として
4
+ Gistプラグインがちゃんと動いていることを確認したい
5
+
6
+ 背景:
7
+ 前提 "Gist"プラグインを登録する
8
+
9
+ シナリオ: ブロックプラグイン
10
+ もし 以下のHiki記法テキストをXHTMLにする
11
+ """
12
+ ! Gist
13
+ {{gist(123456)}}
14
+ """
15
+ # かつ 結果を目視
16
+ ならば "div.plugin.gist > script[src='http://gist.github.com/123456.js']"要素が含まれること
17
+ かつ "h1"要素のテキストは"Gist"であること
18
+
19
+ シナリオ: インラインプラグイン
20
+ もし 以下のHiki記法テキストをXHTMLにする
21
+ """
22
+ ! Gist
23
+ こちらをご覧ください。{{gist(123456)}}
24
+ """
25
+ # かつ 結果を目視
26
+ ならば "a[href='http://gist.github.com/123456']"要素が含まれること
27
+ かつ "h1"要素のテキストは"Gist"であること
28
+
@@ -0,0 +1,28 @@
1
+ #coding:utf-8
2
+ require 'piki_doc'
3
+ require 'piki_doc/bundles/gist'
4
+ require 'piki_doc/bundles/asin'
5
+ require 'nokogiri'
6
+
7
+ When /^"([^\"]*)"プラグインを登録する$/ do |name|
8
+ PikiDoc.register(PikiDoc::Bundles.const_get(name).new)
9
+ end
10
+
11
+ When /^以下のHiki記法テキストをXHTMLにする$/ do |text|
12
+ @out = PikiDoc.to_xhtml(text)
13
+ end
14
+
15
+ Then /^"([^\"]*)"要素が含まれること$/ do |selector|
16
+ @doc ||= Nokogiri::HTML(@out)
17
+ @doc.css(selector).should_not be_empty
18
+ end
19
+
20
+ When /^"([^\"]*)"要素のテキストは"([^\"]*)"であること$/ do |selector, text|
21
+ @doc ||= Nokogiri::HTML(@out)
22
+ @doc.css(selector).text.should == text
23
+ end
24
+
25
+ When /^結果を目視$/ do
26
+ at_exit{ ["-" * 80, @out, "-" * 80].each{|s| puts s } }
27
+ end
28
+
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+ $KCODE = "u" if RUBY_VERSION < "1.9"
3
+
4
+ $LOAD_PATH << File.expand_path("../../lib", File.dirname(__FILE__))
5
+
@@ -0,0 +1,11 @@
1
+
2
+ module PikiDoc
3
+ Version = "0.0.2.2"
4
+
5
+ autoload "Document", "piki_doc/document"
6
+ def register(*plugins); PikiDoc::Document.register(*plugins); end
7
+ def to_html(src, options={}); PikiDoc::Document.to_html(src, options) ; end
8
+ def to_xhtml(src, options={}); PikiDoc::Document.to_xhtml(src, options) ; end
9
+ module_function :register, :to_html, :to_xhtml
10
+ end
11
+
@@ -0,0 +1,25 @@
1
+ module PikiDoc
2
+ module Bundles
3
+ class Asin
4
+ include PluginAdapter
5
+ def initialize(host = "www.amazon.co.jp", iframe_host = "rcm-jp.amazon.co.jp")
6
+ @host = host
7
+ @iframe_host = iframe_host
8
+ end
9
+
10
+ def inline_plugin(src)
11
+ (asin, id), = src.scan(/\(\s*'(\d+)',\s*'([a-z0-9\-]+)'\s*\)/)
12
+ plugin_dom("span", <<-HTML)
13
+ <a href="http://#{@host}/exec/obidos/ASIN/#{asin}/#{id}/ref=nosim">Amazon</a>
14
+ HTML
15
+ end
16
+ def block_plugin(src)
17
+ (asin, id), = src.scan(/\(\s*'(\d+)',\s*'([a-z0-9\-]+)'\s*\)/)
18
+ plugin_dom("div", <<-HTML)
19
+ <iframe src="http://#{@iframe_host}/e/cm?t=#{id}&o=9&p=8&l=as1&asins=#{asin}&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr&nou=1"
20
+ style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
21
+ HTML
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ require 'piki_doc/bundles/plugin_adapter'
2
+
3
+ module PikiDoc
4
+ module Bundles
5
+ class Gist
6
+ include PluginAdapter
7
+ def inline_plugin(src)
8
+ (id,), = src.scan(/gist\((\d+)\)/)
9
+ %Q[<a href="http://gist.github.com/#{id}">Gist:#{id}</a>]
10
+ end
11
+
12
+ private
13
+ def plugin(src)
14
+ (id,), = src.scan(/gist\((\d+)\)/)
15
+ %Q[<script src="http://gist.github.com/#{id}.js"></script>]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ module PikiDoc
2
+ module Bundles
3
+ module PluginAdapter
4
+ RE = /\A([a-z]+)\(.[^\)]+\)/
5
+ def accept?(src)
6
+ (name,_), = src.scan(RE)
7
+ name == plugin_name
8
+ end
9
+
10
+ def inline_plugin(src)
11
+ plugin_dom("span", plugin(src))
12
+ end
13
+
14
+ def block_plugin(src)
15
+ plugin_dom("div", plugin(src))
16
+ end
17
+
18
+ private
19
+ def plugin(src); raise NotImplementedError; end
20
+
21
+ def plugin_name
22
+ self.class.name.split("::").last.
23
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
24
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
25
+ downcase
26
+ end
27
+
28
+ def plugin_dom(tag, content)
29
+ %Q[<#{tag} class='plugin #{plugin_name}'>#{content}</#{tag}>]
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,32 @@
1
+ require 'uri'
2
+ require 'piki_doc/output'
3
+ require 'piki_doc/image_uri_autolink_fix'
4
+ require 'vendor/hikidoc'
5
+
6
+ module PikiDoc
7
+ class Document < ::HikiDoc
8
+ @@plugins ||= []
9
+ include ImageUriAutolinkFix
10
+
11
+ class << self
12
+ def plugins; @@plugins; end
13
+ def register(*plugins)
14
+ @@plugins.concat(plugins)
15
+ end
16
+
17
+ def lint(plugin)
18
+ [:inline_plugin, :block_plugin].any?{|m| plugin.respond_to?(m) } && \
19
+ plugin.respond_to?(:accept?)
20
+ end
21
+
22
+ def to_xhtml(src, options = {})
23
+ new(::PikiDoc::HTMLOutput.new(" />", @@plugins), options).compile(src)
24
+ end
25
+
26
+ def to_html(src, options = {})
27
+ new(::PikiDoc::HTMLOutput.new(">", @@plugins), options).compile(src)
28
+ end
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,12 @@
1
+ module PikiDoc
2
+ module ImageUriAutolinkFix
3
+ private
4
+ def compile_uri_autolink(uri)
5
+ if(image?(path = URI(uri).path))
6
+ @output.image_hyperlink(uri, path.split(/\//).last)
7
+ else
8
+ super
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ require 'vendor/hikidoc'
2
+
3
+ module PikiDoc
4
+ class HTMLOutput < ::HikiDoc::HTMLOutput
5
+ def initialize(suffix, plugins)
6
+ super(suffix)
7
+ @inlines = plugins.select{|p| p.respond_to?(:inline_plugin) }
8
+ @blocks = plugins.select{|p| p.respond_to?(:block_plugin) }
9
+ end
10
+
11
+ def inline_plugin(src)
12
+ if plugin = @inlines.detect{|p| p.accept?(src) }
13
+ plugin.inline_plugin(src)
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ def block_plugin(src)
20
+ if plugin = @blocks.detect{|p| p.accept?(src) }
21
+ @f.puts plugin.block_plugin(src)
22
+ else
23
+ super
24
+ end
25
+ end
26
+ end
27
+ end