-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkalimba.rb
860 lines (781 loc) · 24.4 KB
/
kalimba.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
%w{camping embedly open-uri nokogiri json digest/sha1 ostruct sass yaml builder}.each {|r| require r}
Camping.goes :Kalimba
CONFIG = YAML.load(File.read('config/app.yml'))
module Kalimba
def r404 path
@code = 404
@message = "Page Not Found"
render :error
end
def r500 klass, method, exception
puts exception.inspect
puts exception.backtrace
@code = 500
@message = "An Unexpected Error Has Occurred"
render :error
end
def r501 method
@code = 501
@message = "#{method.capitalize} Isn't Supported"
render :error
end
end
module Kalimba::Models
class Article < Base
def self.normalize_url link
if link !~ /^http/
"#{CONFIG[:hn_root]}#{link}"
else
link
end
end
def author_link
Article.normalize_url("user?id=#{self.author}")
end
end
class Update < Base; end
class Preview < Base
def self._key url
Digest::SHA1.hexdigest(url)
end
def self.key_exists? url
find_redirect(url) or find_preview(url)
end
def self.find_redirect url
key = "r::#{_key url}"
find(:first, :conditions => {:key => key})
end
def self.find_preview url
key = "p::#{_key url}"
prev = find(:first, :conditions => {:key => key})
return prev if prev
if redirect = find_redirect(url)
return find_preview(redirect.value)
else
nil
end
end
def self.save_preview requested_url, preview
if preview.url != requested_url
key = "r::#{_key requested_url}"
# does the redirect exist?
r = find(:first, :conditions => { :key => key })
# it does, so update if needed
if r and r.value != preview.url
r.value = preview.url
r.save
# nope, let's created it
else
create :key => key, :value => preview.url
end
end
key = "p::#{_key preview.url}"
create :key => key, :value => preview.marshal_dump.to_json
end
end
class CreateTables < V 0.1
def self.up
create_table Article.table_name do |t|
t.integer :rank
t.string :title
t.string :link
t.string :comments
end
create_table Preview.table_name do |t|
t.string :key
t.text :value
t.timestamps
end
end
def self.down
drop_table Article.table_name
drop_table Preview.table_name
end
end
class AddMeta < V 0.2
def self.up
change_table Article.table_name do |t|
t.integer :comment_count
t.string :author
t.integer :points
end
end
def self.down
remove_column Article.table_name, :comment_count
remove_column Article.table_name, :author
remove_column Article.table_name, :points
end
end
class AddTopComment < V 0.3
def self.up
change_table Article.table_name do |t|
t.text :top_comment_content
t.string :top_comment_author
t.integer :top_comment_points
end
end
def self.down
remove_column Article.table_name, :top_comment_content
remove_column Article.table_name, :top_comment_author
remove_column Article.table_name, :top_comment_points
end
end
class AddRateLimit < V 0.4
def self.up
create_table Update.table_name do |t|
t.string :caller
t.timestamps
end
end
def self.down
drop_table Update.table_name
end
end
class RemoveTopCommentPoints < V 0.5
def self.up
remove_column Article.table_name, :top_comment_points
end
def self.down
change_table Article.table_name do |t|
t.integer :top_comment_points
end
end
end
class WidenTopCommentAuthor < V 0.6
def self.up
change_column Article.table_name, "top_comment_author", :text
end
def self.down
change_column Article.table_name, "top_comment_author", :string
end
end
class WidenLink < V 0.7
def self.up
change_column Article.table_name, "link", :text
end
def self.down
change_column Article.table_name, "link", :string
end
end
end
module Kalimba::Controllers
class Index
def get
raise 'Failure' if @input.fail # for testing
@shortcuts_on = true
@articles = []
Article::find(:all, :order => 'id').each do |a|
preview_row = Preview.find_preview(Article.normalize_url(a.link))
preview = ::Embedly::EmbedlyObject.new(JSON.parse(preview_row.value)) if preview_row
@articles << [a, preview]
end
render :list_articles
end
end
class Update
def get
last_update = Kalimba::Models::Update.find(:last)
if CONFIG[:rate_limit] and last_update and
last_update.created_at + CONFIG[:rate_limit].seconds > Time.now
redirect R(Index)
return
end
# clean cache
Preview.where("created_at < :expiration",
:expiration => Time.now - 2.days).each do |r|
r.delete
end
articles = []
doc = Nokogiri::HTML(open(CONFIG[:hn_root]), CONFIG[:hn_root], 'UTF-8')
doc.css('.subtext').xpath('..').each do |subtext|
article = subtext.previous
begin
articles << {
:rank => article.at_css('.title').inner_html.strip,
:title => article.at_css('.title/a').inner_html.strip,
:link => article.at_css('.title/a')[:href],
:comments => Article.normalize_url(subtext.at_css('a:last')[:href]),
:comment_count => subtext.at_css('a:last').inner_html[/\d+/].to_i,
:author => subtext.at_css('a').inner_html.strip,
:points => subtext.at_css('span').inner_html[/\d+/].to_i
}
rescue
# TODO something?
puts "Failed to parse article"
puts $!.inspect
puts $!.backtrace
end
end
if CONFIG[:top_comment]
articles.each do |a|
begin
doc = Nokogiri::HTML(open(a[:comments]))
top_comment = doc.at_css('.default')
if top_comment
a[:top_comment_author] = top_comment.at_css('.comhead/a').inner_html.strip
content = []
node = top_comment.at_css('.comment')
# we are intentionally skipping the last node (reply node)
while node.next
content << node.to_s
node = node.next
end
a[:top_comment_content] = content.join
end
rescue
# TODO something?
puts "Failed to parse #{a[:comments]}"
puts $!.inspect
puts $!.backtrace
end
end
end
urls = articles.collect {|a| Article.normalize_url(a[:link])}.reject {|a| Preview.key_exists? a}
if urls.size > 0
[urls[0..14], urls[15..-1]].each do |u|
api = ::Embedly::API.new :key => CONFIG[:embedly_key], :user_agent => 'Mozilla/5.0 (compatible; Kalimba/0.1;)'
api.preview(:urls => u, :maxwidth => 200).each_with_index do |preview, i|
begin
Preview.save_preview urls[i], preview
rescue
puts "Failed to save #{urls[i]}"
end
end
end
end
Article.delete_all
Article.create articles
Kalimba::Models::Update.create :caller => @request.env['REMOTE_ADDR']
redirect R(Index)
end
end
class KeysJs < R "/media/js/keys.js"
def get
@headers['Content-Type'] = 'text/javascript'
render :_keys_js
end
end
class ShareaholicJs < R "/media/js/shareaholic.js"
def get
@headers['Content-Type'] = 'text/javascript'
render :_shareaholic_js
end
end
class ImagesJs < R "/media/js/images.js"
def get
@headers['Content-Type'] = 'text/javascript'
render :_images_js
end
end
class AnalyticsJs < R "/media/js/analytics.js"
def get
@headers['Content-Type'] = 'text/javascript'
render :_analytics_js
end
end
class Rss < R "/atom.xml"
def get
@last_update = Kalimba::Models::Update.find(:last)
return unless @last_update
@articles = []
Article::find(:all, :order => 'id').each do |a|
preview_row = Preview.find_preview(Article.normalize_url(a.link))
preview = ::Embedly::EmbedlyObject.new(JSON.parse(preview_row.value)) if preview_row
@articles << [a, preview_row, preview]
end
@headers['Content-Type'] = 'application/atom+xml; charset=utf-8'
@b = ::Builder::XmlMarkup.new :indent => 2
@b.instruct!
render :_rss
end
end
# dummies to make links
class Image < R "#{CONFIG[:image_root]}/(.*)"; end
class Javascript < R "#{CONFIG[:js_root]}/(.*)"; end
class Css < R "#{CONFIG[:css_root]}/(.*)"; end
class HackerNews < R "#{CONFIG[:hn_root]}/(.*)"; end
class GoogleApi < R "#{CONFIG[:google_api]}/(.*)"; end
class GoogleFonts < R "http://fonts.googleapis.com/css"; end
end
module Kalimba::Views
def layout
xhtml_transitional do
head do
title { "Kalimba - #{CONFIG[:tagline]}" }
link :href => '/static/css/reset.css', :type => 'text/css', :rel => 'stylesheet'
link :href => '/static/css/main.css', :type => 'text/css', :rel => 'stylesheet'
link :href => R(Css, 'facebox.css'), :type => 'text/css', :rel => 'stylesheet'
link :href => R(GoogleFonts, :family => 'Tangerine'), :type => 'text/css', :rel => 'stylesheet'
link :rel => 'canonical', :href => CONFIG[:canonical_url]
link :rel => 'icon', :href => R(Image, 'favicon.ico'), :type => 'image/x-icon'
link :rel => 'image_src', :href => 'http://static.embed.ly/images/logos/embedly-powered-large-light.png'
if CONFIG[:rss]
link :rel => 'alternative', :type => 'application/rss+xml', :title => 'Kalimba Feedburner RSS Feed', :href => CONFIG[:rss]
else
link :rel => 'alternative', :type => 'application/atom+xml', :title => 'Kalimba Atom Feed', :href => R(Rss)
end
meta :name => 'description', :content => CONFIG[:tagline]
meta :name => 'author', :content => 'Embed.ly, Inc.'
meta :name => 'keywords', :content => 'Hacker News, embedly, embed, news, hacker, ycombinator'
script(:type => 'text/javascript', :src => R(GoogleApi, 'jquery/1.5.1/jquery.min.js')) {}
script(:type => 'text/javascript', :src => R(GoogleApi, 'jqueryui/1.8.9/jquery-ui.min.js')) {}
script(:type => 'text/javascript', :src => R(Javascript, 'facebox.js')) {}
script(:type => 'text/javascript', :src => R(KeysJs)) {}
if CONFIG[:shareaholic_key]
script(:type => 'text/javascript', :src => R(ShareaholicJs)) {}
script(:type => 'text/javascript', :src => CONFIG[:shareaholic_plugin]) {}
end
if CONFIG[:google_analytics_key]
script(:type => 'text/javascript', :src => R(AnalyticsJs)) {}
end
script(:type => 'text/javascript', :src => R(ImagesJs)) {}
end
body do
div.header do
div.title do
a.home "KALIMBA - #{CONFIG[:tagline]}", :href => CONFIG[:canonical_url]
a.keyboard_link.open_help.help_icon! do
img.rss :src => R(Image, 'keyboard.png'), :alt => 'keys'
end
a.rss_link :href => (CONFIG[:rss] or R(Rss)) do
img.rss :src => R(Image, 'feed-icon32x32.png'), :alt => 'rss'
end
end
end
div.main do
self << yield
div.clear {}
div.footer do
a 'About', :href => 'http://news.ycombinator.com/item?id=2152950'
self << ' | '
a 'Hacker News', :href => 'http://news.ycombinator.com'
self << ' | '
a 'Embedly', :href => 'http://embed.ly'
self << ' | '
a 'Feedback', :href => "mailto:#{CONFIG[:author_email]}"
self << ' | '
a '@doki_pen', :href => 'http://twitter.com/doki_pen'
if @shortcuts_on
self << ' | '
a 'Shortcuts', :name => 'keys'
end
end
end
end
end
end
def list_articles
ul.article_list do
@articles.each do |article, preview|
li.article do
a.index :name => article.rank {}
div.article_rank { "#{article.rank}" }
div.article_content do
if preview and preview.title and preview.title.strip != ''
_embed(article, preview)
else
div.embedly do
div.embedly_title do
a.article_link(:href => article.link, :target => '_blank') {article.title}
end
end
end
div.article_meta do
self << "#{article.points} points by "
a.author_link article.author,
:href => article.author_link, :target => '_blank'
self << " | "
a.comment_link "#{article.comment_count} comments",
:href => article.comments, :target => '_blank'
if CONFIG[:tagline] and article.comment_count and article.comment_count > 0
a.top_comment_link :href => '#', :title => 'see top comment' do
self << ' '
img.top_comment_icon :src => R(Image, "icon_eye.png"), :alt => 'see top comment'
end
div.top_comment do
div.comment_head do
self << "by "
a.top_comment_author article.top_comment_author,
:href => R(HackerNews, "user", :id=> article.top_comment_author)
end
div.comment_content { article.top_comment_content }
end
end
end
end
div.clear {}
end
end
end
div.like {CONFIG[:fblike_fragment]}
div.clear {}
div.shr {}
div.shortcuts! do
h2 'Keyboard Shortcuts'
hr
dl.shortcut do
dt { 'j or →' }
dd 'Select next article'
end
dl.shortcut do
dt { 'k or ←' }
dd 'Select previous article'
end
dl.shortcut do
dt 'c'
dd 'Toggle Hacker News top comment'
end
dl.shortcut do
dt 'shift + c'
dd 'Open Hacker News comments page in a new window'
end
dl.shortcut do
dt 'd'
dd 'Toggle article content'
end
dl.shortcut do
dt 'enter'
dd 'Follow the article link in this window'
end
dl.shortcut do
dt 'shift + enter'
dd 'Follow the article link in a new window'
end
dl.shortcut do
dt '?'
dd 'Show this keyboard shortcuts dialog'
end
end
end
def _content preview
begin
case preview.type
when 'image'
a.embedly_thumbnail(:href => preview.original_url) do
img.thumbnail :src => preview.url, :alt => 'goto article'
end
when 'video'
video.embedly_video :src => preview.url, :controls => "controls", :preload => "preload"
when 'audio'
audio.embedly_video :src => preview.url, :controls => "controls", :preload => "preload"
else
if preview.content
div.embedly_content do
p { preview.content }
end
else
case preview.object.type
when 'photo'
div.embedly_content do
a.embedly_thumbnail :href => preview.original_url do
img.thumbnail :src => preview.object_url, :alt => 'goto article'
end
end
when 'video'
div.embedly_content { preview.object.html }
when 'rich'
div.embedly_content { preview.html }
else
div.embedly_content do
if preview.images.length != 0
a.embedly_thumbnail_small :target => '_blank', :href => preview.original_url, :title => preview.url do
img.thumbnail :src => preview.images.first['url'], :alt => 'thumbnail'
end
end
p { preview.description }
div { preview.embeds.first['html'] if preview.embeds.length > 0 }
end
end
end
end
div.clear {}
div.provider :style => 'float: right;' do
self << 'via '
if preview.favicon_url
img.provider_favicon :src => preview.favicon_url, :alt => 'favicon'
self << ' '
end
a.provider_link preview.provider_name, :href => preview.provider_url
end
rescue
puts $!
puts $!.backtrace
div.embedly_content { 'ERROR' }
div.clear {}
end
end
def _embed article, preview
div.embedly do
div.embedly_title do
a(:target => '_blank', :href => preview.original_url, :title => preview.url) {article.title}
end
_content preview
end
end
def _rss_content article, preview
div do
self << "#{article.points} points by "
a article.author, :href => article.author_link
self << " | "
a "#{article.comment_count} comments", :href => article.comments
end
hr
_content preview
div(:style => 'clear: both;') {' '}
hr
if CONFIG[:tagline] and article.comment_count and article.comment_count > 0
div do
div do
self << "by "
a article.top_comment_author, :href => R(HackerNews, "user", :id => article.top_comment_author)
end
br
div { article.top_comment_content }
end
end
end
def _rss
if @last_update
self << @b.feed('xmlns' => 'http://www.w3.org/2005/Atom') do |f|
f.title 'Kalimba'
f.link :href => CONFIG[:canonical_url]
id = CONFIG[:canonical_url]
id = "#{id}/" unless id.end_with?'/'
f.id id
f.link :rel => 'self', :type => 'application/atom+xml', :href=> "#{CONFIG[:canonical_url]}#{R(Rss)}"
f.subtitle CONFIG[:tagline]
f.updated @last_update.created_at.utc.strftime("%Y-%m-%dT%H:%S:%MZ")
f.author do |a|
a.name CONFIG[:author_name]
a.email CONFIG[:author_email]
a.uri CONFIG[:author_uri]
end
f.generator 'Kalimba'
@articles.each do |article, preview_row, preview|
f.entry do |i|
i.title article.title
i.link article.link, :href => Kalimba::Models::Article.normalize_url(article.link)
id = Kalimba::Models::Article.normalize_url(article.link)
id = "#{id}/" unless id.end_with?'/'
i.id id
if preview_row
i.updated preview_row.created_at.utc.strftime("%Y-%m-%dT%H:%S:%MZ")
i.published preview_row.created_at.utc.strftime("%Y-%m-%dT%H:%S:%MZ")
else
i.updated @last_update.created_at.utc.strftime("%Y-%m-%dT%H:%S:%MZ")
i.published @last_update.created_at.utc.strftime("%Y-%m-%dT%H:%S:%MZ")
end
i.author do |author|
author.name article.author
author.uri article.author_link
end
content = render(:_rss_content, article, preview) if preview
if content
i.content content, :type => 'html'
end
if preview
i.summary preview.description, :type => 'html'
end
end
end
end
end
end
def error
div.error do
center do
h1 "We're Sorry"
img :src => R(Image, 'kalimba-piano.jpg'), :alt => 'not found'
h1 "#{@code} - #{@message}"
end
end
end
def _images_js
self <<<<-"END"
jQuery(document).ready(function($) {
$('img').error(function() {
this.style.display='none'
})
})
END
end
def _keys_js
self <<<<-"END"
jQuery(document).ready(function($) {
$('.top_comment_link').click(function(event) {
event.preventDefault();
$(this).parent().find('.top_comment').toggle('fast');
});
$.facebox.settings.loadingImage = '#{R(Image, 'loading.gif')}'
$.facebox.settings.closeImage = '#{R(Image, 'closelabel.png')}'
$.facebox.settings.opacity = 0.2
$.facebox.settings.faceboxHtml = '\
<div id="facebox" style="display:none;"> \
<div class="popup"> \
<div class="content"> \
</div> \
<a href="#" class="close"><img src="#{R(Image, 'closelabel.png')}" title="close" class="close_image" /></a> \
</div> \
</div>'
function State() {
this.index = -1
this.max = $('ul.article_list > li.article').size();
this.toggle = 'fast';
}
State.prototype.current = function() {
return $($('.article')[this.index])
}
State.prototype.inRange = function() {
return this.index >= 0 && this.index < this.max
}
State.prototype.up = function() {
if (this.index > 0) {
this.index--;
this.index %= this.max;
this.highlight(true);
}
}
State.prototype.down = function() {
if (this.index < this.max - 1) {
this.index++;
this.index %= this.max;
this.highlight(true);
}
}
State.prototype.toggle_content = function() {
if (this.inRange()) {
this.current().find('.embedly_content').toggle(this.toggle)
}
}
State.prototype.toggle_comments = function() {
if (this.inRange()) {
this.current().find('.top_comment').toggle(this.toggle)
}
}
State.prototype.goto_comments = function() {
if (this.inRange()) {
window.open(this.current().find('.comment_link').attr('href'))
}
}
State.prototype.follow = function(shift) {
if (this.inRange()) {
var href = this.current().find('.embedly_title').find('a').last().attr('href');
if (shift) {
window.open(href);
} else {
document.location.href = href;
}
}
}
State.prototype.highlight = function(goto_rank) {
$('.article_rank').removeClass('selected');
if (this.inRange()) {
state.current().find('div.article_rank').addClass('selected');
if (goto_rank) {
document.location.href = '#'+(this.index+1);
}
}
}
State.prototype.help = function() {
$.facebox({div: '#shortcuts'});
}
var state = new State();
// keypress mappings
var KEYS = {
106: 'down', // j
107: 'up', // k
99: 'toggle_comments', // c
67: 'goto_comments', // C
100: 'toggle_content', // d
13: 'follow', // enter
63: 'help' // ?
}
// keyup mappings
var ARROWS = {
37: 'up', // up arrow
39: 'down' // down arrow
}
$(document).keypress(function(event) {
var command = KEYS[event.which];
if (command) {
event.preventDefault();
state[command](event.shiftKey);
}
});
$(document).keyup(function(event) {
var command = ARROWS[event.keyCode];
if (command) {
event.preventDefault();
state[command](event.shiftKey);
}
});
$(document).scroll(function() {
var top = $(document).scrollTop()
, current = null
, ranks = $('div.article_rank')
for (var i in $.makeArray(ranks)) {
var r = $(ranks[i])
if (r.offset().top >= top) {
current = i
break
}
}
if (current != state.index) {
state.index = current;
state.highlight()
}
})
$('.open_help').click(function() {state.help()})
$('a[name=keys]').click(function() {
state.help();
});
if (document.location.hash) {
state.index = document.location.hash.substring(1) - 1;
state.highlight(true);
} else {
state.index = 0
state.highlight()
}
});
END
end
def _shareaholic_js
self <<<<-"END"
jQuery(document).ready(function($) {
if (typeof(SHR4P) == 'undefined') {
SHR4P = {};
}
SHR4P.onready = function() {
SHR4P.jQuery('.shr').shareaholic_publishers({
mode: 'inject',
showShareCount: true,
service: '202,7,5,40,2,52,3',
apikey: '#{CONFIG[:shareaholic_key]}',
link: "#{CONFIG[:canonical_url]}",
short_link: '#{CONFIG[:short_url]}',
title: 'Kalimba - #{CONFIG[:tagline]}',
center: true
});
};
if (typeof(SHR4P.ready) != 'undefined' && SHR4P.ready) {
SHR4P.onready();
}
});
END
end
def _analytics_js
self <<<<-"END"
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '#{CONFIG[:google_analytics_key]}']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
END
end
end
def Kalimba.create
Kalimba::Models.create_schema
end