wikicloth 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ end
25
25
 
26
26
  spec = Gem::Specification.new do |s|
27
27
  s.name = "wikicloth"
28
- s.version = %q{0.1.4}
28
+ s.version = %q{0.1.5}
29
29
  s.author = "David Ricciardi"
30
30
  s.email = "nricciar@gmail.com"
31
31
  s.homepage = "http://github.com/nricciar/wikicloth"
@@ -0,0 +1,69 @@
1
+ module WikiCloth
2
+
3
+ class Parser < WikiLinkHandler
4
+
5
+ def initialize(opt={})
6
+ opt.each { |k,v|
7
+ if v.instance_of?(Proc)
8
+ self.class.send :define_method, k.to_sym do |*args|
9
+ v.call(args)
10
+ end
11
+ end
12
+ }
13
+ @params = opt[:params] || {}
14
+ @wikicloth = WikiCloth.new(:data => opt[:data], :link_handler => self, :params => @params)
15
+ end
16
+
17
+ class << self
18
+ def url_for(&block)
19
+ self.send :define_method, 'url_for' do |url|
20
+ block.call(url)
21
+ end
22
+ end
23
+
24
+ def external_link(&block)
25
+ self.send :define_method, 'external_link' do |url,text|
26
+ block.call(url,text)
27
+ end
28
+ end
29
+
30
+ def include_resource(&block)
31
+ self.send :define_method, 'include_resource' do |resource,options|
32
+ options ||= []
33
+ block.call(resource,options)
34
+ end
35
+ end
36
+
37
+ def link_for_resource(&block)
38
+ self.send :define_method, 'link_for_resource' do |prefix,resource,options|
39
+ options ||= []
40
+ block.call(prefix,resource,options)
41
+ end
42
+ end
43
+
44
+ def template(&block)
45
+ self.send :define_method, 'template' do |template|
46
+ block.call(template)
47
+ end
48
+ end
49
+
50
+ def link_for(&block)
51
+ self.send :define_method, 'link_for' do |page,text|
52
+ block.call(page,text)
53
+ end
54
+ end
55
+
56
+ def link_attributes_for(&block)
57
+ self.send :define_method, 'link_attributes_for' do |page|
58
+ block.call(page)
59
+ end
60
+ end
61
+ end
62
+
63
+ def to_html
64
+ @wikicloth.to_html
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -17,7 +17,7 @@ class WikiLinkHandler
17
17
  @params ||= {}
18
18
  end
19
19
 
20
- def include_template(template)
20
+ def template(template)
21
21
  nil
22
22
  end
23
23
 
data/lib/wikicloth.rb CHANGED
@@ -2,6 +2,7 @@ require 'jcode'
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), "wikicloth", "core_ext")
3
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "wikicloth", "wiki_buffer")
4
4
  require File.join(File.expand_path(File.dirname(__FILE__)), "wikicloth", "wiki_link_handler")
5
+ require File.join(File.expand_path(File.dirname(__FILE__)), "wikicloth", "parser")
5
6
  String.send(:include, ExtendedString)
6
7
 
7
8
  module WikiCloth
@@ -15,14 +16,14 @@ module WikiCloth
15
16
 
16
17
  def load(data,p={})
17
18
  data.gsub!(/<!--(.|\s)*?-->/,"")
18
- data = data.gsub(/\{\{(.*?)\}\}/){ |match| expand_templates($1,["."]) }
19
+ data = data.gsub(/^[^\s]*\{\{(.*?)\}\}/){ |match| expand_templates($1,["."]) }
19
20
  self.params = p
20
21
  self.html = data
21
22
  end
22
23
 
23
24
  def expand_templates(template, stack)
24
25
  template.strip!
25
- article = self.link_handler.include_template(template)
26
+ article = link_handler.template(template)
26
27
 
27
28
  if article.nil?
28
29
  data = "{{template}}"
@@ -32,7 +33,7 @@ module WikiCloth
32
33
  else
33
34
  data = "template loop! OHNOES!"
34
35
  end
35
- data = data.gsub(/\{\{(.*?)\}\}/){ |match| expand_templates($1,stack + [template])}
36
+ data = data.gsub(/^[^\s]*\{\{(.*?)\}\}/){ |match| expand_templates($1,stack + [template])}
36
37
  end
37
38
 
38
39
  data
data/run_tests.rb CHANGED
@@ -19,7 +19,7 @@ class CustomLinkHandler < WikiLinkHandler
19
19
  end
20
20
  end
21
21
  @wiki = WikiCloth::WikiCloth.new({
22
- :data => "<nowiki>{{test}}</nowiki> ''Hello {{test}}!''\n",
22
+ :data => "\n {{test}}\n\n<nowiki>{{test}}</nowiki> ''Hello {{test}}!''\n",
23
23
  :params => { "test" => "World" } })
24
24
  puts @wiki.to_html
25
25
  @wiki = WikiCloth::WikiCloth.new({
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikicloth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Ricciardi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-05 00:00:00 -04:00
18
+ date: 2010-08-10 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -29,31 +29,32 @@ extra_rdoc_files:
29
29
  - README
30
30
  - MIT-LICENSE
31
31
  files:
32
+ - lib/wikicloth.rb
33
+ - lib/wikicloth/wiki_buffer.rb
34
+ - lib/wikicloth/parser.rb
32
35
  - lib/wikicloth/core_ext.rb
33
- - lib/wikicloth/wiki_buffer/html_element.rb
34
- - lib/wikicloth/wiki_buffer/link.rb
35
36
  - lib/wikicloth/wiki_buffer/table.rb
37
+ - lib/wikicloth/wiki_buffer/html_element.rb
36
38
  - lib/wikicloth/wiki_buffer/var.rb
37
- - lib/wikicloth/wiki_buffer.rb
39
+ - lib/wikicloth/wiki_buffer/link.rb
38
40
  - lib/wikicloth/wiki_link_handler.rb
39
- - lib/wikicloth.rb
40
41
  - tasks/wikicloth_tasks.rake
41
- - sample_documents/air_force_one.wiki
42
- - sample_documents/cheatsheet.wiki
43
- - sample_documents/elements.wiki
44
42
  - sample_documents/george_washington.wiki
45
- - sample_documents/images.wiki
46
- - sample_documents/lists.wiki
47
43
  - sample_documents/pipe_trick.wiki
48
44
  - sample_documents/random.wiki
49
45
  - sample_documents/tv.wiki
46
+ - sample_documents/air_force_one.wiki
47
+ - sample_documents/lists.wiki
48
+ - sample_documents/images.wiki
49
+ - sample_documents/elements.wiki
50
50
  - sample_documents/wiki_tables.wiki
51
+ - sample_documents/cheatsheet.wiki
51
52
  - init.rb
52
53
  - uninstall.rb
53
54
  - Rakefile
54
55
  - install.rb
55
- - test/test_helper.rb
56
56
  - test/wiki_cloth_test.rb
57
+ - test/test_helper.rb
57
58
  - run_tests.rb
58
59
  - README
59
60
  - MIT-LICENSE
@@ -92,6 +93,6 @@ signing_key:
92
93
  specification_version: 3
93
94
  summary: An implementation of the mediawiki markup in ruby
94
95
  test_files:
95
- - test/test_helper.rb
96
96
  - test/wiki_cloth_test.rb
97
+ - test/test_helper.rb
97
98
  - run_tests.rb