retter 0.1.3 → 0.2.0

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.
@@ -35,30 +35,20 @@ module Retter
35
35
  end
36
36
  end
37
37
 
38
- autoload :Generator, 'retter/generator'
38
+ autoload :Generator, 'retter/generator'
39
+
40
+ autoload :VERSION, 'retter/version'
41
+ autoload :Config, 'retter/config'
42
+ autoload :Renderers, 'retter/renderers'
43
+ autoload :Entry, 'retter/entry'
44
+ autoload :Entries, 'retter/entries'
45
+ autoload :Page, 'retter/page'
46
+ autoload :Pages, 'retter/pages'
47
+ autoload :Preprint, 'retter/preprint'
48
+ autoload :Repository, 'retter/repository'
49
+ autoload :Command, 'retter/command'
39
50
  end
40
51
 
41
52
  require 'date'
42
53
  require 'time'
43
- require 'builder'
44
54
  require 'pathname'
45
- require 'thor'
46
- require 'redcarpet'
47
- require 'coderay'
48
- require 'nokogiri'
49
- require 'launchy'
50
- require 'haml'
51
- require 'uri'
52
- require 'forwardable'
53
- require 'grit'
54
-
55
- require 'retter/version'
56
- require 'retter/config'
57
- require 'retter/renderer'
58
- require 'retter/entry'
59
- require 'retter/entries'
60
- require 'retter/page'
61
- require 'retter/pages'
62
- require 'retter/preprint'
63
- require 'retter/repository'
64
- require 'retter/command'
@@ -1,5 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'thor'
4
+ require 'launchy'
5
+
3
6
  class Retter::Command < Thor
4
7
  include Retter::Stationery
5
8
 
@@ -144,11 +147,10 @@ Usage:
144
147
  cd $RETTER_HOME
145
148
  git push [remote] [branch] # or sftp, rsync, etc...
146
149
 
147
- # Specific date
150
+ # Command options
148
151
  retter edit 20110101
149
152
  retter preview 20110101
150
153
 
151
- # Specific file
152
154
  retter edit today.md
153
155
  retter edit 20110101.md
154
156
  retter preview 20110101.md
@@ -1,5 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'active_support/cache'
4
+
3
5
  module Retter
4
6
  class EnvError < RetterError; end
5
7
 
@@ -7,6 +9,8 @@ module Retter
7
9
  ATTRIBUTES = [
8
10
  :editor,
9
11
  :shell,
12
+ :renderer,
13
+ :cache,
10
14
  :title,
11
15
  :description,
12
16
  :url,
@@ -51,15 +55,18 @@ module Retter
51
55
  @retter_home = Pathname.new(@env['RETTER_HOME'])
52
56
  load_defaults
53
57
  load_retterfile_if_exists
54
- rescue Retter::EnvError
55
- $stderr.puts 'Set $RETTER_HOME and $EDITOR, first.'
56
- say Retter::Command.usage, :green
57
- exit 1
58
+ rescue Retter::EnvError
59
+ $stderr.puts 'Set $RETTER_HOME and $EDITOR, first.'
60
+ say Retter::Command.usage, :green
61
+
62
+ exit 1
58
63
  end
59
64
 
60
65
  def load_defaults
61
66
  editor @env['EDITOR']
62
67
  shell @env['SHELL']
68
+ renderer Retter::Renderers::CodeRayRenderer
69
+ cache ActiveSupport::Cache::FileStore.new(retter_home.join('tmp/cache').to_s)
63
70
  url 'http://example.com'
64
71
  retters_dir retter_home.join('retters/')
65
72
  wip_file retters_dir.join('today.md')
@@ -99,10 +106,6 @@ module Retter
99
106
  entries_dir.join date.strftime('%Y%m%d')
100
107
  end
101
108
 
102
- def self.delegatables
103
- ATTRIBUTES + [:retter_file, :entry_file, :entry_dir]
104
- end
105
-
106
109
  def after(name, sym = nil, &block)
107
110
  if callback = sym || block
108
111
  @after_callbacks[name] = callback
@@ -1,6 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require 'active_support/core_ext/object'
4
+ require 'digest/sha1'
5
+ require 'redcarpet'
4
6
 
5
7
  module Retter
6
8
  class EntryLoadError < RetterError; end
@@ -13,18 +15,19 @@ module Retter
13
15
  end
14
16
 
15
17
  def detect_by_string(str)
16
- entry = case str
17
- when nil, ''
18
- detect_by_today || wip_entry
19
- when /^e([0-9]+)$/
20
- index = $1.to_i
21
- self[index]
22
- when /^([0-9a-z]+\.md)$/
23
- detect_by_filename($1)
24
- else
25
- date = parse_date_string(str)
26
- detect_by_date(date) || wip_entry(date)
27
- end
18
+ entry =
19
+ case str
20
+ when nil, ''
21
+ detect_by_today || wip_entry
22
+ when /^e([0-9]+)$/
23
+ index = $1.to_i
24
+ self[index]
25
+ when /^([0-9a-z]+\.md)$/
26
+ detect_by_filename($1)
27
+ else
28
+ date = parse_date_string(str)
29
+ detect_by_date(date) || wip_entry(date)
30
+ end
28
31
 
29
32
  raise EntryLoadError, "Entry not found with keyword '#{str}'" unless entry
30
33
 
@@ -65,7 +68,7 @@ module Retter
65
68
  wip_date = date || Date.today
66
69
  wip_body = wip_file.exist? ? wip_file.read : ''
67
70
 
68
- Retter::Entry.new date: wip_date, body: markupper.render(wip_body), pathname: wip_file
71
+ Retter::Entry.new date: wip_date, body: rendered_body(wip_body), pathname: wip_file
69
72
  end
70
73
 
71
74
  def commit_wip_entry!
@@ -85,7 +88,7 @@ module Retter
85
88
  }.sort_by(&:first)
86
89
 
87
90
  date_files.reverse_each {|date, file|
88
- self << Retter::Entry.new(date: date, body: markupper.render(file.read))
91
+ self << Retter::Entry.new(date: date, body: rendered_body(file.read))
89
92
  }
90
93
  end
91
94
 
@@ -94,17 +97,21 @@ module Retter
94
97
  Dir.open(path, &:to_a).grep(/^\d{4}(?:0[1-9]|1[012])(?:0[1-9]|[12][0-9]|3[01])\.(md)$/).map {|f| path.join f }
95
98
  end
96
99
 
97
- def markupper
98
- @markupper ||= ::Redcarpet::Markdown.new(
99
- Renderer,
100
- autolink: true,
101
- space_after_headers: true,
102
- fenced_code_blocks: true,
103
- strikethrough: true,
104
- superscript: true,
105
- fenced_code_blocks: true,
106
- tables: true
107
- )
100
+ def rendered_body(body)
101
+ key = Digest::SHA1.hexdigest('entry_' + body)
102
+
103
+ config.cache.fetch(key) do
104
+ Redcarpet::Markdown.new(
105
+ config.renderer,
106
+ autolink: true,
107
+ space_after_headers: true,
108
+ fenced_code_blocks: true,
109
+ strikethrough: true,
110
+ superscript: true,
111
+ fenced_code_blocks: true,
112
+ tables: true
113
+ ).render(body)
114
+ end
108
115
  end
109
116
  end
110
117
  end
@@ -1,5 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'nokogiri'
4
+
3
5
  class Retter::Entry
4
6
  class Article
5
7
  attr_accessor :entry, :id, :title, :body
@@ -25,9 +25,11 @@ class Retter::Generator::Base < Thor::Group
25
25
  retters/.gitkeep
26
26
  images/.gitkeep
27
27
  entries/.gitkeep
28
+ tmp/cache/.gitkeep
28
29
  javascripts/.gitkeep
29
30
  stylesheets/base.css
30
31
  stylesheets/retter.css
32
+ stylesheets/pygments.css
31
33
 
32
34
  stylesheets/orange.css
33
35
  images/orange/bg_body.jpg
@@ -5,6 +5,7 @@ url 'http://retter.example.com/'
5
5
  title '<%= name %>'
6
6
  description '<%= name %>'
7
7
  author '<%= ENV["USER"] %>'
8
+ renderer Retter::Renderers::PygmentsRenderer
8
9
 
9
10
  ## Callbacks for retter sub-command: edit, rebind, commit
10
11
  ##
@@ -23,5 +24,6 @@ author '<%= ENV["USER"] %>'
23
24
  # end
24
25
  #
25
26
  # after :edit do
26
- # preview ARGV.pop if yes?("Preview now? [yes/no]")
27
+ # ident = ARGV.pop || 'today'
28
+ # preview ident if yes?("Preview now? [yes/no]")
27
29
  # end
@@ -3,9 +3,11 @@
3
3
  %head
4
4
  %title= title
5
5
  %meta{:'http-equiv' => 'Content-Type', content: 'text/html', charset: 'utf-8'}
6
+ %meta{name: 'author', content: config.author}
6
7
  %link{rel: 'icon', type: 'image/png', href: '/favicon.png'}
7
8
  %link{href: '/stylesheets/base.css', media: 'screen', rel: 'stylesheet', type: 'text/css'}
8
9
  %link{href: '/stylesheets/retter.css', media: 'screen', rel: 'stylesheet', type: 'text/css'}
10
+ %link{href: '/stylesheets/pygments.css', media: 'screen', rel: 'stylesheet', type: 'text/css'}
9
11
  %link{rel: 'alternate', type: 'application/rss+xml', title: 'RSS', href: '/entries.rss'}
10
12
  %body
11
13
  #header
@@ -47,7 +47,7 @@ code{
47
47
  }
48
48
 
49
49
  #header ul#menu {
50
- margin: 0.5em 0 3em 0;
50
+ margin: 0.5em 0 6em 0;
51
51
  padding: 0 0 0 2em;
52
52
  }
53
53
 
@@ -83,11 +83,10 @@ article {
83
83
  border: 3px #FFC solid;
84
84
  -moz-border-radius: 10px;
85
85
  -webkit-border-radius: 10px;
86
- padding: 1em 1.5em 1em 1.5em;
87
- margin: 1em 0 1em 0;
88
- width: 100%;
86
+ padding: 2em 3em;
89
87
  background-image: url("../images/orange/bg_entry.jpg");
90
88
  position: relative;
89
+ margin-top:60px;
91
90
  }
92
91
 
93
92
  article ul li {
@@ -134,6 +133,10 @@ article ul#entries {
134
133
  line-height: 1.5em;
135
134
  }
136
135
 
136
+ article img{
137
+ max-width: 100%
138
+ }
139
+
137
140
  #entries {
138
141
  width: 100%;
139
142
  }
@@ -144,9 +147,8 @@ article ul#entries {
144
147
  border: 3px #FFC solid;
145
148
  -moz-border-radius: 10px;
146
149
  -webkit-border-radius: 10px;
147
- padding: 1em 1.5em 1em 1.5em;
150
+ padding: 2em 3em;
148
151
  margin: 1em 0 1em 0;
149
- width: 100%;
150
152
  background-image: url("../images/orange/bg_entry.jpg");
151
153
  position: relative;
152
154
  }
@@ -0,0 +1,288 @@
1
+ .highlight {
2
+ background: #fff;
3
+ }
4
+
5
+ .highlight .c {
6
+ color: #998;
7
+ font-style: italic;
8
+ }
9
+
10
+ .highlight .err {
11
+ color: #a61717;
12
+ background-color: #e3d2d2;
13
+ }
14
+
15
+ .highlight .k {
16
+ font-weight: bold;
17
+ }
18
+
19
+ .highlight .o {
20
+ font-weight: bold;
21
+ }
22
+
23
+ .highlight .cm {
24
+ color: #998;
25
+ font-style: italic;
26
+ }
27
+
28
+ .highlight .cp {
29
+ color: #999;
30
+ font-weight: bold;
31
+ }
32
+
33
+ .highlight .c1 {
34
+ color: #998;
35
+ font-style: italic;
36
+ }
37
+
38
+ .highlight .cs {
39
+ color: #999;
40
+ font-weight: bold;
41
+ font-style: italic;
42
+ }
43
+
44
+ .highlight .gd {
45
+ color: #000;
46
+ background-color: #fdd;
47
+ }
48
+
49
+ .highlight .gd .x {
50
+ color: #000;
51
+ background-color: #faa;
52
+ }
53
+
54
+ .highlight .ge {
55
+ font-style: italic;
56
+ }
57
+
58
+ .highlight .gr {
59
+ color: #a00;
60
+ }
61
+
62
+ .highlight .gh {
63
+ color: #999;
64
+ }
65
+
66
+ .highlight .gi {
67
+ color: #000;
68
+ background-color: #dfd;
69
+ }
70
+
71
+ .highlight .gi .x {
72
+ color: #000;
73
+ background-color: #afa;
74
+ }
75
+
76
+ .highlight .go {
77
+ color: #888;
78
+ }
79
+
80
+ .highlight .gp {
81
+ color: #555;
82
+ }
83
+
84
+ .highlight .gs {
85
+ font-weight: bold;
86
+ }
87
+
88
+ .highlight .gu {
89
+ color: #800080;
90
+ font-weight: bold;
91
+ }
92
+
93
+ .highlight .gt {
94
+ color: #a00;
95
+ }
96
+
97
+ .highlight .kc {
98
+ font-weight: bold;
99
+ }
100
+
101
+ .highlight .kd {
102
+ font-weight: bold;
103
+ }
104
+
105
+ .highlight .kn {
106
+ font-weight: bold;
107
+ }
108
+
109
+ .highlight .kp {
110
+ font-weight: bold;
111
+ }
112
+
113
+ .highlight .kr {
114
+ font-weight: bold;
115
+ }
116
+
117
+ .highlight .kt {
118
+ color: #458;
119
+ font-weight: bold;
120
+ }
121
+
122
+ .highlight .m {
123
+ color: #099;
124
+ }
125
+
126
+ .highlight .s {
127
+ color: #d14;
128
+ }
129
+
130
+ .highlight .na {
131
+ color: #008080;
132
+ }
133
+
134
+ .highlight .nb {
135
+ color: #0086B3;
136
+ }
137
+
138
+ .highlight .nc {
139
+ color: #458;
140
+ font-weight: bold;
141
+ }
142
+
143
+ .highlight .no {
144
+ color: #008080;
145
+ }
146
+
147
+ .highlight .ni {
148
+ color: #800080;
149
+ }
150
+
151
+ .highlight .ne {
152
+ color: #900;
153
+ font-weight: bold;
154
+ }
155
+
156
+ .highlight .nf {
157
+ color: #900;
158
+ font-weight: bold;
159
+ }
160
+
161
+ .highlight .nn {
162
+ color: #555;
163
+ }
164
+
165
+ .highlight .nt {
166
+ color: #000080;
167
+ }
168
+
169
+ .highlight .nv {
170
+ color: #008080;
171
+ }
172
+
173
+ .highlight .ow {
174
+ font-weight: bold;
175
+ }
176
+
177
+ .highlight .w {
178
+ color: #bbb;
179
+ }
180
+
181
+ .highlight .mf {
182
+ color: #099;
183
+ }
184
+
185
+ .highlight .mh {
186
+ color: #099;
187
+ }
188
+
189
+ .highlight .mi {
190
+ color: #099;
191
+ }
192
+
193
+ .highlight .mo {
194
+ color: #099;
195
+ }
196
+
197
+ .highlight .sb {
198
+ color: #d14;
199
+ }
200
+
201
+ .highlight .sc {
202
+ color: #d14;
203
+ }
204
+
205
+ .highlight .sd {
206
+ color: #d14;
207
+ }
208
+
209
+ .highlight .s2 {
210
+ color: #d14;
211
+ }
212
+
213
+ .highlight .se {
214
+ color: #d14;
215
+ }
216
+
217
+ .highlight .sh {
218
+ color: #d14;
219
+ }
220
+
221
+ .highlight .si {
222
+ color: #d14;
223
+ }
224
+
225
+ .highlight .sx {
226
+ color: #d14;
227
+ }
228
+
229
+ .highlight .sr {
230
+ color: #009926;
231
+ }
232
+
233
+ .highlight .s1 {
234
+ color: #d14;
235
+ }
236
+
237
+ .highlight .ss {
238
+ color: #990073;
239
+ }
240
+
241
+ .highlight .bp {
242
+ color: #999;
243
+ }
244
+
245
+ .highlight .vc {
246
+ color: #008080;
247
+ }
248
+
249
+ .highlight .vg {
250
+ color: #008080;
251
+ }
252
+
253
+ .highlight .vi {
254
+ color: #008080;
255
+ }
256
+
257
+ .highlight .il {
258
+ color: #099;
259
+ }
260
+
261
+ .type-csharp .highlight .k {
262
+ color: #00F;
263
+ }
264
+
265
+ .type-csharp .highlight .kt {
266
+ color: #00F;
267
+ }
268
+
269
+ .type-csharp .highlight .nf {
270
+ color: #000;
271
+ font-weight: normal;
272
+ }
273
+
274
+ .type-csharp .highlight .nc {
275
+ color: #2B91AF;
276
+ }
277
+
278
+ .type-csharp .highlight .nn {
279
+ color: #000;
280
+ }
281
+
282
+ .type-csharp .highlight .s {
283
+ color: #A31515;
284
+ }
285
+
286
+ .type-csharp .highlight .sc {
287
+ color: #A31515;
288
+ }