write 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ # Write
2
+
3
+ gem "write"
4
+
5
+ Write is a mountable Rails engine that gives the ability to use Github gists as a backend store for customizable blog tool.
6
+
7
+ Install the gem, mount it somewhere under your site, configure the account to use for gists, and you're done. No database needed.
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Write'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,14 @@
1
+ jQuery ($)->
2
+ commentNode = (comment) ->
3
+ container = $("<div>").addClass("comment-container")
4
+ container.append $("<div>").addClass("comment-author").text(comment.user.login)
5
+ container.append $("<div>").addClass("comment-time").text(comment.updated_at)
6
+ container.append $("<div>").addClass("comment-content").text(comment.body)
7
+ $.ajax
8
+ dataType: 'jsonp',
9
+ url: $('#post-view').data('comments-url')
10
+ success: (response) ->
11
+ $("#comments").text("")
12
+ for comment in response.data
13
+ $("#comments").append(commentNode(comment))
14
+
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,60 @@
1
+ .highlight { background: #ffffff; }
2
+ .highlight .c { color: #999988; font-style: italic } /* Comment */
3
+ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
4
+ .highlight .k { font-weight: bold } /* Keyword */
5
+ .highlight .o { font-weight: bold } /* Operator */
6
+ .highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
7
+ .highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
8
+ .highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
9
+ .highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
10
+ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
11
+ .highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
12
+ .highlight .ge { font-style: italic } /* Generic.Emph */
13
+ .highlight .gr { color: #aa0000 } /* Generic.Error */
14
+ .highlight .gh { color: #999999 } /* Generic.Heading */
15
+ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
16
+ .highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
17
+ .highlight .go { color: #888888 } /* Generic.Output */
18
+ .highlight .gp { color: #555555 } /* Generic.Prompt */
19
+ .highlight .gs { font-weight: bold } /* Generic.Strong */
20
+ .highlight .gu { color: #aaaaaa } /* Generic.Subheading */
21
+ .highlight .gt { color: #aa0000 } /* Generic.Traceback */
22
+ .highlight .kc { font-weight: bold } /* Keyword.Constant */
23
+ .highlight .kd { font-weight: bold } /* Keyword.Declaration */
24
+ .highlight .kp { font-weight: bold } /* Keyword.Pseudo */
25
+ .highlight .kr { font-weight: bold } /* Keyword.Reserved */
26
+ .highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
27
+ .highlight .m { color: #009999 } /* Literal.Number */
28
+ .highlight .s { color: #d14 } /* Literal.String */
29
+ .highlight .na { color: #008080 } /* Name.Attribute */
30
+ .highlight .nb { color: #0086B3 } /* Name.Builtin */
31
+ .highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
32
+ .highlight .no { color: #008080 } /* Name.Constant */
33
+ .highlight .ni { color: #800080 } /* Name.Entity */
34
+ .highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
35
+ .highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
36
+ .highlight .nn { color: #555555 } /* Name.Namespace */
37
+ .highlight .nt { color: #000080 } /* Name.Tag */
38
+ .highlight .nv { color: #008080 } /* Name.Variable */
39
+ .highlight .ow { font-weight: bold } /* Operator.Word */
40
+ .highlight .w { color: #bbbbbb } /* Text.Whitespace */
41
+ .highlight .mf { color: #009999 } /* Literal.Number.Float */
42
+ .highlight .mh { color: #009999 } /* Literal.Number.Hex */
43
+ .highlight .mi { color: #009999 } /* Literal.Number.Integer */
44
+ .highlight .mo { color: #009999 } /* Literal.Number.Oct */
45
+ .highlight .sb { color: #d14 } /* Literal.String.Backtick */
46
+ .highlight .sc { color: #d14 } /* Literal.String.Char */
47
+ .highlight .sd { color: #d14 } /* Literal.String.Doc */
48
+ .highlight .s2 { color: #d14 } /* Literal.String.Double */
49
+ .highlight .se { color: #d14 } /* Literal.String.Escape */
50
+ .highlight .sh { color: #d14 } /* Literal.String.Heredoc */
51
+ .highlight .si { color: #d14 } /* Literal.String.Interpol */
52
+ .highlight .sx { color: #d14 } /* Literal.String.Other */
53
+ .highlight .sr { color: #009926 } /* Literal.String.Regex */
54
+ .highlight .s1 { color: #d14 } /* Literal.String.Single */
55
+ .highlight .ss { color: #990073 } /* Literal.String.Symbol */
56
+ .highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
57
+ .highlight .vc { color: #008080 } /* Name.Variable.Class */
58
+ .highlight .vg { color: #008080 } /* Name.Variable.Global */
59
+ .highlight .vi { color: #008080 } /* Name.Variable.Instance */
60
+ .highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
@@ -0,0 +1,4 @@
1
+ module Write
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,13 @@
1
+ require_dependency "write/application_controller"
2
+
3
+ module Write
4
+ class PostsController < ApplicationController
5
+ layout Write.layout
6
+ def index
7
+ @posts = GG.all
8
+ end
9
+ def show
10
+ @post = GG.find params[:code]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Write
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,50 @@
1
+ class GG
2
+ def self.url path
3
+ "https://api.github.com" + path
4
+ end
5
+
6
+ def self.fetch
7
+ posts = []
8
+ Write.accounts.each do |username, password|
9
+ JSON.parse(open(url "/users/#{username}/gists").read).each do |p|
10
+ next unless p["files"]["write.md"]
11
+ post = new(p)
12
+ posts.push post
13
+ end
14
+ end
15
+ Rails.cache.write "write.posts", posts
16
+ end
17
+
18
+ def self.all
19
+ Rails.cache.read "write.posts"
20
+ end
21
+
22
+ def self.find code
23
+ all.find { |p| p.code == code }
24
+ end
25
+
26
+ attr_reader :code
27
+
28
+ def initialize attributes
29
+ @attributes = attributes
30
+ @code = attributes["description"].downcase.gsub(/[^a-z0-9]/, "-").squeeze
31
+ @raw_url = files["write.md"]["raw_url"]
32
+ puts "*** Write *** Caching post #{@code}"
33
+ @raw_data = open(@raw_url).read
34
+ Rails.cache.write "write.post-#{id}", @raw_data
35
+ end
36
+
37
+ def id
38
+ @attributes["id"]
39
+ end
40
+
41
+ def content
42
+ Rails.cache.read "write.post-#{id}"
43
+ end
44
+
45
+ def method_missing method, *args, &block
46
+ attribute = @attributes[method.to_s]
47
+ return attribute if attribute
48
+ super
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Write</title>
5
+ <%= stylesheet_link_tag "write/application", :media => "all" %>
6
+ <%= javascript_include_tag "write/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,16 @@
1
+ <% content_for :title, Write.title + " - " + Write.tagline %>
2
+
3
+ <%= stylesheet_link_tag "write/application", :media => "all" %>
4
+
5
+ <%= content_tag :div, Write.tagline, class: "blog-title" %>
6
+
7
+ <% @posts.each do |p| %>
8
+ <div class="post-container">
9
+ <%= link_to p.description, short_post_path(p.code), class: "post-title" %>
10
+ <%= content_tag :div, time_ago_in_words(p.updated_at) + " ago", class: "post-time" %>
11
+ <div class="post-content">
12
+ <%= truncate_html(Write::MD.render(p.content), :length => 256).html_safe %>
13
+ <%= link_to "Read", short_post_path(p.code), class: "post-continue" %>
14
+ </div>
15
+ </div>
16
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <% content_for :title, Write.title + " - " + @post.description %>
2
+
3
+ <%= stylesheet_link_tag "write/application", :media => "all" %>
4
+
5
+ <div id="post-view" data-comments-url="<%= @post.comments_url %>">
6
+ <%= content_tag :div, @post.description, class: "post-title" %>
7
+ <%= content_tag :div, time_ago_in_words(@post.updated_at) + " ago", class: "post-time" %>
8
+
9
+ <%= content_tag :div, Write::MD.render(@post.content).html_safe, class: "post-content" %>
10
+
11
+ <div id="comments">Loading ...</div>
12
+ </div>
13
+
14
+ <%= javascript_include_tag "write/comments" %>
@@ -0,0 +1,5 @@
1
+ Write::Engine.routes.draw do
2
+ resources :posts
3
+ get ":code" => "posts#show", :as => :short_post
4
+ root to: "posts#index"
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :write do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,34 @@
1
+ require "write/engine"
2
+ require "pygmentize"
3
+ require "redcarpet"
4
+ require "open-uri"
5
+ require "truncate_html"
6
+
7
+ module Write
8
+ mattr_accessor :config
9
+
10
+ def self.accounts
11
+ config[:accounts] || { "github" => "changeme" }
12
+ end
13
+
14
+ def self.title
15
+ config[:title] || "A Write Blog"
16
+ end
17
+
18
+ def self.tagline
19
+ config[:tagline] || "Blog using github gists as your data store"
20
+ end
21
+
22
+ def self.layout
23
+ config[:layout] || "application"
24
+ end
25
+
26
+ class PygmentizeHTML < Redcarpet::Render::HTML
27
+ def block_code(code, language)
28
+ Pygmentize.process(code, language)
29
+ end
30
+ end
31
+ MD = Redcarpet::Markdown.new(PygmentizeHTML, fenced_code_blocks: true, autolink: true, space_after_headers: true, strikethrough: true, superscript: true)
32
+ end
33
+
34
+ Write.config = {}
@@ -0,0 +1,8 @@
1
+ module Write
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Write
4
+ config.after_initialize do
5
+ GG.fetch if Write.accounts.present?
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Write
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: write
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Samer Buna
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: coffee-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sass-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: redcarpet
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pygmentize
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: truncate_html
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: jquery-rails
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rspec-rails
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: capybara
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: Mountable Rails Engine that gives you the ability to add a github-gist-stored
159
+ blog to your site.
160
+ email:
161
+ - samer.buna@gmail.com
162
+ executables: []
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - app/controllers/write/application_controller.rb
167
+ - app/controllers/write/posts_controller.rb
168
+ - app/helpers/write/application_helper.rb
169
+ - app/models/gg.rb
170
+ - app/views/layouts/write/application.html.erb
171
+ - app/views/write/posts/index.html.erb
172
+ - app/views/write/posts/show.html.erb
173
+ - app/assets/stylesheets/write/application.css
174
+ - app/assets/stylesheets/write/pygments.css
175
+ - app/assets/javascripts/write/application.js
176
+ - app/assets/javascripts/write/comments.js.coffee
177
+ - config/routes.rb
178
+ - lib/write/version.rb
179
+ - lib/write/engine.rb
180
+ - lib/tasks/write_tasks.rake
181
+ - lib/write.rb
182
+ - MIT-LICENSE
183
+ - Rakefile
184
+ - README.md
185
+ homepage: https://github.com/samerbuna/write
186
+ licenses: []
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ none: false
199
+ requirements:
200
+ - - ! '>='
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ requirements: []
204
+ rubyforge_project:
205
+ rubygems_version: 1.8.24
206
+ signing_key:
207
+ specification_version: 3
208
+ summary: Blog using github gists
209
+ test_files: []