low_voltage 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/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/controllers/low_voltage/posts_controller.rb +44 -0
- data/app/views/low_voltage/posts/index.html.erb +24 -0
- data/app/views/low_voltage/posts/show.html.erb +10 -0
- data/config/routes.rb +5 -0
- data/lib/low_voltage.rb +18 -0
- data/lib/low_voltage/configuration.rb +17 -0
- data/lib/low_voltage/engine.rb +6 -0
- data/lib/low_voltage/post.rb +32 -0
- data/lib/low_voltage/post_finder.rb +13 -0
- data/lib/low_voltage/version.rb +3 -0
- data/low_voltage.gemspec +23 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Adam Michel
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Low Voltage
|
2
|
+
|
3
|
+
If you've heard of [High Voltage](https://github.com/thoughtbot/high_voltage) then all you need to know is we're like that, but for blogs.
|
4
|
+
|
5
|
+
High Voltage allows you to very easily setup static pages in your Rails app without having to setup extra controllers and actions. You put a page of content in a pages folder under your views and it shows up on your website as `/pages/blah`. This is the same concept, only with a blog format. You write a blog post, add some metadata, drop it in a folder, and voila your blog has a new post.
|
6
|
+
|
7
|
+
I wrote Low Voltage because I used [Nesta](https://github.com/gma/nesta) and really liked it, but then wanted to add more Rails to it. Instead of going through mounting it in my app, I found High Voltage and re-tooled it to work as a blog platform as well.
|
8
|
+
|
9
|
+
## Install
|
10
|
+
|
11
|
+
Add the following line to your Gemfile:
|
12
|
+
|
13
|
+
gem 'low_voltage'
|
14
|
+
|
15
|
+
## Basic Usage
|
16
|
+
|
17
|
+
1. Add a directory called `posts` with a subdirectory called `sources` to your views folder.
|
18
|
+
2. Place your markdown flavored blog posts in the `sources` directory.
|
19
|
+
3. Refresh.
|
20
|
+
|
21
|
+
## TODO
|
22
|
+
|
23
|
+
* Add some basic configuration options to override the defaults.
|
24
|
+
* Add an RSS feed.
|
25
|
+
* I should probably get in the habbit of writing tests...
|
26
|
+
|
27
|
+
## Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2012 Adam Michel. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class LowVoltage::PostsController < ApplicationController
|
2
|
+
layout Proc.new { |_| LowVoltage.configuration.layout }
|
3
|
+
|
4
|
+
if LowVoltage.configuration.use_action_caching
|
5
|
+
caches_action :index, :cache_path => Proc.new { |c| c.params[:offset] }
|
6
|
+
caches_action :show, :cache_path => Proc.new { |c| c.params[:id] }
|
7
|
+
end
|
8
|
+
|
9
|
+
def index
|
10
|
+
@offset = params[:offset].to_i || 0
|
11
|
+
@total_posts, @posts = load_posts(@offset)
|
12
|
+
end
|
13
|
+
|
14
|
+
def show
|
15
|
+
@post = post_factory.new(current_post)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def current_post
|
21
|
+
post_finder.find
|
22
|
+
end
|
23
|
+
|
24
|
+
def post_finder
|
25
|
+
post_finder_factory.new(params[:id])
|
26
|
+
end
|
27
|
+
|
28
|
+
def post_finder_factory
|
29
|
+
LowVoltage::PostFinder
|
30
|
+
end
|
31
|
+
|
32
|
+
def post_factory
|
33
|
+
LowVoltage::Post
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_posts(offset=0, limit=LowVoltage.configuration.posts_per_page)
|
37
|
+
range = (offset)..(offset+limit-1)
|
38
|
+
posts = Dir.glob(LowVoltage.configuration.full_content_path).map do |path|
|
39
|
+
path = post_factory.new(path)
|
40
|
+
end.sort! { |a,b| b.date <=> a.date }
|
41
|
+
[posts.count(), posts.slice(range)]
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<h1>Recent Blog Posts</h1>
|
2
|
+
|
3
|
+
<section class="posts">
|
4
|
+
<% @posts.each do |post| %>
|
5
|
+
<article class="post">
|
6
|
+
<h2><%= link_to post.title, post_path(post.id) %> <small>By <%= post.author %></small></h2>
|
7
|
+
<%= date_bubble(post.date) %>
|
8
|
+
<%= post.content %>
|
9
|
+
</article>
|
10
|
+
<% end %>
|
11
|
+
</section>
|
12
|
+
|
13
|
+
<ul class="blog-pager">
|
14
|
+
<% if @offset > 0 %>
|
15
|
+
<li class="prev">
|
16
|
+
<%= link_to "<i class=\"icon-arrow-left\"></i> Newer".html_safe, posts_path(:offset => @offset - 10) %>
|
17
|
+
</li>
|
18
|
+
<% end %>
|
19
|
+
<% if @offset + 10 < @total_posts %>
|
20
|
+
<li class="next">
|
21
|
+
<%= link_to "Older <i class=\"icon-arrow-right\"></i>".html_safe, posts_path(:offset => @offset + 10) %>
|
22
|
+
</li>
|
23
|
+
<% end %>
|
24
|
+
</ul>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<article class="post">
|
2
|
+
<h1><%= @post.title %> <small>By <%= @post.author %></small></h1>
|
3
|
+
<%= date_bubble(@post.date) %>
|
4
|
+
<%= @post.content %>
|
5
|
+
</article>
|
6
|
+
|
7
|
+
<script type="text/javascript">
|
8
|
+
var disqus_identifier = "<%= @post.id %>";
|
9
|
+
</script>
|
10
|
+
<div id="disqus_thread"></div>
|
data/config/routes.rb
ADDED
data/lib/low_voltage.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'low_voltage/version'
|
2
|
+
require 'low_voltage/configuration'
|
3
|
+
|
4
|
+
module LowVoltage
|
5
|
+
autoload :PostFinder, 'low_voltage/post_finder'
|
6
|
+
autoload :Post, 'low_voltage/post'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
self.configuration ||= Configuration.new
|
14
|
+
yield(configuration)
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'low_voltage/engine' if defined?(Rails)
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module LowVoltage
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :layout, :content_path, :use_routes, :use_action_caching, :posts_per_page
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@layout = "application"
|
7
|
+
@content_path = "posts"
|
8
|
+
@use_routes = true
|
9
|
+
@use_action_caching = true
|
10
|
+
@posts_per_page = 10
|
11
|
+
end
|
12
|
+
|
13
|
+
def full_content_path
|
14
|
+
Rails.root.join("app/views/#{LowVoltage.configuration.content_path}/*.md")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'metadown'
|
2
|
+
|
3
|
+
module LowVoltage
|
4
|
+
class Post
|
5
|
+
attr_reader :title, :date, :id, :content, :author
|
6
|
+
|
7
|
+
def initialize(path)
|
8
|
+
@id = File.basename(path, ".md")
|
9
|
+
@path = path
|
10
|
+
|
11
|
+
begin
|
12
|
+
parse_post(Metadown.render(IO.read(@path)))
|
13
|
+
rescue Errno::ENOENT
|
14
|
+
raise ActionController::RoutingError, "Post not found: #{path}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def parse_post(data)
|
21
|
+
@content = data.output.html_safe
|
22
|
+
parse_metadata(data.metadata)
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_metadata(metadata)
|
26
|
+
@title = metadata['title'] || @id.titleize
|
27
|
+
@date = Date.parse(metadata['date'] || File.mtime(@path).inspect)
|
28
|
+
@author = metadata['author'] || "Anonymous"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/low_voltage.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "low_voltage/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "low_voltage"
|
7
|
+
s.version = LowVoltage::VERSION
|
8
|
+
s.authors = ["Adam Michel"]
|
9
|
+
s.email = ["awmichel90@gmail.com"]
|
10
|
+
s.homepage = "http://amichel.me"
|
11
|
+
s.summary = %q{Uses concepts from High Voltage for powering a file based blog in Rails.}
|
12
|
+
s.description = %q{Building off High Voltage, Low Voltage allows you to have a file based blog in your Rails app.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "low_voltage"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.add_dependency("high_voltage", ">= 1.2.0")
|
21
|
+
s.add_dependency("metadown", ">= 1.0.1")
|
22
|
+
s.add_development_dependency("rake")
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: low_voltage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Michel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: high_voltage
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.2.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: 1.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: metadown
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.1
|
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: 1.0.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
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
|
+
description: Building off High Voltage, Low Voltage allows you to have a file based
|
63
|
+
blog in your Rails app.
|
64
|
+
email:
|
65
|
+
- awmichel90@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- app/controllers/low_voltage/posts_controller.rb
|
76
|
+
- app/views/low_voltage/posts/index.html.erb
|
77
|
+
- app/views/low_voltage/posts/show.html.erb
|
78
|
+
- config/routes.rb
|
79
|
+
- lib/low_voltage.rb
|
80
|
+
- lib/low_voltage/configuration.rb
|
81
|
+
- lib/low_voltage/engine.rb
|
82
|
+
- lib/low_voltage/post.rb
|
83
|
+
- lib/low_voltage/post_finder.rb
|
84
|
+
- lib/low_voltage/version.rb
|
85
|
+
- low_voltage.gemspec
|
86
|
+
homepage: http://amichel.me
|
87
|
+
licenses: []
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project: low_voltage
|
106
|
+
rubygems_version: 1.8.24
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Uses concepts from High Voltage for powering a file based blog in Rails.
|
110
|
+
test_files: []
|