document_mapper 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,16 @@
1
- h1. Document Mapper
1
+ # Document Mapper
2
2
 
3
- !http://travis-ci.org/ralph/document_mapper.png!:http://travis-ci.org/ralph/document_mapper
3
+ [![Build Status](https://secure.travis-ci.org/ralph/document_mapper.png)](http://travis-ci.org/ralph/document_mapper)
4
4
 
5
- Document mapper is an object mapper for plain text documents. The documents look like the ones used in "jekyll":http://github.com/mojombo/jekyll, "toto":http://github.com/cloudhead/toto or "Serious":http://github.com/colszowka/serious. They consist of a preambel written in YAML (also called YAML front matter), and some content in the format you prefer, e.g. Textile. This enables you to write documents in your favorite editor and access the content and metadata in your Ruby scripts.
5
+ Document mapper is an object mapper for plain text documents. The documents look like the ones used in [jekyll](http://github.com/mojombo/jekyll), [toto](http://github.com/cloudhead/toto) or [Serious](http://github.com/colszowka/serious). They consist of a preambel written in YAML (also called YAML front matter), and some content in the format you prefer, e.g. Textile. This enables you to write documents in your favorite editor and access the content and metadata in your Ruby scripts.
6
6
 
7
7
 
8
- h2. Step-by-step tutorial
8
+ ## Step-by-step tutorial
9
9
 
10
- Documents look somehow like this. The part between the @---@s is the YAML front matter. After the second @---@, there is one blank line, followed by the content of the file. All items in the YAML front matter and the content are accessible by Document Mapper.
10
+ Documents look somehow like this. The part between the ```---```s is the YAML front matter. After the second ```---```, there is one blank line, followed by the content of the file. All items in the YAML front matter and the content are accessible by Document Mapper.
11
11
 
12
- <pre><code>---
12
+ ```yaml
13
+ ---
13
14
  id: 1
14
15
  title: Ruby is great
15
16
  tags: [programming, software]
@@ -18,66 +19,72 @@ status: published
18
19
  ---
19
20
 
20
21
  I like Ruby.
21
- </code></pre>
22
+ ```
22
23
 
23
24
 
24
- In order to access the values in the front matter, you have to create a class that includes @DocumentMapper@.
25
+ In order to access the values in the front matter, you have to create a class that includes ```DocumentMapper```.
25
26
 
26
- <pre><code>require 'document_mapper'
27
+ ```ruby
28
+ require 'document_mapper'
27
29
  class MyDocument
28
30
  include DocumentMapper::Document
29
31
  end
30
- </code></pre>
31
-
32
+ ```
32
33
 
33
- h3. Initializing single documents
34
+ ### Initializing single documents
34
35
 
35
- <pre><code>doc = MyDocument.from_file('./documents/document-file.textile')
36
- </code></pre>
36
+ ```ruby
37
+ doc = MyDocument.from_file('./documents/document-file.textile')
38
+ ```
37
39
 
38
40
 
39
- h3. Accessing the attributes of single documents
41
+ ### Accessing the attributes of single documents
40
42
 
41
- <pre><code>doc.title # => "Ruby is great"
43
+ ```ruby
44
+ doc.title # => "Ruby is great"
42
45
  doc.tags # => ["programming", "software"]
43
46
  doc.content # => "I like Ruby."
44
- </code></pre>
47
+ ```
45
48
 
46
49
 
47
- h3. Date recognition
50
+ ### Date recognition
48
51
 
49
- You can either set the date of a document in the YAML front matter, or you can use the file name, if you want to. A file named @2010-08-07-test-document-file.textile@ will return a date like this:
52
+ You can either set the date of a document in the YAML front matter, or you can use the file name, if you want to. A file named ```2010-08-07-test-document-file.textile``` will return a date like this:
50
53
 
51
- <pre><code>doc.date # => #<Date: 2010-08-08 (4910833/2,0,2299161)>
52
- doc.date.to_s # => "2010-08-08"
54
+ ```ruby
55
+ doc.date # => #<Date: 2010-08-07 (4910833/2,0,2299161)>
56
+ doc.date.to_s # => "2010-08-07"
53
57
  doc.year # => 2010
54
58
  doc.month # => 08
55
59
  doc.day # => 07
56
- </code></pre>
60
+ ```
57
61
 
58
62
 
59
- h3. Working with directories
63
+ ### Working with directories
60
64
 
61
65
  As an example let's assume we have a directory called "documents" containing the following files:
62
66
 
63
- <pre><code>documents/
67
+ ```ruby
68
+ documents/
64
69
  |-foo.textile
65
70
  |-bar.textile
66
- </code></pre>
71
+ ```
67
72
 
68
73
 
69
74
  In order to work with a whole directory of files, we have to use the @directory@ method:
70
75
 
71
- <pre><code>require 'document_mapper'
76
+ ```ruby
77
+ require 'document_mapper'
72
78
  class MyDocument
73
79
  include DocumentMapper::Document
74
80
  self.directory = 'documents'
75
81
  end
76
- </code></pre>
82
+ ```
77
83
 
78
84
  Now we can receive all available documents or filter like that:
79
85
 
80
- <pre><code>MyDocument.all
86
+ ```ruby
87
+ MyDocument.all
81
88
  MyDocument.first
82
89
  MyDocument.last
83
90
  MyDocument.limit(2)
@@ -85,46 +92,50 @@ MyDocument.offset(2)
85
92
  MyDocument.where(:title => 'Some title').first
86
93
  MyDocument.where(:status => 'published').all
87
94
  MyDocument.where(:year => 2010).all
88
- </code></pre>
95
+ ```
89
96
 
90
97
  Not all of the documents in the directory need to have all of the attributes. You can add single attributes to single documents, and the queries will only return those documents where the attributes match.
91
98
 
92
99
  The document queries do support more operators than just equality. The following operators are available:
93
100
 
94
- <pre><code>MyDocument.where(:year.gt => 2010) # year > 2010
101
+ ```ruby
102
+ MyDocument.where(:year.gt => 2010) # year > 2010
95
103
  MyDocument.where(:year.gte => 2010) # year >= 2010
96
104
  MyDocument.where(:year.in => [2010,2011]) # year one of [2010,2011]
97
105
  MyDocument.where(:tags.include => 'ruby') # 'ruby' is included in tags = ['ruby', 'rails', ...]
98
106
  MyDocument.where(:year.lt => 2010) # year < 2010
99
107
  MyDocument.where(:year.lte => 2010) # year <= 2010
100
- </code></pre>
108
+ ```
101
109
 
102
110
  While retrieving documents, you can also define the way the documents should be ordered. By default, the documents will be returned in the order they were loaded from the file system, which usually means by file name ascending. If you define an ordering, the documents that don't own the ordering attribute will be excluded.
103
111
 
104
- <pre><code>MyDocument.order_by(:title => :asc).all # Order by title attribute, ascending
112
+ ```ruby
113
+ MyDocument.order_by(:title => :asc).all # Order by title attribute, ascending
105
114
  MyDocument.order_by(:title).all # Same as order_by(:title => :asc)
106
115
  MyDocument.order_by(:title => :desc).all # Order by title attribute, descending
107
- </code></pre>
116
+ ```
108
117
 
109
118
 
110
- h3. Chaining
119
+ ### Chaining
111
120
 
112
121
  Chaining works with all available query methods, e.g.:
113
122
 
114
- <pre><code>MyDocument.where(:status => 'published').where(:title => 'Some title').limit(2).all
115
- </code></pre>
123
+ ```ruby
124
+ MyDocument.where(:status => 'published').where(:title => 'Some title').limit(2).all
125
+ ```
116
126
 
117
127
 
118
- h3. Reloading
128
+ ### Reloading
119
129
 
120
130
  If any of the files change, you must manually reload them:
121
131
 
122
- <pre><code>MyDocument.reload
123
- </code></pre>
132
+ ```ruby
133
+ MyDocument.reload
134
+ ```
124
135
 
125
136
 
126
- h2. Author
137
+ ## Author
127
138
 
128
- Written by "Ralph von der Heyden":http://rvdh.de. Don't hesitate to contact me if you have any further questions.
139
+ Written by [Ralph von der Heyden](http://www.rvdh.de). Don't hesitate to contact me if you have any further questions.
129
140
 
130
- Follow me on "Twitter":http://twitter.com/ralph!
141
+ Follow me on [Twitter](http://twitter.com/ralph)
@@ -1,3 +1,3 @@
1
1
  module DocumentMapper
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: document_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-20 00:00:00.000000000Z
12
+ date: 2011-09-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &2156281780 !ruby/object:Gem::Requirement
16
+ requirement: &70138859185020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.0.0
21
+ version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156281780
24
+ version_requirements: *70138859185020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activemodel
27
- requirement: &2156280460 !ruby/object:Gem::Requirement
27
+ requirement: &70138859184180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 3.0.0
32
+ version: 3.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156280460
35
+ version_requirements: *70138859184180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &2156278980 !ruby/object:Gem::Requirement
38
+ requirement: &70138859183360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2156278980
46
+ version_requirements: *70138859183360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: tilt
49
- requirement: &2156278120 !ruby/object:Gem::Requirement
49
+ requirement: &70138859182700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.3.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2156278120
57
+ version_requirements: *70138859182700
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: RedCloth
60
- requirement: &2156277280 !ruby/object:Gem::Requirement
60
+ requirement: &70138859182100 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,18 +65,18 @@ dependencies:
65
65
  version: 4.2.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2156277280
68
+ version_requirements: *70138859182100
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
- requirement: &2156276220 !ruby/object:Gem::Requirement
71
+ requirement: &70138859181500 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- version: 2.3.1
76
+ version: 2.6.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2156276220
79
+ version_requirements: *70138859181500
80
80
  description: ! ' DocumentMapper is an object mapper for plain text documents. The
81
81
  documents look like the ones used in jekyll (http://github.com/mojombo/jekyll).
82
82
  They consist of a preambel written in YAML (also called YAML front matter), and
@@ -91,7 +91,7 @@ extensions: []
91
91
  extra_rdoc_files: []
92
92
  files:
93
93
  - LICENSE
94
- - README.textile
94
+ - README.md
95
95
  - lib/document_mapper/attribute_methods.rb
96
96
  - lib/document_mapper/constants.rb
97
97
  - lib/document_mapper/core_ext/object.rb
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  segments:
128
128
  - 0
129
- hash: 3820388701645222296
129
+ hash: 4508131542455826029
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  none: false
132
132
  requirements:
@@ -135,10 +135,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: 3820388701645222296
138
+ hash: 4508131542455826029
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 1.8.5
141
+ rubygems_version: 1.8.10
142
142
  signing_key:
143
143
  specification_version: 3
144
144
  summary: DocumentMapper is an object mapper for plain text documents.