static-bartender 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 ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bartender.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Daniel Westendorf
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Bartender
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bartender'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bartender
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bartender.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'bartender/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Daniel Westendorf"]
7
+ gem.email = ["daniel@prowestech.com"]
8
+ gem.description = %q{Build static websites smartly}
9
+ gem.summary = %q{Use layouts, link helpers, and the asset pipeline to create static websites smartly.}
10
+ gem.homepage = ""
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "static-bartender"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = Bartender::VERSION
18
+ gem.add_dependency "deep_merge"
19
+ gem.add_dependency "tilt"
20
+ gem.add_dependency "sprockets"
21
+ end
data/bin/bartender ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ help = <<HELP
6
+ Bartender is a smart static site generator
7
+
8
+ Basic Command Line Usage:
9
+ bartender # . -> ./_site
10
+ bartender --new [SITE NAME] # create a new site by this name
11
+
12
+ Configuration is read from '<source>/_config.yml'
13
+
14
+ HELP
15
+
16
+ require 'optparse'
17
+ require 'bartender'
18
+
19
+ options = {}
20
+
21
+ opts = OptionParser.new do |opts|
22
+ opts.on("--new [SITE NAME]", "Create a new site") do |site_name|
23
+ Bartender::Site.create(site_name)
24
+ end
25
+ end
26
+
27
+ opts.parse!
28
+
29
+ if ARGV.size == 0
30
+ Bartender::Site.new({})
31
+ end
@@ -0,0 +1,22 @@
1
+ module Bartender
2
+
3
+ class Asset
4
+ attr_reader :site_path, :src_file, :digest, :mtime, :file, :dest_path, :sprockets_object, :found
5
+
6
+ def initialize(file, sprockets_env)
7
+ @sprockets_object = sprockets_env[file]
8
+ if @sprockets_object
9
+ @found = true
10
+ split_file_name = file.split("/")
11
+ @file = split_file_name[-1] # asset
12
+ @site_path = @sprockets_object.digest_path # folder/asset-digest.ext
13
+ @src_file = @sprockets_object.pathname # site/asset-folder/asset.ext
14
+ @dest_path = File.join(Bartender::DEFAULTS["output"], site_path) # output/folder/asset-digest.ext
15
+ else
16
+ @found = false #asset doesn't exist, return nothing
17
+ end
18
+ end #Function init
19
+
20
+ end #Class Asset
21
+
22
+ end #Module Bartender
@@ -0,0 +1,78 @@
1
+ module Bartender
2
+
3
+ class Page
4
+ include ViewHelpers
5
+ attr_reader :config, :page, :data, :content, :output, :sprockets_env
6
+
7
+ def initialize(page, sprockets_env)
8
+ @page = page
9
+ @sprockets_env = sprockets_env
10
+ return false unless File.exists?(@page) #does the page actual exist?
11
+ @data = File.read(@page)
12
+ self.read_yaml
13
+ @klass = Tilt[page]
14
+ end #Funciton initialize
15
+
16
+ def compile
17
+ output_path = @page.split('/')
18
+ output_path[0] =Bartender::DEFAULTS['output']
19
+ file_name = output_path[-1].split('.')
20
+ file_name.delete_at(-1)
21
+ output_path[-1] = file_name.join('.')
22
+ @output = output_path.join('/')
23
+ File.delete @output if File.exists? @output
24
+ File.open(@output, 'w') {|f| f.write self.render}
25
+ end #Funciton compile
26
+
27
+ def render
28
+ return nil if @klass.nil? #make sure tilt knows what to render, otherwise return nil
29
+ template = @klass.new {@content}
30
+ compiled = template.render(self)
31
+ if self.layout_specified?
32
+ layout = Tilt.new self.find_layout
33
+ return layout.render(self) {compiled}
34
+ else
35
+ return compiled
36
+ end
37
+ end #Function render
38
+
39
+ def find_layout
40
+ layouts = Dir.glob(Bartender::DEFAULTS['layouts'] + "/#{self.layout}.*")
41
+ if layouts.length > 0
42
+ return layouts[0]
43
+ else
44
+ $stderr.puts "ERROR: Could not find layout file '#{self.layout}' in #{Bartender::DEFAULTS['layouts']} for page #{@page} "
45
+ exit 0
46
+ end
47
+ end #Function find_layout
48
+
49
+ def layout_specified?
50
+ self.layout
51
+ end
52
+
53
+ def read_yaml
54
+ begin
55
+ if @data =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
56
+ @config = YAML.load($1)
57
+ @config.each_key do |k|
58
+ instance_variable_set ('@'<<k).to_sym, @config[k]
59
+ end
60
+ @content = @data
61
+ @content.gsub!(/^(---\s*\n.*?\n?)^(---\s*$\n?)/m, '')
62
+ end
63
+ rescue => e
64
+ puts "YAML Exception reading #{@page}: #{e.message}"
65
+ end
66
+ end #Function read_yaml
67
+
68
+ def method_missing(m, *args)
69
+ if m =~ /^(\w+)=$/
70
+ instance_variable_set "@#{$1}", args[0]
71
+ else
72
+ instance_variable_get "@#{m}"
73
+ end
74
+ end #Funciton method_missing
75
+
76
+ end #Class Page
77
+
78
+ end #Module Bartender
@@ -0,0 +1,66 @@
1
+ require 'sprockets'
2
+ require 'tilt'
3
+ module Bartender
4
+
5
+ class Site
6
+
7
+ #Load the config, and compile the site
8
+ def initialize(config)
9
+ Bartender.configure(config)
10
+
11
+ @sprockets_env = Sprockets::Environment.new
12
+ @sprockets_env.append_path Bartender::DEFAULTS["assets"]
13
+ compile_assets
14
+
15
+ Dir.glob(File.join(Bartender::DEFAULTS["pages"], '/**/*')).each do |page|
16
+ Page.new(page, @sprockets_env).compile unless page.split('/')[-1].match /^_/
17
+ end
18
+ end #Function initialize
19
+
20
+
21
+ #compile the css and js assets for use in the page
22
+ #uses sprokets set an environment, compile them, then get accessed
23
+ def compile_assets
24
+ Dir.glob(File.join(Bartender::DEFAULTS["assets"], '/**/*')).each do |asset|
25
+ asset = Bartender::Asset.new(asset.gsub(File.join(Bartender::DEFAULTS["assets"], '/'), ''), @sprockets_env)
26
+
27
+ if asset.found #make sure sprockets can find the asset
28
+ asset.sprockets_object.write_to(asset.dest_path)
29
+ end
30
+ end
31
+ end #Function compile_assets
32
+
33
+
34
+
35
+ def self.create(name)
36
+ name = File.join(Bartender::DEFAULTS["root"], name)
37
+ if File.directory?(name)
38
+ $stderr.puts "ERROR: Could not create a new site by that name (#{name}), it already exists!"
39
+ exit 0
40
+ else #no conflicts with the site name, create some shit
41
+ Dir.mkdir(name) #make new site dir
42
+ Dir.mkdir(File.join(name, Bartender::DEFAULTS["output"]))
43
+ Bartender::DEFAULTS.values_at("layouts", "pages", "assets").each do |dir| #make default directories
44
+ Dir.mkdir(File.join(name, dir))
45
+ end
46
+
47
+ #make asset directories
48
+ ["js", "css", "images"].each do |asset_dir|
49
+ Dir.mkdir(File.join(File.join(name, Bartender::DEFAULTS["assets"]), asset_dir)) #this is where un-comiled assets go
50
+ Dir.mkdir(File.join(File.join(name, Bartender::DEFAULTS["output"]), asset_dir)) #this is where compiled assets will go
51
+ end
52
+
53
+ #copy over the default files
54
+ templates = File.join(File.dirname(__FILE__), *%w[.. .. templates])
55
+ FileUtils.cp(File.join(templates, "app.js"), File.join(File.join(name, Bartender::DEFAULTS["assets"]), "js")) #app.js
56
+ FileUtils.cp(File.join(templates, "app.css"), File.join(File.join(name, Bartender::DEFAULTS["assets"]), "css")) #app.css
57
+ FileUtils.cp(File.join(templates, "application.html.erb"), File.join(name, Bartender::DEFAULTS["layouts"])) #application.html.erb
58
+ FileUtils.cp(File.join(templates, "index.html.erb"), File.join(name, Bartender::DEFAULTS["pages"])) #index.html.erb
59
+
60
+ end
61
+
62
+ end #Function create
63
+
64
+ end #Class Site
65
+
66
+ end #Module Bartender
@@ -0,0 +1,3 @@
1
+ module Bartender
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,65 @@
1
+ module Bartender
2
+
3
+ module ViewHelpers
4
+
5
+ #render a simple partial, use Tilt to render it
6
+ #display an error if the partial isn't found
7
+ def partial(filename, variables={})
8
+ search_string = File.join(Bartender::DEFAULTS['pages'], '_' + filename + "*")
9
+ file = Dir.glob(search_string)[0]
10
+ if file && File.exists?(file)
11
+ Tilt.new(file).render(variables, variables)
12
+ else
13
+ $stderr.puts "ERROR: Could not find partial file '#{filename}' in #{Bartender::DEFAULTS['pages']} for page #{self.page}"
14
+ exit 0
15
+ end
16
+ end
17
+
18
+ #link the appropriate stylesheet
19
+ def link_stylesheet(filename, options={})
20
+ opts = {:rel => "stylesheet", :type => "text/css", :media => "all"}.merge(options) #these are the default options for the stylesheet
21
+
22
+ file_path = File.join('css', filename) #this is where the un-compiled asset currently resides
23
+ asset = Bartender::Asset.new(file_path, self.sprockets_env)
24
+
25
+ if asset
26
+ return "<link #{opts.to_a.collect{|opt_a| "#{opt_a[0]}=\"#{opt_a[1]}\""}.join(' ')} src=\"#{asset.site_path}\"/>"
27
+ else
28
+ $stderr.puts "WARNING: Could not find stylesheet '#{filename}' in #{Bartender::DEFAULTS['assets']} for page #{self.page}"
29
+ return "<!-- WARNING: Could not link stylesheet #{filename} -->"
30
+ end
31
+ end #Function link_stylesheet
32
+
33
+ #link the appropriate js
34
+ def link_script(filename, options={})
35
+ opts = {:type => "text/javascript"}.merge(options) #these are the default options for the stylesheet
36
+
37
+ file_path = File.join('js', filename) #this is where the un-compiled asset currently resides
38
+ asset = Bartender::Asset.new(file_path, self.sprockets_env)
39
+
40
+ if asset
41
+ return "<script #{opts.to_a.collect{|opt_a| "#{opt_a[0]}=\"#{opt_a[1]}\""}.join(' ')} src=\"#{asset.site_path}\"> </script>"
42
+ else
43
+ $stderr.puts "WARNING: Could not find javascript '#{filename}' in #{Bartender::DEFAULTS['assets']} for page #{self.page}"
44
+ return "<!-- WARNING: Could not link javascript #{filename} -->"
45
+ end
46
+ end #Function link_script
47
+
48
+ #link to the appropriate image
49
+ def link_image(filename, options={})
50
+ opts = {}.merge(options) #these are the default options for the stylesheet
51
+
52
+ file_path = File.join('images', filename) #this is where the un-compiled asset currently resides
53
+ asset = Bartender::Asset.new(file_path, self.sprockets_env)
54
+
55
+ if asset
56
+ return "<img #{opts.to_a.collect{|opt_a| "#{opt_a[0]}=\"#{opt_a[1]}\""}.join(' ')} src=\"#{asset.site_path}\"/>"
57
+ else
58
+ $stderr.puts "WARNING: Could not find image '#{filename}' in #{Bartender::DEFAULTS['assets']} for page #{self.page}"
59
+ return "<!-- WARNING: Could not link img #{filename} -->"
60
+ end
61
+ end #Function link_image
62
+
63
+ end #Module ViewHelpers
64
+
65
+ end #Module Bartender
data/lib/bartender.rb ADDED
@@ -0,0 +1,49 @@
1
+ require "bartender/version"
2
+
3
+ require 'rubygems'
4
+ require 'yaml'
5
+ require 'fileutils'
6
+
7
+ require 'deep_merge'
8
+
9
+ require 'bartender/view_helpers'
10
+ require 'bartender/asset'
11
+ require 'bartender/site'
12
+ require 'bartender/page'
13
+
14
+ module Bartender
15
+ DEFAULTS = {
16
+ #default options here
17
+
18
+ #path options
19
+ "root" => "./", #root for the source
20
+ "output" => "_site", #where the site content will be saved
21
+ "layouts" => "layouts", #folder where layouts are saved
22
+ "pages" => "pages", #folder where actual pages are saved
23
+ "assets" => "assets", #folder where un-compiled assets should be
24
+ "excluded_files" => [], #files that shouldn't be compiled
25
+
26
+ #site map options
27
+ "site_map_excluded_files" => [] #exclude these file from the site map, excluded_files automatically included
28
+ }
29
+
30
+ def self.configure(cli_options)
31
+ root = Bartender::DEFAULTS["root"]
32
+
33
+ config_file = File.join(root, '_config.yml')
34
+ if File.directory?(config_file)
35
+ begin
36
+ config YAML.load_file(config_file)
37
+ $stdout.puts "Configuration from #{config_file}"
38
+ rescue => err
39
+ $stderr.puts "WARNING: Could not read configuration. " +
40
+ "Using defaults (and options)."
41
+ $stderr.puts "\t" + err.to_s
42
+ config = {}
43
+ end
44
+ else
45
+ config = {}
46
+ end
47
+ Bartender::DEFAULTS.deep_merge(config).deep_merge(cli_options)
48
+ end
49
+ end
data/templates/app.css ADDED
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Add files that you want included below, default is the entire directory
3
+ *= require_self
4
+ *= require_tree .
5
+ */
data/templates/app.js ADDED
@@ -0,0 +1,2 @@
1
+ // Add files that you want included below, default is the entire directory
2
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ <!doctype html public "✰">
2
+ <html lang="en-us">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6
+
7
+ <title dir="ltr"><%= title ||= "My Page" %></title>
8
+ <%= link_stylesheet 'app' %>
9
+ <%= link_script "app" %>
10
+ <meta name="viewport" content="width=device-width">
11
+ </head>
12
+ <body>
13
+ <%= yield %>
14
+ </body>
15
+ </html>
@@ -0,0 +1,5 @@
1
+ ---
2
+ layout: application
3
+ title: My Title
4
+ ---
5
+ <h3><%= title %></h3>
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: static-bartender
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Westendorf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: deep_merge
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: tilt
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: sprockets
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
+ description: Build static websites smartly
63
+ email:
64
+ - daniel@prowestech.com
65
+ executables:
66
+ - bartender
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - bartender.gemspec
76
+ - bin/bartender
77
+ - lib/bartender.rb
78
+ - lib/bartender/asset.rb
79
+ - lib/bartender/page.rb
80
+ - lib/bartender/site.rb
81
+ - lib/bartender/version.rb
82
+ - lib/bartender/view_helpers.rb
83
+ - templates/app.css
84
+ - templates/app.js
85
+ - templates/application.html.erb
86
+ - templates/index.html.erb
87
+ homepage: ''
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.23
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Use layouts, link helpers, and the asset pipeline to create static websites
111
+ smartly.
112
+ test_files: []