snippr 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ == 0.3.0 (2010-07-05)
2
+ * Added support for links in wiki syntax:
3
+
4
+ [[http://www.blaulabs.de|blaulabs]]
5
+
6
+ will be converted to:
7
+
8
+ <a href="http://www.blaulabs.de">blaulabs</a>
9
+
1
10
  == 0.2.0 (2010-05-13)
2
11
  * Added support for I18n snippr files. Simply enable I18n:
3
12
 
data/README.rdoc CHANGED
@@ -56,6 +56,16 @@ prefixed with a "_" to your snippr files.
56
56
 
57
57
  I18n.locale = :en
58
58
  Snippr.load :shop # tries to load "shop_en.snip" relative to your Snippr path
59
+
60
+ == Wiki Syntax
61
+
62
+ Until now, only wiki links with text are supported by Snippr:
63
+
64
+ [[http://www.blaulabs.de|blaulabs]]
65
+
66
+ will be converted to:
67
+
68
+ <a href="http://www.blaulabs.de">blaulabs</a>
59
69
 
60
70
  == Rails Helper
61
71
 
@@ -0,0 +1,26 @@
1
+ # = Snippr::Link
2
+ #
3
+ # Extends the Snippr module adding support for link helpers like wiki links.
4
+ module Snippr
5
+ module Link
6
+
7
+ # Regex for links in wiki syntax (eg. [[http://www.google.de|google]]).
8
+ WikiLink = /\[\[([^|]+)\|([^\]]+)\]\]/
9
+
10
+ # Pattern for general link tags.
11
+ HtmlLink = '<a href="\1">\2</a>'
12
+
13
+ # Convert all links to html links (eg. wiki links to html links).
14
+ def linkify(content)
15
+ convert_wiki_links content
16
+ end
17
+
18
+ private
19
+
20
+ # Convert wiki links to html links
21
+ def convert_wiki_links(content)
22
+ content.gsub WikiLink, HtmlLink
23
+ end
24
+
25
+ end
26
+ end
data/lib/snippr/snippr.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "snippr/core_ext"
2
2
  require "snippr/path"
3
3
  require "snippr/i18n"
4
+ require "snippr/link"
4
5
 
5
6
  # = Snippr
6
7
  # ==== File based content management
@@ -10,6 +11,7 @@ require "snippr/i18n"
10
11
  module Snippr
11
12
  extend Snippr::Path
12
13
  extend Snippr::I18n
14
+ extend Snippr::Link
13
15
 
14
16
  class << self
15
17
 
@@ -22,6 +24,7 @@ module Snippr
22
24
  # The fallback tag for a missing snippr.
23
25
  MissingSnipprTag = '<samp class="missing snippr" />'
24
26
 
27
+
25
28
  # Expects the name of a snippr file. Also accepts a Hash of placeholders
26
29
  # to be replaced with dynamic values.
27
30
  def load(*args)
@@ -44,7 +47,7 @@ module Snippr
44
47
 
45
48
  content = File.read(file).strip
46
49
  insert_dynamics content
47
- content
50
+ linkify content
48
51
  end
49
52
 
50
53
  # Returns the complete path to a snippr file.
@@ -0,0 +1 @@
1
+ <p>Click [[http://www.blaulabs.de|here with blanks]].</p>
@@ -46,6 +46,13 @@ describe Snippr do
46
46
  "<samp class=\"missing snippr\" />\n" <<
47
47
  "<!-- closing snippr: doesnotexist -->"
48
48
  end
49
+
50
+ it "should convert wiki links to html links" do
51
+ Snippr.load(:wiki).should ==
52
+ "<!-- starting snippr: wiki -->\n" <<
53
+ "<p>Click <a href=\"http://www.blaulabs.de\">here with blanks</a>.</p>\n" <<
54
+ "<!-- closing snippr: wiki -->"
55
+ end
49
56
 
50
57
  describe "I18n" do
51
58
  before { Snippr.i18n = true }
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snippr
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 2
8
+ - 3
8
9
  - 0
9
- version: 0.2.0
10
+ version: 0.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Daniel Harrington
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-13 00:00:00 +02:00
18
+ date: 2010-07-05 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: i18n
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -33,9 +36,11 @@ dependencies:
33
36
  name: rspec
34
37
  prerelease: false
35
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
36
40
  requirements:
37
41
  - - ">="
38
42
  - !ruby/object:Gem::Version
43
+ hash: 15
39
44
  segments:
40
45
  - 1
41
46
  - 2
@@ -55,22 +60,24 @@ files:
55
60
  - CHANGELOG
56
61
  - Rakefile
57
62
  - README.rdoc
58
- - lib/snippr/core_ext.rb
63
+ - lib/snippr.rb
64
+ - lib/snippr/snippr.rb
59
65
  - lib/snippr/helper.rb
60
- - lib/snippr/i18n.rb
61
66
  - lib/snippr/path.rb
62
- - lib/snippr/snippr.rb
63
- - lib/snippr.rb
67
+ - lib/snippr/core_ext.rb
68
+ - lib/snippr/link.rb
69
+ - lib/snippr/i18n.rb
64
70
  - rails/init.rb
65
- - spec/snippr/core_ext_spec.rb
66
71
  - spec/snippr/snippr_spec.rb
72
+ - spec/snippr/core_ext_spec.rb
67
73
  - spec/spec_helper.rb
68
- - spec/fixtures/home.snip
69
- - spec/fixtures/i18n/shop_de.snip
70
- - spec/fixtures/i18n/shop_en.snip
71
- - spec/fixtures/tariff/einheit.snip
72
74
  - spec/fixtures/topup/someError.snip
73
75
  - spec/fixtures/topup/success.snip
76
+ - spec/fixtures/wiki.snip
77
+ - spec/fixtures/tariff/einheit.snip
78
+ - spec/fixtures/i18n/shop_de.snip
79
+ - spec/fixtures/i18n/shop_en.snip
80
+ - spec/fixtures/home.snip
74
81
  has_rdoc: true
75
82
  homepage: http://github.com/blaulabs/snippr
76
83
  licenses: []
@@ -85,27 +92,31 @@ rdoc_options:
85
92
  require_paths:
86
93
  - lib
87
94
  required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
88
96
  requirements:
89
97
  - - ">="
90
98
  - !ruby/object:Gem::Version
99
+ hash: 3
91
100
  segments:
92
101
  - 0
93
102
  version: "0"
94
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
95
105
  requirements:
96
106
  - - ">="
97
107
  - !ruby/object:Gem::Version
108
+ hash: 3
98
109
  segments:
99
110
  - 0
100
111
  version: "0"
101
112
  requirements: []
102
113
 
103
114
  rubyforge_project:
104
- rubygems_version: 1.3.6
115
+ rubygems_version: 1.3.7
105
116
  signing_key:
106
117
  specification_version: 3
107
118
  summary: File based content management
108
119
  test_files:
109
- - spec/snippr/core_ext_spec.rb
110
120
  - spec/snippr/snippr_spec.rb
121
+ - spec/snippr/core_ext_spec.rb
111
122
  - spec/spec_helper.rb