Skip to content

Commit 2428400

Browse files
committed
initial commit
0 parents  commit 2428400

28 files changed

+489
-0
lines changed

.gitignore

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
Gemfile.lock
7+
InstalledFiles
8+
_yardoc
9+
coverage
10+
doc/
11+
lib/bundler/man
12+
pkg
13+
rdoc
14+
spec/reports
15+
test/tmp
16+
test/version_tmp
17+
tmp
18+
.DS_Store

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in themebase.gemspec
4+
gemspec

LICENSE.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2013 Brandon Mathis
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Octopress ThemeKit
2+
3+
Use Themekit to help you build themes and plugins for Jekyll.
4+
5+
### Features
6+
- Installing ThemeKit plugins is easy. [See how](#user_installation).
7+
- Users won't need to install or managae plugin assets.
8+
- Jekyll will read your plugin's layouts, javascripts, stylesheets and more directly from your gem.
9+
- ThemeKit allows users to modify a theme/plugin by adding their modified version to _themes directory.
10+
11+
## Installation
12+
13+
Add this line to your application's Gemfile:
14+
15+
gem 'themebase'
16+
17+
And then execute:
18+
19+
$ bundle
20+
21+
Or install it yourself as:
22+
23+
$ gem install themebase
24+
25+
## Usage
26+
27+
TODO: Write usage instructions here
28+
29+
## Contributing
30+
31+
1. Fork it
32+
2. Create your feature branch (`git checkout -b my-new-feature`)
33+
3. Commit your changes (`git commit -am 'Add some feature'`)
34+
4. Push to the branch (`git push origin my-new-feature`)
35+
5. Create new Pull Request

Rakefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require "bundler/gem_tasks"

assets/_theme/javascripts/foo.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('omg')

assets/_theme/layouts/default.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6+
<title>{{ page.title }}</title>
7+
<meta name="viewport" content="width=device-width">
8+
{% theme_css %}
9+
</head>
10+
<body>
11+
{{ content }}
12+
{% theme_js %}
13+
</body>
14+
</html>

assets/_theme/layouts/test.html

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: default
3+
---
4+
<div class='test'>{{ content }}</div>

assets/_theme/stylesheets/foo.css

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
div { display: block; }

assets/_theme/stylesheets/site.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
margin: 0;
3+
}

lib/octopress-themekit.rb

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require 'jekyll'
2+
require 'jekyll-page-hooks'
3+
require 'pry-debugger'
4+
require 'octopress-themekit/tags/layout'
5+
require 'octopress-themekit/tags/javascript'
6+
require 'octopress-themekit/tags/stylesheet'
7+
require 'octopress-themekit/generators/stylesheets'
8+
require 'octopress-themekit/generators/javascripts'
9+
10+
module ThemeKit
11+
autoload :Stylesheet, 'octopress-themekit/stylesheet'
12+
autoload :Theme, 'octopress-themekit/theme'
13+
class Template
14+
class << self
15+
attr_accessor :theme
16+
end
17+
18+
def initialize
19+
@plugins = {}
20+
end
21+
22+
def self.register_theme(name, theme)
23+
@theme = theme.new()
24+
end
25+
26+
def self.register_plugin(name, plugin)
27+
@plugins[name] = plugin.new()
28+
end
29+
30+
def self.all_stylesheets
31+
css = []
32+
plugins.each do |plugin|
33+
css.concat plugin.stylesheets
34+
end
35+
css
36+
end
37+
end
38+
end
39+
40+
Liquid::Template.register_tag('layout', ThemeKit::LayoutTag)
41+
Liquid::Template.register_tag('do_layout', ThemeKit::DoLayoutTag)
42+
Liquid::Template.register_tag('theme_js', ThemeKit::JavascriptTag)
43+
Liquid::Template.register_tag('theme_css', ThemeKit::StylesheetTag)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module ThemeKit
2+
class Javascripts < Jekyll::Generator
3+
def generate(site)
4+
Template.theme.output_javascripts(site)
5+
end
6+
end
7+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module ThemeKit
2+
class Stylesheets < Jekyll::Generator
3+
def generate(site)
4+
Template.theme.output_stylesheets(site)
5+
end
6+
end
7+
end
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'pry-debugger'
2+
3+
CONTENT = /(.*?)({{\s*content\s*}})(.*)/im
4+
YAML_HEADER = /\A-{3}(.+[^\A])-{3}\n(.+)/m
5+
6+
module ThemeKit
7+
module Render
8+
def self.render(tag, file, context)
9+
@tag = tag
10+
partial = Liquid::Template.parse(read(file, context.registers[:site]))
11+
binding.pry
12+
context.stack {
13+
context['page'] = context['page'].deep_merge(@local_vars) if @local_vars and @local_vars.keys.size > 0
14+
partial.render!(context)
15+
}.strip
16+
end
17+
18+
def self.read(file, site)
19+
file += '.html' unless file =~ /\.html$/
20+
content = Template.theme.layout(file, site).read
21+
if content =~ YAML_HEADER
22+
layout = YAML.safe_load($1.strip)['layout']
23+
content = $2.strip
24+
content = wrap_layout(layout, content, site)
25+
end
26+
content
27+
end
28+
29+
def self.wrap_layout(layout, content, site)
30+
if layout
31+
layout = read(layout, site)
32+
if layout =~ CONTENT
33+
$1 + content + $3
34+
end
35+
else
36+
content
37+
end
38+
end
39+
end
40+
end
41+

lib/octopress-themekit/stylesheet.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module ThemeKit
2+
class Stylesheet
3+
def initialize(path, media)
4+
@path = path
5+
@media = media || 'all'
6+
end
7+
8+
def path
9+
@path
10+
end
11+
12+
def link(base_url)
13+
"<link href='/#{File.join(base_url, path)}' media='#{@media}' rel='stylesheet' type='text/css'>"
14+
end
15+
end
16+
end
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module ThemeKit
2+
class JavascriptTag < Liquid::Tag
3+
def initialize(tag_name, markup, tokens)
4+
super
5+
end
6+
def render(context)
7+
Template.theme.javascript_tag(context.registers[:site])
8+
end
9+
end
10+
end

lib/octopress-themekit/tags/layout.rb

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require File.join File.expand_path('../../', __FILE__), 'helpers/render'
2+
3+
module ThemeKit
4+
class LayoutTag < Liquid::Tag
5+
def initialize(tag_name, markup, tokens)
6+
@file = markup.strip
7+
super
8+
end
9+
def render(context)
10+
Render.render('layout', @file, context)
11+
end
12+
end
13+
14+
class DoLayoutTag < Liquid::Block
15+
CONTENT = /(.*?)({{\s*content\s*}})(.*)/im
16+
17+
def initialize(tag_name, markup, tokens)
18+
@tag = tag_name
19+
@file = markup.strip
20+
super
21+
end
22+
23+
def render(context)
24+
content = super.strip
25+
layout = Render.read(@file, context.registers[:site])
26+
if layout =~ CONTENT
27+
content = $1 + content + $3
28+
else
29+
content
30+
end
31+
partial = Liquid::Template.parse(content)
32+
content = context.stack {
33+
partial.render!(context)
34+
}.strip
35+
end
36+
end
37+
end
38+
39+
module Jekyll
40+
class ThemeKitHooks < PageHooks
41+
42+
# Manipulate page/post data before it has been processed with Liquid or
43+
# Converters like Markdown or Textile.
44+
#
45+
def pre_render(page)
46+
if page.data['theme_layout']
47+
page.content = "{% do_layout #{page.data['theme_layout']} %}#{page.content}{% enddo_layout %}"
48+
end
49+
end
50+
end
51+
end
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module ThemeKit
2+
class StylesheetTag < Liquid::Tag
3+
def initialize(tag_name, markup, tokens)
4+
super
5+
end
6+
def render(context)
7+
Template.theme.stylesheet_tag(context.registers[:site])
8+
end
9+
end
10+
end

0 commit comments

Comments
 (0)