walter 0.0.1
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/Manifest +6 -0
- data/README.md +28 -0
- data/Rakefile +12 -0
- data/config.ru +4 -0
- data/lib/walter.rb +139 -0
- data/walter.gemspec +44 -0
- metadata +148 -0
data/Manifest
ADDED
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
**Walter** is a small web app written in ruby and [sinatra](http://sinatrarb.com). The unique purpose is to manage a directory full of quotes and the informations that get along.
|
2
|
+
|
3
|
+
The name is of course a tribue to Walter Benjamin and his obsession for quotes.
|
4
|
+
|
5
|
+
TODO
|
6
|
+
====
|
7
|
+
|
8
|
+
- #### now
|
9
|
+
- having fun
|
10
|
+
- continue the CSS
|
11
|
+
- multi-authors books
|
12
|
+
- author view
|
13
|
+
- display the year
|
14
|
+
- put a proper permalink system
|
15
|
+
- installable via rubygems
|
16
|
+
- separate the views in a different repo
|
17
|
+
- different levels of importance
|
18
|
+
|
19
|
+
- #### über-mich
|
20
|
+
- check english typographic rules
|
21
|
+
- make it easy for multilingual stuffs
|
22
|
+
- clean the code
|
23
|
+
|
24
|
+
- #### far, far future
|
25
|
+
- Search engine
|
26
|
+
- Tags
|
27
|
+
- Better bibtex rendering
|
28
|
+
- Export formats
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('walter', '0.0.1') do |p|
|
6
|
+
p.description = "A small webapp to explore and read a bunch of quotes stored as textfiles"
|
7
|
+
p.url = "https://github.com/taniki/walter"
|
8
|
+
p.author = "Duong Tam Kien"
|
9
|
+
p.email = "tk@deveha.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "quotes/*", "views/*", "public/css/*", "._*" ]
|
11
|
+
p.development_dependencies = [ "sinatra", "less", "rdiscount", "yaml", "erb"]
|
12
|
+
end
|
data/config.ru
ADDED
data/lib/walter.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'sinatra'
|
4
|
+
require 'erb'
|
5
|
+
require 'yaml'
|
6
|
+
require 'less'
|
7
|
+
|
8
|
+
require 'rdiscount'
|
9
|
+
|
10
|
+
|
11
|
+
module Walter
|
12
|
+
|
13
|
+
class App < Sinatra::Base
|
14
|
+
set :title, "fragments"
|
15
|
+
|
16
|
+
get "/css/benjamin.css" do
|
17
|
+
less :benjamin
|
18
|
+
end
|
19
|
+
|
20
|
+
get "/" do
|
21
|
+
file_index = Dir.glob('quotes/*.txt')
|
22
|
+
|
23
|
+
@books = file_index.map do |f|
|
24
|
+
Book.new f
|
25
|
+
end
|
26
|
+
|
27
|
+
erb :index
|
28
|
+
end
|
29
|
+
|
30
|
+
get "/quotes/:name" do
|
31
|
+
|
32
|
+
b = Book.new "quotes/"+params[:name]+".txt"
|
33
|
+
b.load_quotes
|
34
|
+
|
35
|
+
@book = b
|
36
|
+
|
37
|
+
erb :book
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Book
|
42
|
+
attr_accessor :file, :bib, :title, :author, :quotes
|
43
|
+
|
44
|
+
def initialize( f )
|
45
|
+
@quotes = Array.new
|
46
|
+
@file = f
|
47
|
+
|
48
|
+
self.load_bib
|
49
|
+
end
|
50
|
+
|
51
|
+
def load_bib
|
52
|
+
file_content = File.read @file
|
53
|
+
header = file_content.split(/---\n/, 1)[0]
|
54
|
+
|
55
|
+
@bib = YAML.load(header)
|
56
|
+
|
57
|
+
@title = @bib['title']
|
58
|
+
|
59
|
+
if @bib['author']
|
60
|
+
@author = @bib['author'].map do |a|
|
61
|
+
Author.new a['first'], a['last'], a['middle'], a['lineage']
|
62
|
+
end
|
63
|
+
else
|
64
|
+
@author = [ Author.new "John", "Doe", "", ""]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def load_quotes
|
69
|
+
file_content = File.read @file
|
70
|
+
parts = file_content.split(/---\n/)
|
71
|
+
|
72
|
+
parts.each do |part|
|
73
|
+
meta, body = part.split(/\n\n/, 2)
|
74
|
+
|
75
|
+
meta = YAML.load(meta)
|
76
|
+
|
77
|
+
# skipping the first part if it is containing yaml that looks like
|
78
|
+
# bibliographical information
|
79
|
+
|
80
|
+
if(meta['title'])
|
81
|
+
else
|
82
|
+
self.add_quote meta['page'], body
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_quote( p, b )
|
88
|
+
@quotes.push Quote.new p,b
|
89
|
+
end
|
90
|
+
|
91
|
+
def by(k)
|
92
|
+
if k == "author"
|
93
|
+
self.sort_by { |b| b.author[0].last }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def url
|
98
|
+
@file.sub ".txt", ""
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class Quote
|
103
|
+
attr_accessor :book, :page, :body
|
104
|
+
|
105
|
+
def initialize page, body
|
106
|
+
@page = page
|
107
|
+
@body = body
|
108
|
+
end
|
109
|
+
|
110
|
+
def render
|
111
|
+
RDiscount.new(@body).to_html
|
112
|
+
end
|
113
|
+
|
114
|
+
def page
|
115
|
+
h = @page.to_s
|
116
|
+
h.sub! "--", "–"
|
117
|
+
h
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
class Author
|
122
|
+
attr_accessor :first, :middle, :last, :lineage
|
123
|
+
|
124
|
+
def initialize f, l, m, li
|
125
|
+
@first = f
|
126
|
+
@middle = m
|
127
|
+
@last = l
|
128
|
+
@lineage = li
|
129
|
+
end
|
130
|
+
|
131
|
+
def to_html
|
132
|
+
"#{@last}, #{@first}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class Index
|
137
|
+
attr_accessor :authors, :books
|
138
|
+
end
|
139
|
+
end
|
data/walter.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{walter}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Duong Tam Kien"]
|
9
|
+
s.date = %q{2011-01-26}
|
10
|
+
s.description = %q{A small webapp to explore and read a bunch of quotes stored as textfiles}
|
11
|
+
s.email = %q{tk@deveha.com}
|
12
|
+
s.extra_rdoc_files = ["README.md", "lib/walter.rb"]
|
13
|
+
s.files = ["Manifest", "README.md", "Rakefile", "config.ru", "lib/walter.rb", "walter.gemspec"]
|
14
|
+
s.homepage = %q{https://github.com/taniki/walter}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Walter", "--main", "README.md"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{walter}
|
18
|
+
s.rubygems_version = %q{1.4.2}
|
19
|
+
s.summary = %q{A small webapp to explore and read a bunch of quotes stored as textfiles}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
s.add_development_dependency(%q<sinatra>, [">= 0"])
|
26
|
+
s.add_development_dependency(%q<less>, [">= 0"])
|
27
|
+
s.add_development_dependency(%q<rdiscount>, [">= 0"])
|
28
|
+
s.add_development_dependency(%q<yaml>, [">= 0"])
|
29
|
+
s.add_development_dependency(%q<erb>, [">= 0"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
32
|
+
s.add_dependency(%q<less>, [">= 0"])
|
33
|
+
s.add_dependency(%q<rdiscount>, [">= 0"])
|
34
|
+
s.add_dependency(%q<yaml>, [">= 0"])
|
35
|
+
s.add_dependency(%q<erb>, [">= 0"])
|
36
|
+
end
|
37
|
+
else
|
38
|
+
s.add_dependency(%q<sinatra>, [">= 0"])
|
39
|
+
s.add_dependency(%q<less>, [">= 0"])
|
40
|
+
s.add_dependency(%q<rdiscount>, [">= 0"])
|
41
|
+
s.add_dependency(%q<yaml>, [">= 0"])
|
42
|
+
s.add_dependency(%q<erb>, [">= 0"])
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: walter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Duong Tam Kien
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-26 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: sinatra
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: less
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rdiscount
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: yaml
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: erb
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
version_requirements: *id005
|
91
|
+
description: A small webapp to explore and read a bunch of quotes stored as textfiles
|
92
|
+
email: tk@deveha.com
|
93
|
+
executables: []
|
94
|
+
|
95
|
+
extensions: []
|
96
|
+
|
97
|
+
extra_rdoc_files:
|
98
|
+
- README.md
|
99
|
+
- lib/walter.rb
|
100
|
+
files:
|
101
|
+
- Manifest
|
102
|
+
- README.md
|
103
|
+
- Rakefile
|
104
|
+
- config.ru
|
105
|
+
- lib/walter.rb
|
106
|
+
- walter.gemspec
|
107
|
+
has_rdoc: true
|
108
|
+
homepage: https://github.com/taniki/walter
|
109
|
+
licenses: []
|
110
|
+
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options:
|
113
|
+
- --line-numbers
|
114
|
+
- --inline-source
|
115
|
+
- --title
|
116
|
+
- Walter
|
117
|
+
- --main
|
118
|
+
- README.md
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 3
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
version: "0"
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
hash: 11
|
136
|
+
segments:
|
137
|
+
- 1
|
138
|
+
- 2
|
139
|
+
version: "1.2"
|
140
|
+
requirements: []
|
141
|
+
|
142
|
+
rubyforge_project: walter
|
143
|
+
rubygems_version: 1.4.2
|
144
|
+
signing_key:
|
145
|
+
specification_version: 3
|
146
|
+
summary: A small webapp to explore and read a bunch of quotes stored as textfiles
|
147
|
+
test_files: []
|
148
|
+
|