Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 24284007e9a436c3926e58a1b5cbfc3e984ecbd0 @imathis imathis committed Dec 25, 2013
@@ -0,0 +1,18 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+.DS_Store
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in themebase.gemspec
+gemspec
@@ -0,0 +1,22 @@
+Copyright (c) 2013 Brandon Mathis
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
+# Octopress ThemeKit
+
+Use Themekit to help you build themes and plugins for Jekyll.
+
+### Features
+- Installing ThemeKit plugins is easy. [See how](#user_installation).
+- Users won't need to install or managae plugin assets.
+- Jekyll will read your plugin's layouts, javascripts, stylesheets and more directly from your gem.
+- ThemeKit allows users to modify a theme/plugin by adding their modified version to _themes directory.
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'themebase'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install themebase
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -0,0 +1 @@
+console.log('omg')
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+ <title>{{ page.title }}</title>
+ <meta name="viewport" content="width=device-width">
+ {% theme_css %}
+ </head>
+ <body>
+ {{ content }}
+ {% theme_js %}
+ </body>
+</html>
@@ -0,0 +1,4 @@
+---
+layout: default
+---
+<div class='test'>{{ content }}</div>
@@ -0,0 +1 @@
+div { display: block; }
@@ -0,0 +1,3 @@
+body {
+ margin: 0;
+}
@@ -0,0 +1,43 @@
+require 'jekyll'
+require 'jekyll-page-hooks'
+require 'pry-debugger'
+require 'octopress-themekit/tags/layout'
+require 'octopress-themekit/tags/javascript'
+require 'octopress-themekit/tags/stylesheet'
+require 'octopress-themekit/generators/stylesheets'
+require 'octopress-themekit/generators/javascripts'
+
+module ThemeKit
+ autoload :Stylesheet, 'octopress-themekit/stylesheet'
+ autoload :Theme, 'octopress-themekit/theme'
+ class Template
+ class << self
+ attr_accessor :theme
+ end
+
+ def initialize
+ @plugins = {}
+ end
+
+ def self.register_theme(name, theme)
+ @theme = theme.new()
+ end
+
+ def self.register_plugin(name, plugin)
+ @plugins[name] = plugin.new()
+ end
+
+ def self.all_stylesheets
+ css = []
+ plugins.each do |plugin|
+ css.concat plugin.stylesheets
+ end
+ css
+ end
+ end
+end
+
+Liquid::Template.register_tag('layout', ThemeKit::LayoutTag)
+Liquid::Template.register_tag('do_layout', ThemeKit::DoLayoutTag)
+Liquid::Template.register_tag('theme_js', ThemeKit::JavascriptTag)
+Liquid::Template.register_tag('theme_css', ThemeKit::StylesheetTag)
@@ -0,0 +1,7 @@
+module ThemeKit
+ class Javascripts < Jekyll::Generator
+ def generate(site)
+ Template.theme.output_javascripts(site)
+ end
+ end
+end
@@ -0,0 +1,7 @@
+module ThemeKit
+ class Stylesheets < Jekyll::Generator
+ def generate(site)
+ Template.theme.output_stylesheets(site)
+ end
+ end
+end
@@ -0,0 +1,41 @@
+require 'pry-debugger'
+
+CONTENT = /(.*?)({{\s*content\s*}})(.*)/im
+YAML_HEADER = /\A-{3}(.+[^\A])-{3}\n(.+)/m
+
+module ThemeKit
+ module Render
+ def self.render(tag, file, context)
+ @tag = tag
+ partial = Liquid::Template.parse(read(file, context.registers[:site]))
+ binding.pry
+ context.stack {
+ context['page'] = context['page'].deep_merge(@local_vars) if @local_vars and @local_vars.keys.size > 0
+ partial.render!(context)
+ }.strip
+ end
+
+ def self.read(file, site)
+ file += '.html' unless file =~ /\.html$/
+ content = Template.theme.layout(file, site).read
+ if content =~ YAML_HEADER
+ layout = YAML.safe_load($1.strip)['layout']
+ content = $2.strip
+ content = wrap_layout(layout, content, site)
+ end
+ content
+ end
+
+ def self.wrap_layout(layout, content, site)
+ if layout
+ layout = read(layout, site)
+ if layout =~ CONTENT
+ $1 + content + $3
+ end
+ else
+ content
+ end
+ end
+ end
+end
+
@@ -0,0 +1,16 @@
+module ThemeKit
+ class Stylesheet
+ def initialize(path, media)
+ @path = path
+ @media = media || 'all'
+ end
+
+ def path
+ @path
+ end
+
+ def link(base_url)
+ "<link href='/#{File.join(base_url, path)}' media='#{@media}' rel='stylesheet' type='text/css'>"
+ end
+ end
+end
@@ -0,0 +1,10 @@
+module ThemeKit
+ class JavascriptTag < Liquid::Tag
+ def initialize(tag_name, markup, tokens)
+ super
+ end
+ def render(context)
+ Template.theme.javascript_tag(context.registers[:site])
+ end
+ end
+end
@@ -0,0 +1,51 @@
+require File.join File.expand_path('../../', __FILE__), 'helpers/render'
+
+module ThemeKit
+ class LayoutTag < Liquid::Tag
+ def initialize(tag_name, markup, tokens)
+ @file = markup.strip
+ super
+ end
+ def render(context)
+ Render.render('layout', @file, context)
+ end
+ end
+
+ class DoLayoutTag < Liquid::Block
+ CONTENT = /(.*?)({{\s*content\s*}})(.*)/im
+
+ def initialize(tag_name, markup, tokens)
+ @tag = tag_name
+ @file = markup.strip
+ super
+ end
+
+ def render(context)
+ content = super.strip
+ layout = Render.read(@file, context.registers[:site])
+ if layout =~ CONTENT
+ content = $1 + content + $3
+ else
+ content
+ end
+ partial = Liquid::Template.parse(content)
+ content = context.stack {
+ partial.render!(context)
+ }.strip
+ end
+ end
+end
+
+module Jekyll
+ class ThemeKitHooks < PageHooks
+
+ # Manipulate page/post data before it has been processed with Liquid or
+ # Converters like Markdown or Textile.
+ #
+ def pre_render(page)
+ if page.data['theme_layout']
+ page.content = "{% do_layout #{page.data['theme_layout']} %}#{page.content}{% enddo_layout %}"
+ end
+ end
+ end
+end
@@ -0,0 +1,10 @@
+module ThemeKit
+ class StylesheetTag < Liquid::Tag
+ def initialize(tag_name, markup, tokens)
+ super
+ end
+ def render(context)
+ Template.theme.stylesheet_tag(context.registers[:site])
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 2428400

Please sign in to comment.