frank 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,11 +2,13 @@ Frank
2
2
  =========
3
3
 
4
4
  Inspired by [Sinatra][0]'s simplicity and ease of use, Frank lets you build
5
- static sites using your favorite libs, painlessly. It uses [Tilt][1], so it
6
- comes with support for [Haml & Sass][2], [LESS][10], [Builder][3], [ERB][4],
7
- [Liquid][5], & [Mustache][6].
5
+ static sites using your favorite libs. Frank has a built in development server
6
+ for previewing work as you develop. Frank also has a "dump" command for compiling and saving
7
+ your work out to static html, css, and js.
8
8
 
9
- Frank also supports [CoffeeScript][7] for writing JavaScript in style.
9
+ Frank uses [Tilt][1], so it
10
+ comes with support for [Haml & Sass][2], [LESS][10], [Builder][3], [ERB][4],
11
+ [Liquid][5], [Mustache][6], and [CoffeeScript][7].
10
12
 
11
13
  Overview
12
14
  --------
@@ -15,18 +17,22 @@ Create a new project with:
15
17
 
16
18
  $ frank <project_name>
17
19
 
18
- Then start up the server with:
19
-
20
+ Then `cd <project_name>` and start up the server with:
21
+
20
22
  $ frankup
21
23
 
22
24
  -----------------------
23
25
  Frank's holdin' it down...
24
26
  0.0.0.0:3601
25
27
 
26
- And you're ready to get to work. Feel free to use as much or a little of
27
- the available libs as you please. Frank works just as well with Mustache /
28
- CSS / JavasScript as Haml / Sass / CoffeeScript.
28
+ And you're ready to get to work. By default, dynamic templates are served from the `dynamic` folder
29
+ and static files are served from the `static` folder.
30
+
31
+ When you are finished:
32
+
33
+ $ frankout <dump_dir>
29
34
 
35
+ This will compile and copy everything to the folder given.
30
36
 
31
37
  Views & Layouts
32
38
  -------------------------
@@ -100,6 +106,7 @@ This will return 3 sentences of standard [Lorem Ipsum][11]. `lorem` also has all
100
106
  lorem.word
101
107
  lorem.paragraphs 10
102
108
  lorem.paragraph
109
+ lorem.date # accepts a strftime format argument
103
110
  lorem.name
104
111
  lorem.first_name
105
112
  lorem.last_name
data/bin/frankup CHANGED
@@ -1,14 +1,60 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'optparse'
2
3
  require 'frank'
3
4
 
4
- begin
5
+ options = {:server => {}}
6
+
7
+ opts = OptionParser.new do |opts|
8
+
9
+ opts.on('--server [HANDLER]', 'Set the server handler') do |handler|
10
+ options[:server]['handler'] = handler unless handler.nil?
11
+ end
12
+
13
+ opts.on('--hostname [HOSTNAME]', 'Set the server hostname') do |hostname|
14
+ options[:server]['hostname'] = hostname unless hostname.nil?
15
+ end
16
+
17
+ opts.on('--port [PORT]', 'Set the server port') do |port|
18
+ options[:server]['port'] = port unless port.nil?
19
+ end
20
+
21
+ opts.on('--dynamic_folder [FOLDER]', 'Set the dynamic folder') do |folder|
22
+ options[:dynamic_folder] = folder unless folder.nil?
23
+ end
24
+
25
+ opts.on('--static_folder [FOLDER]', 'Set the static folder') do |folder|
26
+ options[:static_folder] = folder unless folder.nil?
27
+ end
28
+
29
+ end.parse!
30
+
31
+ if File.exist? 'settings.yml'
5
32
  settings = YAML.load_file('settings.yml')
6
- Frank.new do
7
- settings.each do |name, value|
8
- set name.to_s, value
9
- end
10
- set :proj_dir, Dir.pwd
11
- end
12
- rescue Errno::ENOENT
13
- puts "Frank could not find settings.yml."
14
- end
33
+ else
34
+ settings = {
35
+ :server => { 'handler' => 'mongrel', 'hostname' => '127.0.0.1', 'port' => 3601 },
36
+ :static_folder => '.',
37
+ :dynamic_folder => '.',
38
+ :environment => :serving
39
+ }
40
+ end
41
+
42
+ options.each do |opt, val|
43
+ if opt == :server
44
+ server = settings['server'] ? settings['server'] : settings[:server]
45
+ val.each { |sopt, sval| server[sopt] = sval }
46
+ else
47
+ settings[opt] = val
48
+ end
49
+ end
50
+
51
+ if settings[:environment] == :serving
52
+ puts "Could not find \"settings.yml\", serving up files from the this directory at http://#{settings[:server]['hostname']}:#{settings[:server]['port']}"
53
+ end
54
+
55
+ Frank.new do
56
+ settings.each do |name, value|
57
+ set name.to_s, value
58
+ end
59
+ set :proj_dir, Dir.pwd
60
+ end
data/frank.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{frank}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
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-11}
12
+ s.date = %q{2010-03-29}
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"]
@@ -86,7 +86,7 @@ Gem::Specification.new do |s|
86
86
  s.homepage = %q{http://github.com/blahed/frank}
87
87
  s.rdoc_options = ["--charset=UTF-8"]
88
88
  s.require_paths = ["lib"]
89
- s.rubygems_version = %q{1.3.5}
89
+ s.rubygems_version = %q{1.3.6}
90
90
  s.summary = %q{Stupidly Simple Static Slinger}
91
91
  s.test_files = [
92
92
  "test/helper.rb",
data/lib/frank/base.rb CHANGED
@@ -5,7 +5,7 @@ require 'frank/statik'
5
5
  require 'frank/imager'
6
6
 
7
7
  module Frank
8
- VERSION = '0.2.3'
8
+ VERSION = '0.2.4'
9
9
 
10
10
  module Render; end
11
11
 
@@ -85,13 +85,14 @@ module Frank
85
85
 
86
86
  # renders a template
87
87
  def render_template(tmpl, *args)
88
- tilt_with_request(File.join(@proj_dir, @dynamic_folder, tmpl), *args) {"CONTENT"}
88
+ tilt(File.join(@proj_dir, @dynamic_folder, tmpl), *args) {"CONTENT"}
89
89
  end
90
90
 
91
- # renders layout and template inside layout block
91
+ # if template has a layout defined, render template within layout
92
+ # otherwise render template
92
93
  def render_with_layout(tmpl, *args)
93
94
  if layout = get_layout_for(tmpl)
94
- tilt_with_request(File.join(@proj_dir, @dynamic_folder, layout), *args) do
95
+ tilt(File.join(@proj_dir, @dynamic_folder, layout), *args) do
95
96
  render_template tmpl
96
97
  end
97
98
  else
@@ -132,8 +133,7 @@ module Frank
132
133
  tmpl_ext
133
134
  end
134
135
 
135
- # determines layout using layouts setting
136
- # in settings.yml
136
+ # determines layout using layouts settings
137
137
  # TODO: cleanup
138
138
  def get_layout_for(view)
139
139
  view, ext = name_ext(view)
@@ -142,18 +142,20 @@ module Frank
142
142
  onlies = layouts.select {|l| l['only'] }
143
143
  nots = layouts.select {|l| l['not'] }
144
144
  blanks = layouts - onlies - nots
145
-
146
- layout = onlies.select {|l| l['only'].index(view) }.first
145
+
146
+ layout = onlies.select {|l| l['only'].index(view) }.first
147
147
  layout = nots.reject {|l| l['not'].index(view) }.first unless layout
148
148
  layout = blanks.first unless layout
149
-
150
- layout = nil if (TMPL_EXTS[:css] + TMPL_EXTS[:js]).include?(ext)
151
149
 
150
+ # TODO: we are checking for exts in two places, consolidate soon
151
+ layout = nil if !blanks.empty? && blanks.first['name'] == view
152
+ layout = nil if (TMPL_EXTS[:css] + TMPL_EXTS[:js]).include?(ext)
153
+
152
154
  layout.nil? ? nil : layout['name'] + '.' + ext
153
155
  end
154
156
 
155
157
  # TODO: cleanup
156
- def tilt_with_request(file, *args, &block)
158
+ def tilt(file, *args, &block)
157
159
  locals = @request.nil? ? {} : { :request => @env, :params => @request.params }
158
160
  obj = Object.new.extend(TemplateHelpers).extend(Render)
159
161
  obj.instance_variable_set(:@proj_dir, @proj_dir)
@@ -184,8 +186,8 @@ module Frank
184
186
  puts "\n-----------------------\n" +
185
187
  " Frank's #{ m }...\n" +
186
188
  " #{base.server['hostname']}:#{base.server['port']} \n\n"
187
-
188
189
  server = Rack::Handler.get(base.server['handler'])
190
+
189
191
  server.run(builder, :Port => base.server['port'], :Host => base.server['hostname']) do
190
192
  trap(:INT) { puts "\n\n-----------------------\n Show's over, fellas.\n\n"; exit }
191
193
  end
data/lib/frank/output.rb CHANGED
@@ -10,7 +10,8 @@ module Frank
10
10
  instance_eval &block
11
11
  @output_path = File.join(@proj_dir, @output_folder)
12
12
  end
13
-
13
+
14
+ # get all of the templates and compile them
14
15
  def compile_templates
15
16
  dir = File.join(@proj_dir, @dynamic_folder)
16
17
 
@@ -26,13 +27,15 @@ module Frank
26
27
  end
27
28
  end
28
29
  end
29
-
30
+
31
+ # copies over static content
30
32
  def copy_static
31
33
  puts "Copying over your static content" unless @environment == :test
32
34
  static_folder = File.join(@proj_dir, @static_folder)
33
35
  FileUtils.cp_r(File.join(static_folder, '/.'), @output_path)
34
36
  end
35
-
37
+
38
+ # create the dump dir, compile templates, copy over static assets
36
39
  def dump
37
40
  FileUtils.mkdir(@output_path)
38
41
  puts "Create #{@output_folder}" unless @environment == :test
data/lib/frank/rescue.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  module Frank
2
- module Rescue
2
+ module Rescue
3
3
 
4
4
  def render_404
5
5
  template = File.expand_path(File.dirname(__FILE__)) + '/templates/404.haml'
6
- locals = { :request => @env, :dynamic_folder => @dynamic_folder, :static_folder => @static_folder }
7
-
6
+ locals = { :request => @env,
7
+ :dynamic_folder => @dynamic_folder,
8
+ :static_folder => @static_folder,
9
+ :environment => @environment }
10
+
8
11
  @response['Content-Type'] = 'text/html'
9
12
  @response.status = 404
10
13
  @response.body = Tilt.new(template, 1).render(Object.new, locals = locals)
@@ -13,21 +13,22 @@
13
13
  #wrapper
14
14
  %img{:src=>'/__frank__/frank-404.png'}
15
15
  %h1= "Not Found&mdash;"
16
- %p
17
- - if request['REQUEST_PATH']
18
- - path = request['REQUEST_PATH'][1..-1]
19
- = "Try creating"
16
+ - unless environment == :serving
17
+ %p
18
+ - if request['REQUEST_PATH']
19
+ - path = request['REQUEST_PATH'][1..-1]
20
+ = "Try creating"
20
21
 
21
- - if path.match(/\.css$/)
22
- = "<tt>#{path.match(/([\w\/]+)\./)[1]}.sass</tt>"
23
- - elsif path.match(/\.js$/)
24
- = "<tt>#{path.match(/([\w\/]+)\./)[1]}.coffee</tt>"
25
- - else
26
- = "<tt>#{path.gsub(/\/$/, '')}.haml</tt>"
27
- = "in the <tt>#{dynamic_folder}</tt> folder, or"
22
+ - if path.match(/\.css$/)
23
+ = "<tt>#{path.match(/([\w\/]+)\./)[1]}.sass</tt>"
24
+ - elsif path.match(/\.js$/)
25
+ = "<tt>#{path.match(/([\w\/]+)\./)[1]}.coffee</tt>"
26
+ - else
27
+ = "<tt>#{path.gsub(/\/$/, '')}.haml</tt>"
28
+ = "in the <tt>#{dynamic_folder}</tt> folder, or"
28
29
 
29
- - if path.match(/\.\w+/)
30
- = "<tt>#{path}</tt>"
31
- - else
32
- = "<tt>#{path.gsub(/\/$/, '')}.html</tt>"
33
- = "in the <tt>#{static_folder}</tt> folder."
30
+ - if path.match(/\.\w+/)
31
+ = "<tt>#{path}</tt>"
32
+ - else
33
+ = "<tt>#{path.gsub(/\/$/, '')}.html</tt>"
34
+ = "in the <tt>#{static_folder}</tt> folder."
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 4
9
+ version: 0.2.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - blahed
@@ -10,59 +15,74 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-03-11 00:00:00 -05:00
18
+ date: 2010-03-29 00:00:00 -04:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: rack
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 0
24
31
  version: "1.0"
25
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
26
34
  - !ruby/object:Gem::Dependency
27
35
  name: mongrel
28
- type: :runtime
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
31
38
  requirements:
32
39
  - - ">="
33
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 0
34
44
  version: "1.0"
35
- version:
45
+ type: :runtime
46
+ version_requirements: *id002
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: haml
38
- type: :runtime
39
- version_requirement:
40
- version_requirements: !ruby/object:Gem::Requirement
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
41
51
  requirements:
42
52
  - - ">="
43
53
  - !ruby/object:Gem::Version
54
+ segments:
55
+ - 2
56
+ - 0
44
57
  version: "2.0"
45
- version:
58
+ type: :runtime
59
+ version_requirements: *id003
46
60
  - !ruby/object:Gem::Dependency
47
61
  name: shoulda
48
- type: :development
49
- version_requirement:
50
- version_requirements: !ruby/object:Gem::Requirement
62
+ prerelease: false
63
+ requirement: &id004 !ruby/object:Gem::Requirement
51
64
  requirements:
52
65
  - - ">="
53
66
  - !ruby/object:Gem::Version
67
+ segments:
68
+ - 2
69
+ - 0
54
70
  version: "2.0"
55
- version:
71
+ type: :development
72
+ version_requirements: *id004
56
73
  - !ruby/object:Gem::Dependency
57
74
  name: rack-test
58
- type: :development
59
- version_requirement:
60
- version_requirements: !ruby/object:Gem::Requirement
75
+ prerelease: false
76
+ requirement: &id005 !ruby/object:Gem::Requirement
61
77
  requirements:
62
78
  - - ">="
63
79
  - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ - 5
64
83
  version: "0.5"
65
- version:
84
+ type: :development
85
+ version_requirements: *id005
66
86
  description: Create/Dump static builds using whatever templating/helper languages you wish
67
87
  email: travis.dunn@thisismedium.com
68
88
  executables:
@@ -152,18 +172,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
172
  requirements:
153
173
  - - ">="
154
174
  - !ruby/object:Gem::Version
175
+ segments:
176
+ - 0
155
177
  version: "0"
156
- version:
157
178
  required_rubygems_version: !ruby/object:Gem::Requirement
158
179
  requirements:
159
180
  - - ">="
160
181
  - !ruby/object:Gem::Version
182
+ segments:
183
+ - 0
161
184
  version: "0"
162
- version:
163
185
  requirements: []
164
186
 
165
187
  rubyforge_project:
166
- rubygems_version: 1.3.5
188
+ rubygems_version: 1.3.6
167
189
  signing_key:
168
190
  specification_version: 3
169
191
  summary: Stupidly Simple Static Slinger