benofsky-bolt 0.1.0
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/LICENSE +22 -0
- data/bin/bolt +19 -0
- data/default_files/config.yml +4 -0
- data/lib/bolt.rb +100 -0
- data/lib/bolt/base.rb +68 -0
- data/lib/bolt/build.rb +51 -0
- data/lib/bolt/page.rb +74 -0
- data/lib/bolt/project.rb +40 -0
- data/lib/bolt/view.rb +11 -0
- metadata +73 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2009 Ben McRedmond
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/bolt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# bolt
|
5
|
+
# bolt
|
6
|
+
#
|
7
|
+
# Created by Ben McRedmond on 2010-01-08.
|
8
|
+
# Copyright 2010 Ben McRedmond. All rights reserved.
|
9
|
+
#
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'bolt'
|
13
|
+
rescue LoadError
|
14
|
+
require 'rubygems'
|
15
|
+
require 'bolt'
|
16
|
+
end
|
17
|
+
|
18
|
+
b = Bolt::Bolt.new
|
19
|
+
b.run
|
data/lib/bolt.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
#
|
2
|
+
# bolt.rb
|
3
|
+
# bolt
|
4
|
+
#
|
5
|
+
# Created by Ben McRedmond on 2010-01-08.
|
6
|
+
# Copyright 2010 Ben McRedmond. All rights reserved.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
require 'ostruct'
|
11
|
+
|
12
|
+
module Bolt
|
13
|
+
class Bolt
|
14
|
+
def initialize
|
15
|
+
$config = OpenStruct.new
|
16
|
+
@commands = {"create" => true,
|
17
|
+
"build" => true}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Parses command line options then runs the specified command
|
21
|
+
def run
|
22
|
+
parse_options
|
23
|
+
run_command
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
# Runs a command specified on the command line
|
28
|
+
def run_command
|
29
|
+
self.send($config.command)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Creates a new project object and runs it resulting in creating
|
33
|
+
# all nessecary directories for a new bolt project
|
34
|
+
def create
|
35
|
+
require 'bolt/project'
|
36
|
+
Project.new($config).run
|
37
|
+
end
|
38
|
+
|
39
|
+
# Creates a new build object and runs it resulting in building
|
40
|
+
# a bolt project and saving all files into the "out" directory.
|
41
|
+
def build
|
42
|
+
require 'bolt/build'
|
43
|
+
Build.new($config).run
|
44
|
+
end
|
45
|
+
|
46
|
+
# Parses command line options
|
47
|
+
def parse_options
|
48
|
+
$config.resources = "resources"
|
49
|
+
$config.lib = "lib"
|
50
|
+
$config.views = "views"
|
51
|
+
$config.pages = "pages"
|
52
|
+
$config.out = "out"
|
53
|
+
$config.config = "config.yml"
|
54
|
+
|
55
|
+
opts = OptionParser.new do |opts|
|
56
|
+
opts.banner = "Usage: bolt {create/build} [options] [file]"
|
57
|
+
|
58
|
+
opts.on("-r", "--resources [resource-dir]", "Resources directory") do |opts|
|
59
|
+
$config.resources = opts
|
60
|
+
end
|
61
|
+
|
62
|
+
opts.on("-v", "--views [views-dir]", "Views directory") do |opts|
|
63
|
+
$config.views = opts
|
64
|
+
end
|
65
|
+
|
66
|
+
opts.on("-l", "--lib [lib-dir]", "Library directory") do |opts|
|
67
|
+
$config.lib = opts
|
68
|
+
end
|
69
|
+
|
70
|
+
opts.on("-p", "--pages [pages-dir]", "Pages directory") do |opts|
|
71
|
+
$config.pages = opts
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.on("-o", "--out [out-directory]", "Where to save HTML") do |opts|
|
75
|
+
$config.out = opts
|
76
|
+
end
|
77
|
+
|
78
|
+
opts.on("-c", "--config [config-file.yml]", "Config file") do |opts|
|
79
|
+
$config.config = opts
|
80
|
+
end
|
81
|
+
|
82
|
+
opts.on_tail("-h", "--help", "Show this help message") do
|
83
|
+
puts opts
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
|
87
|
+
opts.parse!(ARGV)
|
88
|
+
end
|
89
|
+
|
90
|
+
if ARGV.empty? || ARGV.count > 2 || @commands[ARGV[0]].nil?
|
91
|
+
puts opts.help
|
92
|
+
exit
|
93
|
+
else
|
94
|
+
$config.command = ARGV[0]
|
95
|
+
$config.base_dir = (ARGV.count == 2) ? ARGV[1] : "."
|
96
|
+
$config.base_dir += '/' if $config.base_dir[-1..$config.base_dir.length] != '/'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/bolt/base.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#
|
2
|
+
# base.rb
|
3
|
+
# bolt
|
4
|
+
#
|
5
|
+
# Created by Ben McRedmond on 2010-01-08.
|
6
|
+
# Copyright 2010 Ben McRedmond. All rights reserved.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'fileutils'
|
10
|
+
require 'ftools'
|
11
|
+
|
12
|
+
$BOLT_BASE = File.dirname(__FILE__) + "/../../"
|
13
|
+
|
14
|
+
module Bolt
|
15
|
+
class Base
|
16
|
+
# Takes an ostruct options object created by parsing ARGV
|
17
|
+
def initialize(options)
|
18
|
+
$config = options
|
19
|
+
STDOUT.sync = true
|
20
|
+
end
|
21
|
+
|
22
|
+
# Creates a directory, prefixes $config.base_dir if required
|
23
|
+
def create_directory(directory, options = {})
|
24
|
+
options[:error_if_exists] = (options[:error_if_exists].nil?) ? true : options[:error_if_exists]
|
25
|
+
directory = d(directory) if options[:base_dir].nil?
|
26
|
+
|
27
|
+
if File.directory?(directory)
|
28
|
+
raise ArgumentError, "#{directory} exists already." if options[:error_if_exists]
|
29
|
+
else
|
30
|
+
Dir.mkdir(directory)
|
31
|
+
puts "Created #{directory}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Forces removal of directory, <tt>directory</tt>
|
36
|
+
def remove_directory(directory)
|
37
|
+
directory = d(directory)
|
38
|
+
FileUtils.rm_rf(directory)
|
39
|
+
puts "Removed #{directory}"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Creates a file, <tt>file</tt>, with the contents of <tt>:copy_from</tt>, prefixes $config.base_dir
|
43
|
+
def create_file(file, options = {})
|
44
|
+
file = d(file)
|
45
|
+
|
46
|
+
options[:mode] ||= "r"
|
47
|
+
options[:copy_from] ||= false
|
48
|
+
|
49
|
+
if options[:copy_from]
|
50
|
+
f = File.copy(options[:copy_from], file)
|
51
|
+
else
|
52
|
+
f = File.new(file, options[:mode])
|
53
|
+
end
|
54
|
+
|
55
|
+
puts "Created #{file}"
|
56
|
+
end
|
57
|
+
|
58
|
+
# Opens file, <tt>file</tt> with mode, <tt>mode</tt> prefixes $config.base_dir
|
59
|
+
def open_file(file, mode = "r")
|
60
|
+
File.open(d(file), mode)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns <tt>file_or_directory</tt> with $config.base_dir prefixed
|
64
|
+
def d(file_or_directory)
|
65
|
+
$config.base_dir + file_or_directory
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/bolt/build.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# build.rb
|
3
|
+
# bolt
|
4
|
+
#
|
5
|
+
# Created by Ben McRedmond on 2010-01-08.
|
6
|
+
# Copyright 2010 Ben McRedmond. All rights reserved.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'yaml'
|
10
|
+
require 'fileutils'
|
11
|
+
|
12
|
+
require 'bolt/base'
|
13
|
+
require 'bolt/page'
|
14
|
+
require 'bolt/view'
|
15
|
+
|
16
|
+
module Bolt
|
17
|
+
class Build < Base
|
18
|
+
# Performs all the nessecary steps to build a Bolt project
|
19
|
+
def run
|
20
|
+
remove_directory("out")
|
21
|
+
create_directory("out", :error_if_exists => false)
|
22
|
+
copy_resources
|
23
|
+
parse_config
|
24
|
+
load_pages
|
25
|
+
end
|
26
|
+
|
27
|
+
# Copies the contents of $config.resources to the out directory
|
28
|
+
def copy_resources
|
29
|
+
FileUtils.cp_r(Dir.glob("#{d($config.resources)}/*"), d($config.out))
|
30
|
+
puts "Copied #{d($config.resources)} to #{d($config.out)}"
|
31
|
+
end
|
32
|
+
|
33
|
+
# Parses $config.config and loads all contents into instance variables
|
34
|
+
def parse_config
|
35
|
+
$config_file = YAML::load(open_file(d($config.config)))
|
36
|
+
puts "Parsed config #{d($config.config)}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_pages
|
40
|
+
pages = Dir.glob("#{d($config.pages)}/*.rb")
|
41
|
+
pages.each do |page|
|
42
|
+
parse_page page
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_page(page)
|
47
|
+
puts "Parsing page #{page}"
|
48
|
+
load page
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/bolt/page.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#
|
2
|
+
# page.rb
|
3
|
+
# bolt
|
4
|
+
#
|
5
|
+
# Created by Ben McRedmond on 2010-01-09.
|
6
|
+
# Copyright 2010 Ben McRedmond. All rights reserved.
|
7
|
+
#
|
8
|
+
|
9
|
+
# Loads the specified view into instance variable @content
|
10
|
+
# which is then inserted into a template
|
11
|
+
def render(view, options = {})
|
12
|
+
raise ArgumentError, "Please specify a view to render" if view.empty?
|
13
|
+
|
14
|
+
options[:template] ||= $config_file['primary_template']
|
15
|
+
options[:engine] ||= "haml"
|
16
|
+
|
17
|
+
raise ArgumentError, ":engine cannot be view" if options[:engine] == "view"
|
18
|
+
require options[:engine_require] || options[:engine]
|
19
|
+
|
20
|
+
@content = render_view(view_as_string(view, options[:engine]), options[:engine])
|
21
|
+
render_view(view_as_string(options[:template]), options[:engine]) unless options[:template].empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
# Writes a file containing whatever is returned from a supplied block
|
25
|
+
# Will create directories as required by <tt>path</tt>
|
26
|
+
def page(path)
|
27
|
+
create_path(path)
|
28
|
+
|
29
|
+
path = "#{$config.base_dir}#{$config.out}/#{path}.html"
|
30
|
+
File.open(path, 'w') {|f| f.write yield}
|
31
|
+
puts "Created #{path}"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def create_path(path)
|
36
|
+
path = path.split('/')
|
37
|
+
path = "#{$config.base_dir}#{$config.out}/#{path[0..path.length-2].join('/')}"
|
38
|
+
if !File.directory?(path)
|
39
|
+
FileUtils.mkdir_p(path)
|
40
|
+
puts "Created #{path}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Opens a view file and attempts to read it into a string
|
45
|
+
def view_as_string(view, engine = "haml")
|
46
|
+
v = ""
|
47
|
+
path = "#{$config.base_dir}/#{$config.views}/#{view}"
|
48
|
+
|
49
|
+
begin
|
50
|
+
File.open(path) {|f| v = f.read}
|
51
|
+
rescue Errno::ENOENT
|
52
|
+
File.open("#{path}.#{engine}") {|f| v = f.read}
|
53
|
+
end
|
54
|
+
|
55
|
+
v
|
56
|
+
end
|
57
|
+
|
58
|
+
# Renders <tt>view</tt> with <tt>engine</tt>
|
59
|
+
def render_view(view, engine)
|
60
|
+
self.send("render_#{engine}", view)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Renders haml string, <tt>haml</tt>
|
64
|
+
def render_haml(haml, locals = {})
|
65
|
+
if locals != false && locals.empty?
|
66
|
+
self.instance_variables.each do |var|
|
67
|
+
locals[var.split("@")[1]] = self.instance_variable_get(var)
|
68
|
+
end
|
69
|
+
|
70
|
+
locals.merge!($config_file)
|
71
|
+
end
|
72
|
+
|
73
|
+
Haml::Engine.new(haml).render(Object.new, locals)
|
74
|
+
end
|
data/lib/bolt/project.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# project.rb
|
3
|
+
# bolt
|
4
|
+
#
|
5
|
+
# Created by Ben McRedmond on 2010-01-08.
|
6
|
+
# Copyright 2010 Ben McRedmond. All rights reserved.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'bolt/base'
|
10
|
+
|
11
|
+
module Bolt
|
12
|
+
class Project < Base
|
13
|
+
# Takes an ostruct options object created by parsing ARGV
|
14
|
+
def initialize(options)
|
15
|
+
super(options)
|
16
|
+
@default_directories = [$config.pages, $config.views, $config.lib, $config.resources]
|
17
|
+
@default_files = {$config.config => "default_files/config.yml"}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Creates all nessecary directories and files for a new Bolt Project
|
21
|
+
def run
|
22
|
+
create_directory_structure
|
23
|
+
create_files
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
# Creates all the default directories using either defaults
|
28
|
+
# specified in lib/bolt.rb or by options on the command line
|
29
|
+
def create_directory_structure
|
30
|
+
create_directory($config.base_dir, :base_dir => true) unless File.directory?($config.base_dir)
|
31
|
+
@default_directories.each {|directory| create_directory(directory)}
|
32
|
+
end
|
33
|
+
|
34
|
+
# Creates all the default files using either defaults specified
|
35
|
+
# in lib/bolt.rb or by options on the command line
|
36
|
+
def create_files
|
37
|
+
@default_files.each {|file, template| create_file(file, :copy_from => $BOLT_BASE + template)}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/bolt/view.rb
ADDED
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: benofsky-bolt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben McRedmond
|
8
|
+
autorequire:
|
9
|
+
bindir:
|
10
|
+
- bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2010-01-08 00:00:00 +00:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: haml
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "2.2"
|
25
|
+
version:
|
26
|
+
description: WeBolt was built to fill a gap in static website generators, making it super easy to generate a static website with dynamic content inserted at compile time.
|
27
|
+
email: ben+bolt@benmcredmond.com
|
28
|
+
executables:
|
29
|
+
- bolt
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
34
|
+
files:
|
35
|
+
- lib/bolt/base.rb
|
36
|
+
- lib/bolt/build.rb
|
37
|
+
- lib/bolt/page.rb
|
38
|
+
- lib/bolt/project.rb
|
39
|
+
- lib/bolt/view.rb
|
40
|
+
- lib/bolt.rb
|
41
|
+
- bin/bolt
|
42
|
+
- LICENSE
|
43
|
+
- default_files/config.yml
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/benofsky/bolt/
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: WeBolt is a simple static website generator with support for dynamic content.
|
72
|
+
test_files: []
|
73
|
+
|