frank 0.2.4 → 0.2.5

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/README.md CHANGED
@@ -30,9 +30,11 @@ and static files are served from the `static` folder.
30
30
 
31
31
  When you are finished:
32
32
 
33
- $ frankout <dump_dir>
34
-
35
- This will compile and copy everything to the folder given.
33
+ $ frankout <dump_dir> # compile templates
34
+
35
+ or
36
+
37
+ $ frankout --production <dump_dir> # compile and create folder structure suitable for serving from a production website
36
38
 
37
39
  Views & Layouts
38
40
  -------------------------
@@ -1,16 +1,37 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'optparse'
2
3
  require 'frank'
3
4
 
5
+ options = { :production => false }
6
+
7
+ opts = OptionParser.new do |opts|
8
+ opts.banner = "Usage: frankout [OPTIONS] directory\n",
9
+ "Compiles and dumps a project and it\'s static files to given directory\n",
10
+ "Example: frankout --production html_dump\n\n"
11
+
12
+ opts.separator 'Options:'
13
+
14
+ opts.on('--production', 'Production ready dump i.e. ([FOLDER]/index.html)') do |handler|
15
+ options[:production] = true
16
+ end
17
+
18
+ opts.on( '-h', '--help', 'Display this help' ) do
19
+ puts opts
20
+ exit
21
+ end
22
+ end
23
+
24
+ opts.parse!
25
+
4
26
  if ARGV.empty?
5
- puts "Usage: frankout [DUMP_DIR]"
6
- puts "Compiles and dumps a project and it\'s static files to given folder"
27
+ puts opts
7
28
  exit
8
29
  end
9
30
 
10
31
  output_folder = ARGV.first
11
32
 
12
33
  if File.exists? output_folder
13
- print "Folder: #{output_folder} already exists... do you want to overwrite it? (y|n) "
34
+ print "'#{output_folder}' \033[31malready exists...\033[0m do you want to overwrite it? (y|n) "
14
35
  resp = STDIN.gets.chomp.strip
15
36
  exit if resp.downcase.strip != 'y'
16
37
  FileUtils.rm_rf(output_folder)
@@ -26,7 +47,7 @@ begin
26
47
  end
27
48
  set :output_folder, output_folder
28
49
  set :proj_dir, proj_dir
29
- end.dump
50
+ end.dump(options)
30
51
 
31
52
  rescue Errno::ENOENT
32
53
  puts "Frank could not find settings.yml."
@@ -4,7 +4,12 @@ require 'frank'
4
4
 
5
5
  options = {:server => {}}
6
6
 
7
- opts = OptionParser.new do |opts|
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: frankup [OPTIONS]\n",
9
+ "Starts the frank development server using settings.yml\n",
10
+ "If settings.yml isn\'t found, a webserver will be started and serve up files from the current directory\n\n"
11
+
12
+ opts.separator 'Options:'
8
13
 
9
14
  opts.on('--server [HANDLER]', 'Set the server handler') do |handler|
10
15
  options[:server]['handler'] = handler unless handler.nil?
@@ -26,6 +31,10 @@ opts = OptionParser.new do |opts|
26
31
  options[:static_folder] = folder unless folder.nil?
27
32
  end
28
33
 
34
+ opts.on( '-h', '--help', 'Display this help' ) do
35
+ puts opts
36
+ exit
37
+ end
29
38
  end.parse!
30
39
 
31
40
  if File.exist? 'settings.yml'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{frank}
8
- s.version = "0.2.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["blahed", "nwah"]
12
- s.date = %q{2010-03-29}
12
+ s.date = %q{2010-04-02}
13
13
  s.description = %q{Create/Dump static builds using whatever templating/helper languages you wish}
14
14
  s.email = %q{travis.dunn@thisismedium.com}
15
15
  s.executables = ["frank", "frankout", "frankup"]
@@ -5,7 +5,7 @@ require 'frank/statik'
5
5
  require 'frank/imager'
6
6
 
7
7
  module Frank
8
- VERSION = '0.2.4'
8
+ VERSION = '0.2.5'
9
9
 
10
10
  module Render; end
11
11
 
@@ -201,13 +201,14 @@ module Frank
201
201
 
202
202
  # copies over the generic project template
203
203
  def self.stub(project)
204
- puts "\n-----------------------\n Frank:\n - Creating '#{project}'"
204
+ puts "\nFrank is..."
205
+ puts " - \033[32mCreating\033[0m your project '#{project}'"
205
206
  Dir.mkdir project
206
- puts " - Copying Frank template"
207
+ puts " - \033[32mCopying\033[0m Frank template"
207
208
  FileUtils.cp_r( Dir.glob(File.join(LIBDIR, 'template/*')), project )
208
- puts "\n Congratulations, '#{project}' is ready to go.\n\n"
209
+ puts "\n \033[32mCongratulations, '#{project}' is ready to go!\033[0m"
209
210
  rescue Errno::EEXIST
210
- puts " uh oh, #{project} already exists..."
211
+ puts "\n \033[31muh oh, directory '#{project}' already exists...\033[0m"
211
212
  exit
212
213
  end
213
214
 
@@ -12,36 +12,64 @@ module Frank
12
12
  end
13
13
 
14
14
  # get all of the templates and compile them
15
- def compile_templates
15
+ def compile_templates(options)
16
16
  dir = File.join(@proj_dir, @dynamic_folder)
17
+ layouts = templates['layouts'].map { |l| l['name'] }
17
18
 
18
19
  Find.find(dir) do |path|
19
- if FileTest.file?(path) and !File.basename(path).match(/^(\.|_)/)
20
+ if FileTest.file?(path) && !File.basename(path).match(/^(\.|_)/)
21
+ # get the path name
20
22
  path = path[ dir.size + 1 ..-1 ]
23
+ # get name and ext
21
24
  name, ext = name_ext(path)
25
+ # get output extension
22
26
  new_ext = reverse_ext_lookup(ext)
23
- new_file = File.join(@proj_dir, @output_folder, "#{name}.#{new_ext}")
24
- FileUtils.makedirs(new_file.split('/').reverse[1..-1].reverse.join('/'))
25
- File.open(new_file, 'w') {|f| f.write render_path(path) }
26
- puts "Create #{name}.#{new_ext}" unless @environment == :test
27
+
28
+ # if production is true and this template isn't a layout
29
+ if options[:production] == true && !layouts.include?(name)
30
+ # if template isn't index or template doesn't compile to html
31
+ # then compile it as is, otherwise name a folder based on the template
32
+ # and compile to index.html
33
+ if "#{name}.#{new_ext}" == 'index.html' || new_ext != 'html'
34
+ new_file = File.join(@proj_dir, @output_folder, "#{name}.#{new_ext}")
35
+ else
36
+ new_file = File.join(@proj_dir, @output_folder, name, "index.#{new_ext}")
37
+ name = "#{name}/index"
38
+ end
39
+ create_dir(new_file)
40
+ File.open(new_file, 'w') {|f| f.write render_path(path) }
41
+ elsif options[:production] == false
42
+ new_file = File.join(@proj_dir, @output_folder, "#{name}.#{new_ext}")
43
+ create_dir(new_file)
44
+ File.open(new_file, 'w') {|f| f.write render_path(path) }
45
+ end
46
+ puts " - \033[32mCreating\033[0m '#{@output_folder}/#{name}.#{new_ext}'"
27
47
  end
28
48
  end
29
49
  end
30
50
 
51
+ # use path to determine folder name and
52
+ # create the required folder if it doesn't exist
53
+ def create_dir(path)
54
+ FileUtils.makedirs path.split('/').reverse[1..-1].reverse.join('/')
55
+ end
56
+
31
57
  # copies over static content
32
58
  def copy_static
33
- puts "Copying over your static content" unless @environment == :test
59
+ puts " - \033[32mCopying\033[0m static content"
34
60
  static_folder = File.join(@proj_dir, @static_folder)
35
61
  FileUtils.cp_r(File.join(static_folder, '/.'), @output_path)
36
62
  end
37
63
 
38
64
  # create the dump dir, compile templates, copy over static assets
39
- def dump
65
+ def dump(options={:production => false})
40
66
  FileUtils.mkdir(@output_path)
41
- puts "Create #{@output_folder}" unless @environment == :test
67
+ puts "\nFrank is..."
68
+ puts " - \033[32mCreating\033[0m '#{@output_folder}'"
42
69
 
43
- compile_templates
70
+ compile_templates(options)
44
71
  copy_static
72
+ puts "\n \033[32mCongratulations, project dumped to '#{@output_folder}' successfully!\033[0m"
45
73
  end
46
74
  end
47
75
 
@@ -68,7 +68,7 @@ class TestBase < Test::Unit::TestCase
68
68
  should 'stub out a project' do
69
69
  out = capture_stdout { Frank.stub('stubbed') }
70
70
  assert_equal Dir.entries('stubbed'), Dir.entries(File.join(LIBDIR, 'template'))
71
- putss = "\n-----------------------\n Frank:\n - Creating 'stubbed'\n - Copying Frank template\n\n Congratulations, 'stubbed' is ready to go.\n\n"
71
+ putss = "\nFrank is...\n - \e[32mCreating\e[0m your project 'stubbed'\n - \e[32mCopying\e[0m Frank template\n\n \e[32mCongratulations, 'stubbed' is ready to go!\e[0m\n"
72
72
  assert_equal putss, out.string
73
73
  end
74
74
 
@@ -8,14 +8,16 @@ class TestBase < Test::Unit::TestCase
8
8
  proj_dir = File.join(File.dirname(__FILE__), 'template')
9
9
  settings = YAML.load_file(File.join(proj_dir, 'settings.yml'))
10
10
  require File.join(proj_dir, 'helpers')
11
- @frank = Frank::Output.new do
12
- settings.each do |name, value|
13
- set name.to_s, value
14
- end
15
- set :environment, :test
16
- set :proj_dir, proj_dir
17
- set :output_folder, 'output'
18
- end.dump
11
+ capture_stdout do
12
+ @frank = Frank::Output.new do
13
+ settings.each do |name, value|
14
+ set name.to_s, value
15
+ end
16
+ set :environment, :test
17
+ set :proj_dir, proj_dir
18
+ set :output_folder, 'output'
19
+ end.dump
20
+ end
19
21
  end
20
22
 
21
23
  should 'create the output folder' do
@@ -74,7 +76,84 @@ class TestBase < Test::Unit::TestCase
74
76
  teardown do
75
77
  FileUtils.rm_r File.join(File.dirname(__FILE__), 'template/output')
76
78
  end
77
-
79
+ end
80
+
81
+ context 'Frank::Output Production' do
82
+
83
+ setup do
84
+ proj_dir = File.join(File.dirname(__FILE__), 'template')
85
+ settings = YAML.load_file(File.join(proj_dir, 'settings.yml'))
86
+ require File.join(proj_dir, 'helpers')
87
+
88
+ capture_stdout do
89
+ @frank = Frank::Output.new do
90
+ settings.each do |name, value|
91
+ set name.to_s, value
92
+ end
93
+ set :environment, :test
94
+ set :proj_dir, proj_dir
95
+ set :output_folder, 'output'
96
+ end.dump({:production => true})
97
+ end
98
+ end
99
+
100
+ should 'create the output folder' do
101
+ assert File.exist? File.join(File.dirname(__FILE__), 'template/output')
102
+ end
103
+
104
+ should 'create index.html' do
105
+ output = File.join(File.dirname(__FILE__), 'template/output/index.html')
106
+ assert_equal "<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n", IO.read(output)
107
+ end
108
+
109
+ should 'create partial_test.html' do
110
+ output = File.join(File.dirname(__FILE__), 'template/output/partial_test/index.html')
111
+ assert_equal "<div id='layout'>\n <h1>hello worlds</h1>\n <p>hello from partial</p>\n</div>\n", IO.read(output)
112
+ end
113
+
114
+ should 'create erb.html' do
115
+ output = File.join(File.dirname(__FILE__), 'template/output/erb/index.html')
116
+ assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
117
+ end
118
+
119
+ should 'create redcloth.html' do
120
+ output = File.join(File.dirname(__FILE__), 'template/output/redcloth/index.html')
121
+ assert_equal "<h1>hello worlds</h1>", IO.read(output)
122
+ end
123
+
124
+ should 'create markdown.html' do
125
+ output = File.join(File.dirname(__FILE__), 'template/output/markdown/index.html')
126
+ assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
127
+ end
128
+
129
+ should 'create mustache.html' do
130
+ output = File.join(File.dirname(__FILE__), 'template/output/mustache/index.html')
131
+ assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
132
+ end
133
+
134
+ should 'create liquid.html' do
135
+ output = File.join(File.dirname(__FILE__), 'template/output/liquid/index.html')
136
+ assert_equal "<h1>hello worlds</h1>", IO.read(output)
137
+ end
138
+
139
+ should 'create builder.html' do
140
+ output = File.join(File.dirname(__FILE__), 'template/output/builder/index.html')
141
+ assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
142
+ end
143
+
144
+ should 'copy static.html' do
145
+ output = File.join(File.dirname(__FILE__), 'template/output/static.html')
146
+ assert_equal "hello from static", IO.read(output)
147
+ end
148
+
149
+ should 'not create partials' do
150
+ assert !File.exist?(File.join(File.dirname(__FILE__), 'template/output/_partial/index.html'))
151
+ end
152
+
153
+ teardown do
154
+ FileUtils.rm_r File.join(File.dirname(__FILE__), 'template/output')
155
+ end
156
+
78
157
 
79
158
  end
80
159
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 4
9
- version: 0.2.4
8
+ - 5
9
+ version: 0.2.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - blahed
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-03-29 00:00:00 -04:00
18
+ date: 2010-04-02 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency