templette 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/templette +26 -25
- data/files/config.rb +2 -0
- data/lib/file_generator.rb +11 -1
- data/lib/tasks/templette_tasks.rb +12 -2
- data/lib/templette.rb +16 -1
- data/lib/templette/data_accessors.rb +2 -38
- data/lib/templette/generator.rb +9 -5
- data/lib/templette/helpers.rb +61 -0
- metadata +4 -2
data/bin/templette
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
|
4
|
-
usage = <<USAGE
|
5
|
-
Generate the templette framework.
|
6
|
-
Usage: templette <directory>
|
7
|
-
--help gets you this help message... Helpful!
|
8
|
-
USAGE
|
9
|
-
|
10
|
-
require 'fileutils'
|
11
|
-
|
12
|
-
new_dir = ARGV.first
|
13
|
-
|
14
|
-
if new_dir.nil? || new_dir.empty?
|
15
|
-
puts usage
|
16
|
-
exit(0)
|
17
|
-
end
|
18
|
-
|
19
|
-
FileUtils.mkdir(new_dir) unless File.exists?(new_dir)
|
20
|
-
%w{/pages /templates /helpers /resources}.each do |dir|
|
21
|
-
FileUtils.mkdir(new_dir + dir) unless File.exists?(new_dir + dir)
|
22
|
-
end
|
23
|
-
|
24
|
-
FileUtils.cp(File.dirname(__FILE__) + '/../files/Rakefile', new_dir + '/Rakefile')
|
25
|
-
FileUtils.cp(File.dirname(__FILE__) + '/../files/default_helper.rb', new_dir + '/helpers/default_helper.rb')
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
|
4
|
+
usage = <<USAGE
|
5
|
+
Generate the templette framework.
|
6
|
+
Usage: templette <directory>
|
7
|
+
--help gets you this help message... Helpful!
|
8
|
+
USAGE
|
9
|
+
|
10
|
+
require 'fileutils'
|
11
|
+
|
12
|
+
new_dir = ARGV.first
|
13
|
+
|
14
|
+
if new_dir.nil? || new_dir.empty?
|
15
|
+
puts usage
|
16
|
+
exit(0)
|
17
|
+
end
|
18
|
+
|
19
|
+
FileUtils.mkdir(new_dir) unless File.exists?(new_dir)
|
20
|
+
%w{/pages /templates /helpers /resources}.each do |dir|
|
21
|
+
FileUtils.mkdir(new_dir + dir) unless File.exists?(new_dir + dir)
|
22
|
+
end
|
23
|
+
|
24
|
+
FileUtils.cp(File.dirname(__FILE__) + '/../files/Rakefile', new_dir + '/Rakefile')
|
25
|
+
FileUtils.cp(File.dirname(__FILE__) + '/../files/default_helper.rb', new_dir + '/helpers/default_helper.rb')
|
26
|
+
FileUtils.cp(File.dirname(__FILE__) + '/../files/config.rb', new_dir + '/config.rb')
|
data/files/config.rb
ADDED
data/lib/file_generator.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/templette'
|
2
1
|
module FileGenerator
|
3
2
|
|
4
3
|
class << self
|
@@ -30,6 +29,17 @@ module FileGenerator
|
|
30
29
|
end"
|
31
30
|
end
|
32
31
|
end
|
32
|
+
|
33
|
+
# Called by rake generate:config
|
34
|
+
#
|
35
|
+
# Generates a default config.rb file, with usage examples present and commented out.
|
36
|
+
def config
|
37
|
+
if File.exists?("config.rb")
|
38
|
+
puts 'Config file already exists!'
|
39
|
+
else
|
40
|
+
FileUtils.cp(File.dirname(__FILE__) + '/../files/config.rb', 'config.rb')
|
41
|
+
end
|
42
|
+
end
|
33
43
|
end
|
34
44
|
|
35
45
|
end
|
@@ -1,5 +1,9 @@
|
|
1
|
+
task :load_config do
|
2
|
+
Templette::load_config_from_file
|
3
|
+
end
|
4
|
+
|
1
5
|
desc "Build an HTML project from template files"
|
2
|
-
task(:build) do
|
6
|
+
task(:build => :load_config) do
|
3
7
|
if ENV['destination']
|
4
8
|
Templette::Generator.new(ENV['destination']).run
|
5
9
|
else
|
@@ -8,7 +12,7 @@ task(:build) do
|
|
8
12
|
end
|
9
13
|
|
10
14
|
desc "Build and view the site locally using WEBrick"
|
11
|
-
task(:preview) do
|
15
|
+
task(:preview => :load_config) do
|
12
16
|
gen = Templette::Generator.new('preview')
|
13
17
|
gen.run
|
14
18
|
|
@@ -68,6 +72,12 @@ namespace :generate do
|
|
68
72
|
require 'file_generator'
|
69
73
|
FileGenerator.helper(ENV['name'])
|
70
74
|
end
|
75
|
+
|
76
|
+
desc "Generate a config file"
|
77
|
+
task :config do
|
78
|
+
require 'file_generator'
|
79
|
+
FileGenerator.config
|
80
|
+
end
|
71
81
|
|
72
82
|
end
|
73
83
|
|
data/lib/templette.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
%w{erb yaml fileutils}.each {|lib| require lib}
|
2
2
|
|
3
|
-
%w{data_accessors errors generator method_collector page template engineer}.each do |file|
|
3
|
+
%w{helpers data_accessors errors generator method_collector page template engineer}.each do |file|
|
4
4
|
require File.dirname(__FILE__) + "/templette/#{file}"
|
5
|
+
end
|
6
|
+
|
7
|
+
module Templette
|
8
|
+
CONFIG_FILE_PATH = 'config.rb'
|
9
|
+
|
10
|
+
@@config = {:site_root => '/' }
|
11
|
+
|
12
|
+
def self.config
|
13
|
+
@@config
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.load_config_from_file
|
17
|
+
eval File.read(CONFIG_FILE_PATH) if File.exists?(CONFIG_FILE_PATH)
|
18
|
+
end
|
19
|
+
|
5
20
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Templette
|
2
2
|
module DataAccessors
|
3
|
+
include Templette::Helpers
|
4
|
+
|
3
5
|
def attributes # :nodoc:
|
4
6
|
@attributes ||= {}
|
5
7
|
end
|
@@ -22,47 +24,9 @@ module Templette
|
|
22
24
|
rescue RenderError => e
|
23
25
|
raise PageError.new(page, e.message)
|
24
26
|
end
|
25
|
-
|
26
|
-
# Generates an image tag. Default options {:alt => filename }
|
27
|
-
#
|
28
|
-
# Ex.
|
29
|
-
# image_tag('ball.png', :alt => 'a red ball')
|
30
|
-
# => "<img src='/images/ball.png' alt='a red ball' />"
|
31
|
-
|
32
|
-
def image_tag(path, options = {})
|
33
|
-
options = {:alt => path}.merge(options)
|
34
|
-
"<img src='/images/#{path}' #{params_to_attributes(options)}/>"
|
35
|
-
end
|
36
|
-
|
37
|
-
# Generates a link to a stylesheet. Default options {:type => 'text/css'}
|
38
|
-
#
|
39
|
-
# Ex.
|
40
|
-
# stylesheet_tag('print', :media => 'print')
|
41
|
-
# => "<link href='/stylesheets/print.css' media='print' type='text/css' />"
|
42
|
-
|
43
|
-
def stylesheet_tag(path, options = {})
|
44
|
-
options = {:type => 'text/css'}.merge(options)
|
45
|
-
"<link href='/stylesheets/#{path}.css' #{params_to_attributes(options)}/>"
|
46
|
-
end
|
47
|
-
|
48
|
-
# Genrates a javascript scrip tag.
|
49
|
-
#
|
50
|
-
# Ex.
|
51
|
-
# script_tag('slider')
|
52
|
-
# => <script src='/javascripts/slider.js' type='text/javascript'></script>
|
53
|
-
|
54
|
-
def script_tag(path)
|
55
|
-
"<script src='/javascripts/#{path}.js' type='text/javascript'></script>"
|
56
|
-
end
|
57
27
|
|
58
28
|
private
|
59
29
|
|
60
|
-
def params_to_attributes(options)
|
61
|
-
options.inject('') do |str, h|
|
62
|
-
str << "#{h[0]}='#{h[1]}' "
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
30
|
def generate_accessor(k, v)
|
67
31
|
raise TempletteError.new(page, "Method already defined: #{k}. Change your config file and stop using it!") if self.methods.include?(k.to_s)
|
68
32
|
if v.kind_of?(Hash)
|
data/lib/templette/generator.rb
CHANGED
@@ -7,21 +7,21 @@ module Templette
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def run
|
10
|
-
FileUtils.
|
10
|
+
FileUtils.mkdir_p(output_location) unless File.exists?(output_location)
|
11
11
|
pages = Page.find_all
|
12
|
-
puts "Generating site in: #{
|
12
|
+
puts "Generating site in: #{output_location}; contains #{pages.size} pages"
|
13
13
|
pages.each do |page|
|
14
14
|
puts "Generating page #{page.name} using template #{page.template.name}"
|
15
15
|
begin
|
16
|
-
page.generate(
|
16
|
+
page.generate(output_location)
|
17
17
|
rescue Templette::TempletteError => e
|
18
18
|
@errors.push(e)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
if File.exists?(@resources_dir)
|
23
|
-
puts "Copying resources from #{@resources_dir} to #{
|
24
|
-
FileUtils.cp_r("#{@resources_dir}/.",
|
23
|
+
puts "Copying resources from #{@resources_dir} to #{output_location}"
|
24
|
+
FileUtils.cp_r("#{@resources_dir}/.", output_location)
|
25
25
|
end
|
26
26
|
|
27
27
|
if @errors.empty?
|
@@ -32,6 +32,10 @@ module Templette
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def output_location
|
36
|
+
@out_dir + Templette::config[:site_root]
|
37
|
+
end
|
38
|
+
|
35
39
|
def clean
|
36
40
|
FileUtils.rm_rf(@out_dir) if File.exists?(@out_dir)
|
37
41
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Templette
|
2
|
+
|
3
|
+
# Standard tag helpers to attempt to make life a little easier.
|
4
|
+
# Tag methods will not modify full paths (with an http protocol).
|
5
|
+
# If a tag is just a local path, it will heed the configurable site_root,
|
6
|
+
# and prepend the necessary directories to build the anticipated path.
|
7
|
+
|
8
|
+
module Helpers
|
9
|
+
|
10
|
+
# Generates an image tag. Default options {:alt => filename }
|
11
|
+
#
|
12
|
+
# Ex.
|
13
|
+
# image_tag('ball.png', :alt => 'a red ball')
|
14
|
+
# => "<img src='/images/ball.png' alt='a red ball' />"
|
15
|
+
|
16
|
+
# image_tag('http://flickr.com/hilarious-picture.jpg', :alt => 'lol!')
|
17
|
+
# => "<img src='http://flickr.com/hilarious-picture.jpg' alt='lol!' />"
|
18
|
+
|
19
|
+
def image_tag(path, options = {})
|
20
|
+
options = {:alt => path}.merge(options)
|
21
|
+
"<img src='#{tag_path(path, 'images')}' #{params_to_attributes(options)}/>"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Generates a link to a stylesheet. Default options {:type => 'text/css'}
|
25
|
+
#
|
26
|
+
# Ex.
|
27
|
+
# stylesheet_tag('print', :media => 'print')
|
28
|
+
# => "<link href='/stylesheets/print.css' media='print' type='text/css' />"
|
29
|
+
|
30
|
+
def stylesheet_tag(path, options = {})
|
31
|
+
options = {:type => 'text/css'}.merge(options)
|
32
|
+
"<link href='#{tag_path(path, 'stylesheets', 'css')}' #{params_to_attributes(options)}/>"
|
33
|
+
end
|
34
|
+
|
35
|
+
# Genrates a javascript scrip tag.
|
36
|
+
#
|
37
|
+
# Ex.
|
38
|
+
# script_tag('slider')
|
39
|
+
# => <script src='/javascripts/slider.js' type='text/javascript'></script>
|
40
|
+
|
41
|
+
def script_tag(path)
|
42
|
+
"<script src='#{tag_path(path, 'javascripts', 'js')}' type='text/javascript'></script>"
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def tag_path(path, asset_subdir, file_ext = nil)
|
48
|
+
if path =~ /http:\/\//
|
49
|
+
path
|
50
|
+
else
|
51
|
+
"#{Templette.config[:site_root]}#{asset_subdir}/#{path}#{ "."+file_ext if file_ext }"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def params_to_attributes(options)
|
56
|
+
options.inject('') do |str, h|
|
57
|
+
str << "#{h[0]}='#{h[1]}' "
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: templette
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Dunphy and Steve Holder
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-23 00:00:00 -08:00
|
13
13
|
default_executable: templette
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/templette/engines/haml.rb
|
31
31
|
- lib/templette/errors.rb
|
32
32
|
- lib/templette/generator.rb
|
33
|
+
- lib/templette/helpers.rb
|
33
34
|
- lib/templette/method_collector.rb
|
34
35
|
- lib/templette/page.rb
|
35
36
|
- lib/templette/template.rb
|
@@ -37,6 +38,7 @@ files:
|
|
37
38
|
- bin/templette
|
38
39
|
- bin/templette.cmd
|
39
40
|
- files/Capfile
|
41
|
+
- files/config.rb
|
40
42
|
- files/default_helper.rb
|
41
43
|
- files/deploy.rb
|
42
44
|
- files/Rakefile
|