ciridiri 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,8 @@ module Ciridiri
15
15
  # Return an array of all `Page`s excluding backups
16
16
  def all
17
17
  Dir.chdir(content_dir) do
18
- files = Dir.glob(File.join("**", "*#{SOURCE_FILE_EXT}")).delete_if {|p| p =~ Regexp.new("\\.[0-9]+\\#{SOURCE_FILE_EXT}$")}
18
+ files = Dir.glob(File.join("**", "*#{Ciridiri::SOURCE_FILE_EXT}")).
19
+ delete_if {|p| p =~ Regexp.new("\\.[0-9]+\\#{Ciridiri::SOURCE_FILE_EXT}$")}
19
20
  files.collect {|f| Page.new(uri_from_path(f), File.open(f, 'r') {|b| b.read})}
20
21
  end
21
22
  end
data/lib/ciridiri/page.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  require 'fileutils'
2
2
  dir = File.dirname(__FILE__)
3
- %w[finders paths extensions].each {|r| require File.join(dir, r)}
3
+ %w[extensions paths finders].each {|r| require File.join(dir, r)}
4
4
 
5
5
  module Ciridiri
6
- class Page
7
- extend Ciridiri::Finders, Ciridiri::Paths
8
- ###Constants block
6
+ ### Constants
9
7
 
10
8
  # A regular expression for markdown like headers (`#`, `##`, `###`, `=====`, `----`)
11
9
  MD_TITLE = Regexp.new("(^\#{1,3}\\s*?([^#].*?)#*$)|(^ {0,3}(\\S.*?)\\n(?:=|-)+(?=\\n+|\\Z))", Regexp::MULTILINE)
@@ -16,7 +14,10 @@ module Ciridiri
16
14
  SOURCE_FILE_EXT = ".text".freeze
17
15
  CACHED_FILE_EXT = ".html".freeze
18
16
 
19
- ###Default values for all options
17
+ class Page
18
+ include Ciridiri
19
+ extend Ciridiri::Finders, Ciridiri::Paths
20
+ ### Default values for all options
20
21
 
21
22
  # Where pages should be stored on a file system
22
23
  @@content_dir = '.'
@@ -1,11 +1,24 @@
1
+ require 'pathname'
2
+
1
3
  module Ciridiri
2
4
  module Paths
3
5
  # Convert `uri` to `path` in a file system including `content_dir` and a source file extension
4
6
  # `/team/pro/chuck-norris` -> `content_dir/team/pro/chuck-norris.text`
5
7
  def path_from_uri(uri)
6
- path = uri.split("/")
8
+ path = uri.split('/')
7
9
  filename = path.pop
8
- File.join(content_dir, path, "#{filename}#{Page::SOURCE_FILE_EXT}")
10
+ File.join(content_dir, path, "#{filename}#{Ciridiri::SOURCE_FILE_EXT}")
11
+ end
12
+
13
+ # Convert `path` to `uri`
14
+ # `content_dir/team/pro/chuck-norris.text` -> `/team/pro/chuck-norris`
15
+ def uri_from_path(path)
16
+ path = File.absolute_path(path)
17
+ relative_path = Pathname.new(path).relative_path_from(Pathname(content_dir)).to_s
18
+ relative_uri = relative_path.gsub(File::Separator, '/').
19
+ gsub(Regexp.new("#{Ciridiri::SOURCE_FILE_EXT}$"), '')
20
+
21
+ "/#{relative_uri}"
9
22
  end
10
23
 
11
24
  end
data/test/page_test.rb CHANGED
@@ -49,6 +49,16 @@ class PageTest < Test::Unit::TestCase
49
49
  assert_not_nil Page.find_by_uri_or_empty('nonexistent-uri')
50
50
  end
51
51
 
52
+ should "return all pages" do
53
+ page_1, page_2 = page_stub('/page_1'), page_stub('/page_2')
54
+ page_1.save
55
+ page_2.save
56
+
57
+ assert_equal 2, Page.all.length
58
+ assert_not_nil Page.all.detect {|p| p.uri == page_1.uri}
59
+ assert_not_nil Page.all.detect {|p| p.uri == page_2.uri}
60
+ end
61
+
52
62
  should "respect uri hierarchy" do
53
63
  @page = page_stub('about/team/boris')
54
64
  @page.save
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ciridiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-17 00:00:00.000000000Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &2157070940 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.9.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2157070940
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.1
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rack-test
27
- requirement: &2157070460 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.3.0
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *2157070460
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: contest
38
- requirement: &2157069980 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: 0.1.0
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *2157069980
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
47
62
  description: Dead simple wiki engine
48
63
  email: vasily@polovnyov.ru
49
64
  executables: []
@@ -89,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
104
  version: '0'
90
105
  requirements: []
91
106
  rubyforge_project:
92
- rubygems_version: 1.8.15
107
+ rubygems_version: 1.8.23
93
108
  signing_key:
94
109
  specification_version: 3
95
110
  summary: Dead simple wiki engine