frank 0.4.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,152 @@
1
+ require 'optparse'
2
+
3
+ module Frank
4
+ class CLI
5
+ BANNER = <<-USAGE
6
+ Usage:
7
+ frank new PROJECT_PATH
8
+ frank server [options]
9
+ frank export PATH [options]
10
+ frank publish
11
+
12
+ Description:
13
+ The `frank new' command generates a frank template project with the default
14
+ directory structure and configuration at the given path.
15
+
16
+ Once you have a frank project you can use the `frank server' or the aliased 'frank up' commands
17
+ to start the development server and begin developing your project.
18
+
19
+ When you are finished working and ready to export you can use
20
+ the `frank export' or aliased `frank out' commands.
21
+
22
+ Example:
23
+ frank new ~/Dev/blah.com
24
+ cd ~/Dev/blah.com
25
+ frank server
26
+
27
+ # do some development
28
+
29
+ # export it
30
+ frank export ~/Dev/html/blah.com
31
+
32
+ # or publish it
33
+ frank publish
34
+ USAGE
35
+
36
+ class << self
37
+
38
+ def set_options
39
+ @options = {:server => {}}
40
+
41
+ @opts = OptionParser.new do |opts|
42
+ opts.banner = BANNER.gsub(/^\s{4}/, '')
43
+
44
+ opts.separator ''
45
+ opts.separator 'Options:'
46
+
47
+ opts.on('--server [HANDLER]', 'Set the server handler (frank server)') do |handler|
48
+ @options[:server]['handler'] = handler unless handler.nil?
49
+ end
50
+
51
+ opts.on('--hostname [HOSTNAME]', 'Set the server hostname (frank server)') do |hostname|
52
+ @options[:server]['hostname'] = hostname unless hostname.nil?
53
+ end
54
+
55
+ opts.on('--port [PORT]', 'Set the server port (frank server)') do |port|
56
+ @options[:server]['port'] = port unless port.nil?
57
+ end
58
+
59
+ opts.on('--dynamic_folder [FOLDER]', 'Set the dynamic folder (frank server)') do |folder|
60
+ @options[:dynamic_folder] = folder unless folder.nil?
61
+ end
62
+
63
+ opts.on('--static_folder [FOLDER]', 'Set the static folder (frank server)') do |folder|
64
+ @options[:static_folder] = folder unless folder.nil?
65
+ end
66
+
67
+ opts.on('--production', 'Production ready export (frank export) i.e. ([FOLDER]/index.html)') do |handler|
68
+ @options[:production] = true
69
+ end
70
+
71
+ opts.on('-v', '--version', 'Show the frank version and exit') do
72
+ puts "Frank v#{Frank::VERSION}"
73
+ exit
74
+ end
75
+
76
+ opts.on( '-h', '--help', 'Display this help' ) do
77
+ puts opts
78
+ exit
79
+ end
80
+ end
81
+
82
+ @opts.parse!
83
+ end
84
+
85
+ # parse and set options
86
+ # bootstrap if we need to
87
+ # and go go go
88
+ def run
89
+ set_options
90
+
91
+ if ARGV.empty?
92
+ print_usage_and_exit!
93
+ else
94
+ bootstrap
95
+ run!
96
+ end
97
+ end
98
+
99
+ # determine what the user wants us to do
100
+ # and then, just do it
101
+ def run!
102
+ case ARGV.first
103
+ when 'new', 'n'
104
+ print_usage_and_exit! unless ARGV[1]
105
+ # stub out the project
106
+ Frank.stub(ARGV[1])
107
+ when 'server', 's', 'up'
108
+ # setup server from options
109
+ server_options = @options[:server]
110
+ Frank.server.handler = server_options['handler'] if server_options['handler']
111
+ Frank.server.hostname = server_options['hostname'] if server_options['hostname']
112
+ Frank.server.port = server_options['port'] if server_options['port']
113
+
114
+ # setup folder options
115
+ Frank.dynamic_folder = @options[:dynamic_folder] if @options[:dynamic_folder]
116
+ Frank.static_folder = @options[:static_folder] if @options[:static_folder]
117
+ Frank.new
118
+ when 'export', 'e', 'out'
119
+ # compile the project
120
+ print_usage_and_exit! unless ARGV[1]
121
+ Frank.exporting!
122
+ Frank.production! if @options[:production]
123
+ Frank.export.path = ARGV[1]
124
+ Frank::Compile.export!
125
+ when 'publish', 'p'
126
+ # compile the project and scp it to server
127
+ Frank.publishing!
128
+ Frank::Publish::SCP.execute!
129
+ when 'upgrade'
130
+ # upgrade if we need to upgrade
131
+ Frank.upgrade!
132
+ end
133
+ end
134
+
135
+ # print the usage banner and exit
136
+ def print_usage_and_exit!
137
+ puts @opts
138
+ exit
139
+ end
140
+
141
+ # bootstrap this project up
142
+ # only if we really need to
143
+ def bootstrap
144
+ if %w[server up export out publish upgrade s e p].include? ARGV.first
145
+ Frank.bootstrap(Dir.pwd)
146
+ end
147
+ end
148
+
149
+ end
150
+
151
+ end
152
+ end
@@ -0,0 +1,65 @@
1
+ module Frank
2
+ class Compile < Frank::Base
3
+
4
+ class << self
5
+ include Frank::Render
6
+
7
+ # compile the templates
8
+ # if production and template isn't index and is html
9
+ # name a folder based on the template and compile to index.html
10
+ # otherwise compile as is
11
+ def compile_templates
12
+ dir = File.join(Frank.root, Frank.dynamic_folder)
13
+
14
+ Dir[File.join(dir, '**{,/*/**}/*')].each do |path|
15
+ if File.file?(path) && !File.basename(path).match(/^(\.|_)/)
16
+ path = path[ (dir.size + 1)..-1 ]
17
+ ext = File.extname(path)
18
+ new_ext = ext_from_handler(ext)
19
+ name = File.basename(path, ext)
20
+
21
+ if Frank.production? && "#{name}.#{new_ext}" != 'index.html' && new_ext == 'html'
22
+ new_file = File.join(Frank.export.path, path.sub(/(\/?[\w-]+)\.[\w-]+$/, "\\1/index.#{new_ext}"))
23
+ else
24
+ new_file = File.join(Frank.export.path, path.sub(/\.[\w-]+$/, ".#{new_ext}"))
25
+ end
26
+
27
+ create_dirs(new_file)
28
+ File.open(new_file, 'w') {|f| f.write render(path) }
29
+ puts " - \033[32mCreating\033[0m '#{new_file}'" unless Frank.silent_export?
30
+ end
31
+ end
32
+ end
33
+
34
+ # use path to determine folder name and
35
+ # create the required folders if they don't exist
36
+ def create_dirs(path)
37
+ FileUtils.makedirs path.split('/').reverse[1..-1].reverse.join('/')
38
+ end
39
+
40
+ # copies over static content
41
+ def copy_static
42
+ puts " - \033[32mCopying\033[0m static content" unless Frank.silent_export?
43
+ static_folder = File.join(Frank.root, Frank.static_folder)
44
+ FileUtils.cp_r(File.join(static_folder, '/.'), Frank.export.path)
45
+ end
46
+
47
+ # TODO verbose everywhere is lame
48
+ # create the dump dir, compile templates, copy over static assets
49
+ def export!
50
+ FileUtils.mkdir(Frank.export.path)
51
+
52
+ unless Frank.silent_export?
53
+ puts "\nFrank is..."
54
+ puts " - \033[32mCreating\033[0m '#{Frank.export.path}'"
55
+ end
56
+
57
+ compile_templates
58
+ copy_static
59
+
60
+ puts "\n \033[32mCongratulations, project dumped to '#{Frank.export.path}' successfully!\033[0m" unless Frank.silent_export?
61
+ end
62
+ end
63
+
64
+ end
65
+ end
@@ -2,17 +2,12 @@ module Frank
2
2
  class Lorem
3
3
  WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat)
4
4
 
5
- def initialize(environment)
6
- @environment = environment
7
-
8
- end
9
-
10
5
  def word(replacement = nil)
11
6
  words 1, replacement
12
7
  end
13
8
 
14
9
  def words(total, replacement = nil)
15
- if @environment == :output && replacement
10
+ if Frank.exporting? && replacement
16
11
  replacement
17
12
  else
18
13
  (1..total).map do
@@ -27,7 +22,7 @@ module Frank
27
22
 
28
23
  def sentences(total, replacement = nil)
29
24
  # TODO: Don't capitalize replacement field
30
- if @environment == :output && replacement
25
+ if Frank.exporting? && replacement
31
26
  replacement
32
27
  else
33
28
  (1..total).map do
@@ -41,7 +36,7 @@ module Frank
41
36
  end
42
37
 
43
38
  def paragraphs(total, replacement = nil)
44
- if @environment == :output && replacement
39
+ if Frank.exporting? && replacement
45
40
  replacement
46
41
  else
47
42
  (1..total).map do
@@ -51,7 +46,7 @@ module Frank
51
46
  end
52
47
 
53
48
  def date(fmt = '%a %b %d, %Y', replacement = nil)
54
- if @environment == :output && replacement
49
+ if Frank.exporting? && replacement
55
50
  replacement
56
51
  else
57
52
  y = rand(20) + 1990
@@ -62,7 +57,7 @@ module Frank
62
57
  end
63
58
 
64
59
  def name(replacement = nil)
65
- if @environment == :output && replacement
60
+ if Frank.exporting? && replacement
66
61
  replacement
67
62
  else
68
63
  "#{first_name} #{last_name}"
@@ -70,7 +65,7 @@ module Frank
70
65
  end
71
66
 
72
67
  def first_name(replacement = nil)
73
- if @environment == :output && replacement
68
+ if Frank.exporting? && replacement
74
69
  replacement
75
70
  else
76
71
  names = %w(Judith Angelo Margarita Kerry Elaine Lorenzo Justice Doris Raul Liliana Kerry Elise Ciaran Johnny Moses Davion Penny Mohammed Harvey Sheryl Hudson Brendan Brooklynn Denis Sadie Trisha Jacquelyn Virgil Cindy Alexa Marianne Giselle Casey Alondra Angela Katherine Skyler Kyleigh Carly Abel Adrianna Luis Dominick Eoin Noel Ciara Roberto Skylar Brock Earl Dwayne Jackie Hamish Sienna Nolan Daren Jean Shirley Connor Geraldine Niall Kristi Monty Yvonne Tammie Zachariah Fatima Ruby Nadia Anahi Calum Peggy Alfredo Marybeth Bonnie Gordon Cara John Staci Samuel Carmen Rylee Yehudi Colm Beth Dulce Darius inley Javon Jason Perla Wayne Laila Kaleigh Maggie Don Quinn Collin Aniya Zoe Isabel Clint Leland Esmeralda Emma Madeline Byron Courtney Vanessa Terry Antoinette George Constance Preston Rolando Caleb Kenneth Lynette Carley Francesca Johnnie Jordyn Arturo Camila Skye Guy Ana Kaylin Nia Colton Bart Brendon Alvin Daryl Dirk Mya Pete Joann Uriel Alonzo Agnes Chris Alyson Paola Dora Elias Allen Jackie Eric Bonita Kelvin Emiliano Ashton Kyra Kailey Sonja Alberto Ty Summer Brayden Lori Kelly Tomas Joey Billie Katie Stephanie Danielle Alexis Jamal Kieran Lucinda Eliza Allyson Melinda Alma Piper Deana Harriet Bryce Eli Jadyn Rogelio Orlaith Janet Randal Toby Carla Lorie Caitlyn Annika Isabelle inn Ewan Maisie Michelle Grady Ida Reid Emely Tricia Beau Reese Vance Dalton Lexi Rafael Makenzie Mitzi Clinton Xena Angelina Kendrick Leslie Teddy Jerald Noelle Neil Marsha Gayle Omar Abigail Alexandra Phil Andre Billy Brenden Bianca Jared Gretchen Patrick Antonio Josephine Kyla Manuel Freya Kellie Tonia Jamie Sydney Andres Ruben Harrison Hector Clyde Wendell Kaden Ian Tracy Cathleen Shawn)
@@ -79,7 +74,7 @@ module Frank
79
74
  end
80
75
 
81
76
  def last_name(replacement = nil)
82
- if @environment == :output && replacement
77
+ if Frank.exporting? && replacement
83
78
  replacement
84
79
  else
85
80
  names = %w(Chung Chen Melton Hill Puckett Song Hamilton Bender Wagner McLaughlin McNamara Raynor Moon Woodard Desai Wallace Lawrence Griffin Dougherty Powers May Steele Teague Vick Gallagher Solomon Walsh Monroe Connolly Hawkins Middleton Goldstein Watts Johnston Weeks Wilkerson Barton Walton Hall Ross Chung Bender Woods Mangum Joseph Rosenthal Bowden Barton Underwood Jones Baker Merritt Cross Cooper Holmes Sharpe Morgan Hoyle Allen Rich Rich Grant Proctor Diaz Graham Watkins Hinton Marsh Hewitt Branch Walton O'Brien Case Watts Christensen Parks Hardin Lucas Eason Davidson Whitehead Rose Sparks Moore Pearson Rodgers Graves Scarborough Sutton Sinclair Bowman Olsen Love McLean Christian Lamb James Chandler Stout Cowan Golden Bowling Beasley Clapp Abrams Tilley Morse Boykin Sumner Cassidy Davidson Heath Blanchard McAllister McKenzie Byrne Schroeder Griffin Gross Perkins Robertson Palmer Brady Rowe Zhang Hodge Li Bowling Justice Glass Willis Hester Floyd Graves Fischer Norman Chan Hunt Byrd Lane Kaplan Heller May Jennings Hanna Locklear Holloway Jones Glover Vick O'Donnell Goldman McKenna Starr Stone McClure Watson Monroe Abbott Singer Hall Farrell Lucas Norman Atkins Monroe Robertson Sykes Reid Chandler Finch Hobbs Adkins Kinney Whitaker Alexander Conner Waters Becker Rollins Love Adkins Black Fox Hatcher Wu Lloyd Joyce Welch Matthews Chappell MacDonald Kane Butler Pickett Bowman Barton Kennedy Branch Thornton McNeill Weinstein Middleton Moss Lucas Rich Carlton Brady Schultz Nichols Harvey Stevenson Houston Dunn West O'Brien Barr Snyder Cain Heath Boswell Olsen Pittman Weiner Petersen Davis Coleman Terrell Norman Burch Weiner Parrott Henry Gray Chang McLean Eason Weeks Siegel Puckett Heath Hoyle Garrett Neal Baker Goldman Shaffer Choi Carver)
@@ -88,7 +83,7 @@ module Frank
88
83
  end
89
84
 
90
85
  def email(replacement = nil)
91
- if @environment == :output && replacement
86
+ if Frank.exporting? && replacement
92
87
  replacement
93
88
  else
94
89
  delimiters = [ '_', '-', '' ]
@@ -98,8 +93,9 @@ module Frank
98
93
  end
99
94
  end
100
95
 
96
+
101
97
  def image(size, options={})
102
- if @environment == :output && options[:replacement]
98
+ if Frank.exporting? && options[:replacement]
103
99
  options[:replacement]
104
100
  else
105
101
  src = "http://placehold.it/#{size}"
@@ -0,0 +1,46 @@
1
+ module Frank
2
+ module Publish
3
+
4
+ class SCP
5
+ def self.execute!
6
+ puts "\nFrank is..."
7
+ puts " - \033[32mExporting templates\033[0m"
8
+
9
+ tmp_folder = "/tmp/frankexp-#{Frank.proj_name}"
10
+
11
+ # remove stale folder if it exists
12
+ FileUtils.rm_rf(tmp_folder) if File.exist?(tmp_folder)
13
+
14
+ # dump the project in production mode to tmp folder
15
+ Frank.export.path = tmp_folder
16
+ Frank.export.silent = true
17
+ Frank::Compile.export!
18
+
19
+ puts " - \033[32mPublishing to:\033[0m `#{Frank.publish.host}:#{Frank.publish.path}'"
20
+
21
+ ssh_options = {
22
+ :password => Frank.publish.password,
23
+ :port => Frank.publish.port
24
+ }
25
+
26
+ current = nil
27
+
28
+ # upload the files and report progress
29
+ Net::SSH.start(Frank.publish.host, Frank.publish.user, ssh_options) do |ssh|
30
+ ssh.scp.upload!(tmp_folder, Frank.publish.path, :recursive => true, :chunk_size => 2048) do |ch, name, sent, total|
31
+
32
+ puts " - #{name[tmp_folder.length..-1]}" unless name == current
33
+
34
+ current = name
35
+ end
36
+ end
37
+
38
+ # cleanup by removing tmp folder
39
+ FileUtils.rm_rf(tmp_folder)
40
+
41
+ puts "\n\033[32mPublish complete!\033[0m"
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -12,6 +12,8 @@ module Frank
12
12
  attr_accessor :static_folder
13
13
  attr_accessor :dynamic_folder
14
14
  attr_accessor :layouts_folder
15
+ attr_accessor :export
16
+ attr_accessor :publish
15
17
  attr_accessor :sass_options
16
18
 
17
19
  def initialize
@@ -29,6 +31,18 @@ module Frank
29
31
  # reset options
30
32
  @options = OpenStruct.new
31
33
 
34
+ # export settings
35
+ @export = OpenStruct.new
36
+ @export.path = nil
37
+ @export.silent = false
38
+
39
+ # publish options
40
+ @publish = OpenStruct.new
41
+ @publish.host = nil
42
+ @publish.path = nil
43
+ @publish.username = nil
44
+ @publish.password = nil
45
+
32
46
  # setup folders
33
47
  @static_folder = "static"
34
48
  @dynamic_folder = "dynamic"
@@ -38,6 +52,26 @@ module Frank
38
52
  @sass_options = {}
39
53
  end
40
54
 
55
+ # return the proj folder name
56
+ def proj_name
57
+ @root.split('/').last
58
+ end
59
+
60
+ # Check to see if we're compiling
61
+ def exporting?
62
+ @exporting
63
+ end
64
+
65
+ # Mark this Frank run as compiling
66
+ def exporting!
67
+ @exporting = true
68
+ end
69
+
70
+ # Silent export if set or in test
71
+ def silent_export?
72
+ @environment == :test || @export.silent
73
+ end
74
+
41
75
  # Check to see if we're in production mode
42
76
  def production?
43
77
  @production
@@ -48,5 +82,11 @@ module Frank
48
82
  @production = true
49
83
  end
50
84
 
85
+ # Mark this Frank run as publishing
86
+ def publishing!
87
+ @exporting = true
88
+ @production = true
89
+ end
90
+
51
91
  end
52
92
  end
@@ -3,20 +3,20 @@ require 'frank/lorem'
3
3
  module Frank
4
4
  module TemplateHelpers
5
5
  include FrankHelpers if defined? FrankHelpers
6
-
6
+
7
7
  def render_partial(path, *locals)
8
8
  pieces = path.split('/')
9
9
  partial = '_' + pieces.pop
10
10
  locals = locals.empty? ? nil : locals[0]
11
11
  render(File.join(pieces.join('/'), partial), partial = true, locals)
12
12
  end
13
-
13
+
14
14
  def lorem
15
- Frank::Lorem.new(@environment)
15
+ Frank::Lorem.new
16
16
  end
17
-
17
+
18
18
  def refresh
19
- if @environment == :output
19
+ if Frank.exporting?
20
20
  nil
21
21
  else
22
22
  <<-JS
@@ -30,9 +30,9 @@ module Frank
30
30
  }
31
31
 
32
32
  (function poll(){
33
- var req = new XMLHttpRequest();
34
- req.open('GET', '/__refresh__', true);
35
- req.onreadystatechange = function (aEvt) {
33
+ var req = new XMLHttpRequest();
34
+ req.open('GET', '/__refresh__', true);
35
+ req.onreadystatechange = function (aEvt) {
36
36
  if ( req.readyState == 4 && req.status == 200 )
37
37
  process(req.responseText);
38
38
  };
@@ -45,6 +45,6 @@ module Frank
45
45
  JS
46
46
  end
47
47
  end
48
-
48
+
49
49
  end
50
50
  end