spandex 0.0.2 → 0.0.3
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.
- data/.gitignore +1 -0
- data/lib/spandex/finder.rb +7 -0
- data/lib/spandex/page.rb +1 -19
- data/lib/spandex/version.rb +1 -1
- data/spandex.gemspec +1 -1
- data/spec/finder_spec.rb +71 -40
- data/spec/page_spec.rb +11 -11
- data/spec/spec_helper.rb +7 -4
- metadata +4 -6
data/.gitignore
CHANGED
data/lib/spandex/finder.rb
CHANGED
@@ -16,6 +16,7 @@ module Spandex
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def get(path)
|
19
|
+
path = Page.pathify path
|
19
20
|
load(Page.file_from_path(path, @base_dir), path)
|
20
21
|
end
|
21
22
|
|
@@ -39,6 +40,10 @@ module Spandex
|
|
39
40
|
.sort {|x, y| y.date <=> x.date }
|
40
41
|
end
|
41
42
|
|
43
|
+
def find_pages(conditions)
|
44
|
+
find_inside(all_pages, conditions)
|
45
|
+
end
|
46
|
+
|
42
47
|
def find_articles(conditions)
|
43
48
|
find_inside(all_articles, conditions)
|
44
49
|
end
|
@@ -64,6 +69,7 @@ module Spandex
|
|
64
69
|
private
|
65
70
|
|
66
71
|
def load(filename, key = Page.path_from_file(filename, @base_dir))
|
72
|
+
key = key.to_s
|
67
73
|
return nil unless filename && key && File.exists?(filename)
|
68
74
|
if @pages && @pages[key] && File.mtime(filename) < @pages[key].mtime
|
69
75
|
@pages[key]
|
@@ -81,6 +87,7 @@ module Spandex
|
|
81
87
|
next unless v
|
82
88
|
cond = case k
|
83
89
|
when :tag then lambda {|p| p.tags.include?(v) }
|
90
|
+
when :title then lambda {|p| p.title.match(v)}
|
84
91
|
else lambda{|p| true}
|
85
92
|
end
|
86
93
|
output = output.select(&cond)
|
data/lib/spandex/page.rb
CHANGED
@@ -7,16 +7,6 @@ module Spandex
|
|
7
7
|
class Page
|
8
8
|
attr_reader :path, :mtime, :extension, :render_options
|
9
9
|
|
10
|
-
def self.from_path(path, base_path, render_options = {})
|
11
|
-
path = fix_path path
|
12
|
-
filename = file_from_path(path, base_path)
|
13
|
-
if filename
|
14
|
-
metadata, content = parse_file(filename)
|
15
|
-
Page.new(path, content, filename.extname, metadata, render_options)
|
16
|
-
else nil
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
10
|
def self.from_filename(filename, base_path, render_options = {})
|
21
11
|
pathname = Pathname.new(filename)
|
22
12
|
return nil unless pathname.exist?
|
@@ -27,14 +17,6 @@ module Spandex
|
|
27
17
|
Page.new(path, content, pathname.extname, metadata, render_options)
|
28
18
|
end
|
29
19
|
|
30
|
-
def self.mtime(path, base_path)
|
31
|
-
file = file_from_path(path, base_path)
|
32
|
-
if File.exists?(path)
|
33
|
-
File.mtime(file)
|
34
|
-
else nil
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
20
|
def self.file_from_path(path, base_path)
|
39
21
|
path = fix_path path
|
40
22
|
paths = Pathname.glob(File.join(base_path, "#{path}.*"))
|
@@ -101,7 +83,7 @@ module Spandex
|
|
101
83
|
end
|
102
84
|
|
103
85
|
def self.pathify(path_or_string)
|
104
|
-
path_or_string.is_a?(String) ? Pathname.new(path_or_string) : path_or_string
|
86
|
+
path_or_string.is_a?(String) ? Pathname.new(fix_path path_or_string) : path_or_string
|
105
87
|
end
|
106
88
|
|
107
89
|
def self.parse_file(filename)
|
data/lib/spandex/version.rb
CHANGED
data/spandex.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Isaac Cambron"]
|
10
10
|
s.email = ["icambron@alum.mit.edu"]
|
11
|
-
s.homepage = ""
|
11
|
+
s.homepage = "https://github.com/icambron/spandex"
|
12
12
|
s.summary = "A simple content engine"
|
13
13
|
s.description = "Spandex manages a store of markup files and their metadata, useful in building blogs or blog engines"
|
14
14
|
|
data/spec/finder_spec.rb
CHANGED
@@ -9,23 +9,23 @@ describe Spandex::Finder do
|
|
9
9
|
context "when getting all pages" do
|
10
10
|
|
11
11
|
it "can find files" do
|
12
|
-
create_file("lasers.md"
|
13
|
-
create_file("cheese.textile"
|
12
|
+
create_file("lasers.md")
|
13
|
+
create_file("cheese.textile")
|
14
14
|
make_finder.all_pages.size.should == 2
|
15
15
|
end
|
16
16
|
|
17
17
|
it "won't find repeated files roots" do
|
18
|
-
create_file("stuff.md"
|
19
|
-
create_file("stuff.textile"
|
18
|
+
create_file("stuff.md")
|
19
|
+
create_file("stuff.textile")
|
20
20
|
|
21
21
|
make_finder.all_pages.size.should == 1
|
22
22
|
end
|
23
23
|
|
24
24
|
it "finds thing with populated attributes" do
|
25
|
-
create_file("stuff.md",
|
26
|
-
create_file("more_stuff.textile",
|
25
|
+
create_file("stuff.md", :title => "The")
|
26
|
+
create_file("more_stuff.textile", :title => "Sounds")
|
27
27
|
|
28
|
-
make_finder.all_pages.map{|p| p.title}.should
|
28
|
+
make_finder.all_pages.map{|p| p.title}.should =~ ["The", "Sounds"]
|
29
29
|
end
|
30
30
|
|
31
31
|
end
|
@@ -37,8 +37,8 @@ describe Spandex::Finder do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "only finds pages with dates" do
|
40
|
-
create_file("stuff.md",
|
41
|
-
create_file("more_stuff.md"
|
40
|
+
create_file("stuff.md", :date => "2011/5/25")
|
41
|
+
create_file("more_stuff.md")
|
42
42
|
|
43
43
|
results = make_finder.all_articles
|
44
44
|
results.size.should == 1
|
@@ -46,9 +46,9 @@ describe Spandex::Finder do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "sorts by date descending" do
|
49
|
-
create_file("stuff.md",
|
50
|
-
create_file("more_stuff.md",
|
51
|
-
create_file("even_more_stuff.md",
|
49
|
+
create_file("stuff.md", :date => "1986/5/25")
|
50
|
+
create_file("more_stuff.md", :date => "1982/5/25")
|
51
|
+
create_file("even_more_stuff.md", :date => "2011/5/25")
|
52
52
|
|
53
53
|
results = make_finder.all_articles
|
54
54
|
|
@@ -59,7 +59,7 @@ describe Spandex::Finder do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "ignores stray files" do
|
62
|
-
create_file("stuff.md~",
|
62
|
+
create_file("stuff.md~", :date => "1986/5/25")
|
63
63
|
make_finder.all_articles.should be_empty
|
64
64
|
end
|
65
65
|
|
@@ -68,8 +68,8 @@ describe Spandex::Finder do
|
|
68
68
|
context "when generating an atom feed" do
|
69
69
|
|
70
70
|
it "generates real atom content" do
|
71
|
-
create_file("stuff.md",
|
72
|
-
create_file("more_stuff.md",
|
71
|
+
create_file("stuff.md", :date => "1986/5/25", :title => "BFI")
|
72
|
+
create_file("more_stuff.md", :date => "1982/5/25")
|
73
73
|
|
74
74
|
#generate and then reparse
|
75
75
|
feed = make_finder.atom_feed(3, "The Sounds", "sounds.test.org", "articles.xml")
|
@@ -85,9 +85,9 @@ describe Spandex::Finder do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should only show the top n articles" do
|
88
|
-
create_file("stuff.md",
|
89
|
-
create_file("more_stuff.md",
|
90
|
-
create_file("even_more_stuff.md",
|
88
|
+
create_file("stuff.md", :date => "1986/5/25")
|
89
|
+
create_file("more_stuff.md", :date => "1986/5/25")
|
90
|
+
create_file("even_more_stuff.md", :date => "1986/5/25")
|
91
91
|
|
92
92
|
feed = make_finder.atom_feed(2, "The Sounds", "sounds.test.org", "articles.xml")
|
93
93
|
ratom = Atom::Feed.load_feed(feed)
|
@@ -96,8 +96,8 @@ describe Spandex::Finder do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
it "only includes pages with dates" do
|
99
|
-
create_file("stuff.md",
|
100
|
-
create_file("more_stuff.md"
|
99
|
+
create_file("stuff.md", :date => "2011/5/25")
|
100
|
+
create_file("more_stuff.md")
|
101
101
|
|
102
102
|
feed = make_finder.atom_feed(2, "The Sounds", "sounds.test.org", "articles.xml")
|
103
103
|
ratom = Atom::Feed.load_feed(feed)
|
@@ -110,33 +110,33 @@ describe Spandex::Finder do
|
|
110
110
|
context "when listing tags" do
|
111
111
|
|
112
112
|
it "can list tags" do
|
113
|
-
create_file("stuff.md",
|
114
|
-
create_file("more_stuff.md",
|
113
|
+
create_file("stuff.md", :tags => "Sweedish, New Wave")
|
114
|
+
create_file("more_stuff.md", :tags => "Indie Rock")
|
115
115
|
|
116
116
|
tags = make_finder.tags
|
117
|
-
tags.should
|
117
|
+
tags.should =~ ["Sweedish", "New Wave", "Indie Rock"]
|
118
118
|
end
|
119
119
|
|
120
120
|
it "has unique tags" do
|
121
|
-
create_file("stuff.md",
|
122
|
-
create_file("more_stuff.md",
|
121
|
+
create_file("stuff.md", :tags => "Sweedish, Indie Rock")
|
122
|
+
create_file("more_stuff.md", :tags => "Indie Rock")
|
123
123
|
|
124
124
|
tags = make_finder.tags
|
125
|
-
tags.should
|
125
|
+
tags.should =~ ["Sweedish", "Indie Rock"]
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
context "loading a specific page" do
|
130
130
|
|
131
131
|
it "does in fact load it" do
|
132
|
-
create_file("stuff.md"
|
132
|
+
create_file("stuff.md")
|
133
133
|
page = make_finder.get("stuff")
|
134
134
|
page.should_not be_nil
|
135
135
|
end
|
136
136
|
|
137
137
|
it "finds the first file tilt knows" do
|
138
|
-
create_file("stuff.snoogledoobers"
|
139
|
-
create_file("stuff.md"
|
138
|
+
create_file("stuff.snoogledoobers")
|
139
|
+
create_file("stuff.md")
|
140
140
|
page = make_finder.get("stuff")
|
141
141
|
page.extension.should == "md"
|
142
142
|
end
|
@@ -149,23 +149,40 @@ describe Spandex::Finder do
|
|
149
149
|
it "caches individual files" do
|
150
150
|
finder = make_finder
|
151
151
|
|
152
|
-
create_file("stuff.md",
|
152
|
+
create_file("stuff.md", :tags => "yeah")
|
153
153
|
finder.get("stuff").tags.should == ["yeah"]
|
154
154
|
|
155
|
-
create_file("stuff.md",
|
155
|
+
create_file("stuff.md", :tags => "nah")
|
156
156
|
finder.get("stuff").tags.should == ["yeah"]
|
157
157
|
end
|
158
158
|
|
159
|
+
it "doesn't muck up the cache" do
|
160
|
+
create_file("stuff.md")
|
161
|
+
finder = make_finder
|
162
|
+
finder.all_pages
|
163
|
+
finder.get("stuff")
|
164
|
+
finder.all_pages.size.should == 1
|
165
|
+
end
|
166
|
+
|
159
167
|
it "ignores trailing slashes" do
|
160
|
-
create_file("stuff.md"
|
168
|
+
create_file("stuff.md")
|
161
169
|
make_finder.get("stuff/").should_not be_nil
|
162
170
|
end
|
163
171
|
|
172
|
+
it "doesn't create a separate cache entry for trailing slashes" do
|
173
|
+
create_file("stuff.md")
|
174
|
+
finder = make_finder
|
175
|
+
finder.all_pages
|
176
|
+
finder.get("stuff/")
|
177
|
+
|
178
|
+
finder.all_pages.size.should == 1
|
179
|
+
end
|
180
|
+
|
164
181
|
end
|
165
182
|
|
166
183
|
context "when loading by filename" do
|
167
184
|
it "does in fact load something" do
|
168
|
-
create_file("stuff.md"
|
185
|
+
create_file("stuff.md")
|
169
186
|
page = make_finder.get_by_filename(File.join(TEMP_DIR, "stuff.md"))
|
170
187
|
page.should_not be_nil
|
171
188
|
end
|
@@ -177,21 +194,35 @@ describe Spandex::Finder do
|
|
177
194
|
|
178
195
|
end
|
179
196
|
|
180
|
-
context "when
|
197
|
+
context "when find pages" do
|
181
198
|
it "can find them by tag" do
|
182
|
-
create_file("no.md",
|
183
|
-
create_file("yeah.md",
|
199
|
+
create_file("no.md", :tags => "nono")
|
200
|
+
create_file("yeah.md", :tags => "yeahyeah")
|
184
201
|
|
185
202
|
|
186
|
-
results = make_finder.
|
203
|
+
results = make_finder.find_pages(:tag => "yeahyeah")
|
187
204
|
results.size.should == 1
|
188
205
|
results.first.title == "Yeah Yeah Yeah"
|
189
206
|
end
|
190
207
|
|
208
|
+
it "can find them by titles" do
|
209
|
+
create_file("no.md", :title => "This has the wrong title")
|
210
|
+
create_file("yeah.md", :title => "This has the correct title")
|
211
|
+
end
|
212
|
+
|
213
|
+
it "can find them by multiple metrics" do
|
214
|
+
create_file("no.md", :tags => "yeah", :title => "This has the wrong title")
|
215
|
+
create_file("yeah.md", :tags => "no", :title => "This has the correct title")
|
216
|
+
create_file("definitely.md", :tags => "yeah", :title => "This has the correct title")
|
217
|
+
|
218
|
+
make_finder.find_pages(:tags => "yeah", :title => "correct")
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "when finding articles" do
|
191
223
|
it "only finds articles" do
|
192
|
-
create_file("no.md",
|
193
|
-
create_file("yeah.md",
|
194
|
-
|
224
|
+
create_file("no.md", :tags => "yeahyeah")
|
225
|
+
create_file("yeah.md", :tags => "yeahyeah", :date => "2011/5/26", :title => "Yeah Yeah Yeah")
|
195
226
|
|
196
227
|
results = make_finder.find_articles(:tag => "yeahyeah")
|
197
228
|
results.size.should == 1
|
data/spec/page_spec.rb
CHANGED
@@ -9,44 +9,44 @@ describe Spandex::Page do
|
|
9
9
|
|
10
10
|
context "when parsing a file" do
|
11
11
|
it "determines the extension" do
|
12
|
-
page = create_page("test.md"
|
12
|
+
page = create_page("test.md")
|
13
13
|
page.extension.should=="md"
|
14
14
|
end
|
15
15
|
|
16
16
|
it "can have a title" do
|
17
|
-
page = create_page("test.md",
|
17
|
+
page = create_page("test.md", :title => "The Best of Me")
|
18
18
|
page.title.should == "The Best of Me"
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can have a tag" do
|
22
|
-
page = create_page("test.md",
|
22
|
+
page = create_page("test.md", :tags => "sappy")
|
23
23
|
page.tags.should have(1).tags
|
24
24
|
page.tags.should == ["sappy"]
|
25
25
|
end
|
26
26
|
|
27
27
|
it "can have multiple tags" do
|
28
|
-
page = create_page("test.md",
|
28
|
+
page = create_page("test.md", :tags => "sappy,slightly trite")
|
29
29
|
page.tags.should == ['sappy', 'slightly trite']
|
30
30
|
end
|
31
31
|
|
32
32
|
it "can have multiple tags with weird spacing" do
|
33
|
-
page = create_page("test.md",
|
33
|
+
page = create_page("test.md", :tags => " sappy , slightly trite ")
|
34
34
|
page.tags.should == ['sappy', 'slightly trite']
|
35
35
|
end
|
36
36
|
|
37
37
|
it "can also have tags called 'categories'" do
|
38
|
-
page = create_page("test.md",
|
38
|
+
page = create_page("test.md", :categories => "sappy,slightly trite")
|
39
39
|
page.tags.should have(2).tags
|
40
40
|
end
|
41
41
|
|
42
42
|
it "can parse the body" do
|
43
|
-
page = create_page("test.md", "But it's not that easy")
|
43
|
+
page = create_page("test.md", :content => "But it's not that easy")
|
44
44
|
page.body.should == Redcarpet::Markdown.new(Redcarpet::Render::HTML).render("But it's not that easy")
|
45
45
|
end
|
46
46
|
|
47
47
|
it "pass in rendering options" do
|
48
48
|
text = "```\nI smile but it doesn't make things right```"
|
49
|
-
create_file("test.md", text)
|
49
|
+
create_file("test.md", :content => text)
|
50
50
|
page = Spandex::Page.from_filename(File.join(TEMP_DIR, "test.md"), TEMP_DIR, :fenced_code_blocks => true)
|
51
51
|
page.render_options.should have_key(:fenced_code_blocks)
|
52
52
|
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :fenced_code_blocks => true)
|
@@ -54,17 +54,17 @@ describe Spandex::Page do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "can have a date" do
|
57
|
-
page = create_page("test.md",
|
57
|
+
page = create_page("test.md", :date => "2011/5/25")
|
58
58
|
page.date.should == Date.civil(2011, 5, 25)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "can omit the date" do
|
62
|
-
page = create_page("test.md"
|
62
|
+
page = create_page("test.md")
|
63
63
|
page.date.should be_nil
|
64
64
|
end
|
65
65
|
|
66
66
|
it "produces good atom output" do
|
67
|
-
page = create_page("test.md",
|
67
|
+
page = create_page("test.md", :title => "hello!", :date => "2011/5/25")
|
68
68
|
entry = page.to_atom_entry("http://test.org")
|
69
69
|
entry.title.should == "hello!"
|
70
70
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,9 +17,12 @@ end
|
|
17
17
|
module PageFactory
|
18
18
|
include TempFileHelper
|
19
19
|
|
20
|
-
def create_file(name,
|
20
|
+
def create_file(name, metadata = {})
|
21
21
|
full_name = File.join(TEMP_DIR, name)
|
22
|
-
metatext = metadata
|
22
|
+
metatext = metadata
|
23
|
+
.select { |key, value| key != :content}
|
24
|
+
.map { |key, value| "#{key}: #{value}" }.join("\n")
|
25
|
+
content = metadata[:content] ? metadata[:content] : "Some stuff"
|
23
26
|
contents =<<-EOF
|
24
27
|
#{metatext}
|
25
28
|
|
@@ -29,8 +32,8 @@ EOF
|
|
29
32
|
full_name
|
30
33
|
end
|
31
34
|
|
32
|
-
def create_page(name,
|
33
|
-
full_name = create_file(name,
|
35
|
+
def create_page(name, metadata = {})
|
36
|
+
full_name = create_file(name, metadata)
|
34
37
|
Spandex::Page.from_filename(full_name, TEMP_DIR)
|
35
38
|
end
|
36
39
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: spandex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Isaac Cambron
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-09-30 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: tilt
|
@@ -80,8 +79,7 @@ files:
|
|
80
79
|
- spec/page_spec.rb
|
81
80
|
- spec/spec_helper.rb
|
82
81
|
- spec/wrapper_spec.rb
|
83
|
-
|
84
|
-
homepage: ""
|
82
|
+
homepage: https://github.com/icambron/spandex
|
85
83
|
licenses: []
|
86
84
|
|
87
85
|
post_install_message:
|
@@ -104,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
102
|
requirements: []
|
105
103
|
|
106
104
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.
|
105
|
+
rubygems_version: 1.8.10
|
108
106
|
signing_key:
|
109
107
|
specification_version: 3
|
110
108
|
summary: A simple content engine
|