Class: Tonka
- Inherits:
-
Object
- Object
- Tonka
- Defined in:
- lib/tonka.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#options ⇒ Object
Returns the value of attribute options.
-
#site_name ⇒ Object
Returns the value of attribute site_name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #display_usage ⇒ Object
-
#initialize(options = []) ⇒ Tonka
constructor
A new instance of Tonka.
- #make_directories ⇒ Object
- #make_files ⇒ Object
- #parse_options(options = []) ⇒ Object
- #serve(port) ⇒ Object
Constructor Details
#initialize(options = []) ⇒ Tonka
Returns a new instance of Tonka.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/tonka.rb', line 11 def initialize(=[]) @version = "0.0.8"; @options = || ARGV if !@options[0].nil? (@options) else display_usage end end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
7 8 9 |
# File 'lib/tonka.rb', line 7 def action @action end |
#messages ⇒ Object
Returns the value of attribute messages.
7 8 9 |
# File 'lib/tonka.rb', line 7 def @messages end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/tonka.rb', line 7 def @options end |
#site_name ⇒ Object
Returns the value of attribute site_name.
7 8 9 |
# File 'lib/tonka.rb', line 7 def site_name @site_name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/tonka.rb', line 9 def version @version end |
Instance Method Details
#display_usage ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/tonka.rb', line 98 def display_usage usage_array = ["usage: tonka <action> SITE_NAME [-options] BODY_TEXT\n\n", "The most common actions:\n\n", "build\s\t\t\tbuilds a basic static site with the name passed in as SITE_NAME\n\n", "destroy\s\t\t\tdestroys a previously built site with the name passed in as SITE_NAME\n\n", "serve\s\t\t\tserves your files using WEBrick on port 2000 (a different port can be passed in as an argument)\n\n", "The most common options:\n\n", "-bootstrap \t adds Bootstrap front-end int your stylesheets, javascripts and index.html\n", "-jquery \t\tadds jquery to index.html file.\n", "-underscore \t\tadds underscore.js to the javascripts folder and the index.html file.\n", "-backbone \t\tadds backbone.js, underscore.js, and jquery.js to the javascripts folder and the index.html file.\n", "-handlebars \t\tadds handlebars.js to the javascripts folder and the index.html file.\n", "-d3 \t\t\tadds d3.js to the javascripts folder and the index.html file.\n", "-raphael \t\tadds raphael.js to the javascripts folder and the index.html file.\n", "-angular \t\tadds angular.js to the javascripts folder and the index.html file. Also adds <html ng-app> at top of the index file.\n" ] puts usage_array.join("") end |
#make_directories ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tonka.rb', line 32 def make_directories if !Dir.exist? $SITE_NAME Dir.mkdir $SITE_NAME Dir.mkdir "#{$SITE_NAME}/stylesheets" puts "\t\tbuilt ".green+"#{$SITE_NAME}/stylesheets/" Dir.mkdir "#{$SITE_NAME}/javascripts" puts "\t\tbuilt ".green+"#{$SITE_NAME}/javascripts/" else puts "a '#{$SITE_NAME}' directory already exists!" display_usage end end |
#make_files ⇒ Object
46 47 48 |
# File 'lib/tonka.rb', line 46 def make_files Tonka::HTML.new(@options).render(@options) end |
#parse_options(options = []) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/tonka.rb', line 50 def (=[]) @action = @options[0] case @action when "-v" puts @version when "build" #handles the 'build' command $SITE_NAME = @options[1] || 'sites' jquery = true if @options[2] == '-jquery' css_reset = true if @options[2] == '-jquery' make_directories make_files puts "\n\t\tthe construction of "+"#{$SITE_NAME}".green+" is now complete!" when "destroy" #handles the 'destroy' command $SITE_NAME = @options[1] || 'sites' if Dir.exist? $SITE_NAME system("rm -rf #{$SITE_NAME}") puts "\t\tdemolished ".red+"#{$SITE_NAME}" else "Oops! There is no directory called #{$SITE_NAME}!" end when "add" #handles the 'add' command when "serve" port_string = @options[1] || "2000" serve(port_string) else puts "Oops! I don't know that one." display_usage end end |
#serve(port) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/tonka.rb', line 25 def serve(port) puts "Starting server: http://#{Socket.gethostname}:#{port}" server = HTTPServer.new(:Port=>port,:DocumentRoot=>Dir::pwd ) trap("INT"){ server.shutdown } server.start end |