moka 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/LICENSE.txt +20 -0
  2. data/Manifest +48 -0
  3. data/README.rdoc +9 -0
  4. data/Rakefile +17 -0
  5. data/bin/moka +21 -0
  6. data/lib/commands.rb +54 -0
  7. data/lib/commands/compile.rb +77 -0
  8. data/lib/commands/delete.rb +47 -0
  9. data/lib/commands/group/delete.rb +59 -0
  10. data/lib/commands/group/group_generator.rb +115 -0
  11. data/lib/commands/group/inspect.rb +40 -0
  12. data/lib/commands/group/new.rb +2 -0
  13. data/lib/commands/group/template/groupdir/variables.yml +1 -0
  14. data/lib/commands/inspect.rb +55 -0
  15. data/lib/commands/lib/compiler.rb +114 -0
  16. data/lib/commands/lib/helpers.rb +156 -0
  17. data/lib/commands/lib/lipsum_constants.rb +159 -0
  18. data/lib/commands/lib/lipsum_helpers.rb +56 -0
  19. data/lib/commands/lib/page_scope.rb +29 -0
  20. data/lib/commands/lib/partials_inclusion.rb +42 -0
  21. data/lib/commands/lib/site_tree.rb +274 -0
  22. data/lib/commands/lib/string_inflectors.rb +13 -0
  23. data/lib/commands/lib/utilities.rb +45 -0
  24. data/lib/commands/new.rb +64 -0
  25. data/lib/commands/order_groups.rb +115 -0
  26. data/lib/commands/order_pages.rb +128 -0
  27. data/lib/commands/page/delete.rb +47 -0
  28. data/lib/commands/page/inspect.rb +35 -0
  29. data/lib/commands/page/new.rb +2 -0
  30. data/lib/commands/page/page_generator.rb +130 -0
  31. data/lib/commands/page/template/pagedir/variables.yml +1 -0
  32. data/lib/commands/server.rb +125 -0
  33. data/lib/commands/site/inspect.rb +28 -0
  34. data/lib/commands/site/new.rb +10 -0
  35. data/lib/commands/site/site_generator.rb +93 -0
  36. data/lib/commands/site/template/manifest.yml +4 -0
  37. data/lib/commands/site/template/project/lib/helpers.rb +1 -0
  38. data/lib/commands/site/template/project/site/content.erb +14 -0
  39. data/lib/commands/site/template/project/site/header.erb +7 -0
  40. data/lib/commands/site/template/project/site/layout.erb +20 -0
  41. data/lib/commands/site/template/project/site/navigation.erb +7 -0
  42. data/lib/commands/site/template/project/site/variables.yml +1 -0
  43. data/lib/commands/site/template/project/styles/style.sass +74 -0
  44. data/lib/commands/site/template/script/config/boot.rb +5 -0
  45. data/lib/commands/site/template/script/moka +4 -0
  46. data/lib/script_moka_loader.rb +14 -0
  47. data/lib/version.rb +10 -0
  48. data/moka.gemspec +39 -0
  49. metadata +182 -0
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env ruby
2
+ require 'getoptlong'
3
+
4
+ module Moka
5
+ class SimpleServer
6
+ require 'webrick'
7
+ require "yaml"
8
+ require File.expand_path('lib/compiler', File.dirname(__FILE__))
9
+ include WEBrick
10
+
11
+ def run(config = {})
12
+ start_webrick(config) do |server|
13
+ compiler = Moka::Compiler.new
14
+ server.mount_proc('/') do |req, resp|
15
+ puts req
16
+ if req.path == "" or req.path[-1] == ?/
17
+ req.path << "index.html"
18
+ end
19
+ manifest = YAML.load_file(File.expand_path("manifest.yml", MOKA_ROOT))
20
+ group_name, page_name = search_page_by_path(req.path.sub("/", ""), manifest)
21
+ if group_name.nil? or page_name.nil?
22
+ if File.extname(req.path) == ".css" and (File.exists?(File.expand_path("project/styles/#{File.basename(req.path, ".css") + ".sass"}", MOKA_ROOT)) or File.exists?(File.expand_path("project/styles/#{File.basename(req.path, ".css") + ".scss"}", MOKA_ROOT)))
23
+ resp.status = 200
24
+ resp["Content-Type"] = get_content_type(req.path)
25
+ resp.body = compiler.compile_style(File.basename(req.path, ".css"))
26
+ elsif File.exist?(File.expand_path("compiled#{req.path}", MOKA_ROOT))
27
+ f = File.new(File.expand_path("compiled#{req.path}", MOKA_ROOT), "r")
28
+ resp.status = 200
29
+ resp["Content-Type"] = get_content_type(req.path)
30
+ resp.body = f.read
31
+ f.close
32
+ else
33
+ resp.status = 404
34
+ resp["Content-Type"] = "text/plain"
35
+ resp.body = "Sorry... it looks like the page you are searching doesn't exist..."
36
+ end
37
+ else
38
+ resp.status = 200
39
+ resp["Content-Type"] = get_content_type(req.path)
40
+ resp.body = compiler.compile(group_name, page_name, manifest)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def start_webrick(config = {})
49
+ # always listen on port 8080 if not explicitly specified
50
+ config.update(:Port => 8080) if config[:Port].nil?
51
+ server = HTTPServer.new(config)
52
+ yield server if block_given?
53
+ ['INT', 'TERM'].each {|signal|
54
+ trap(signal) {server.shutdown}
55
+ }
56
+ server.start
57
+ end
58
+
59
+ def search_page_by_path(path, manifest)
60
+ manifest["site"].each do |group_name, pages|
61
+ if pages.is_a? Hash
62
+ pages.each do |page_name, page_vars|
63
+ if page_vars.is_a?(Hash) and page_vars["path"] == path
64
+ return [group_name, page_name]
65
+ end
66
+ end
67
+ end
68
+ end
69
+ return [nil, nil]
70
+ end
71
+
72
+ def get_content_type(p)
73
+ # some common extensions...
74
+ case File.extname(p)
75
+ when ".css"
76
+ "text/css"
77
+ when ".js"
78
+ "text/javascript"
79
+ when ".xml"
80
+ "text/xml"
81
+ when ".jpeg"
82
+ "image/jpeg"
83
+ when ".jpg"
84
+ "image/jpeg"
85
+ when ".gif"
86
+ "image/gif"
87
+ when ".png"
88
+ "image/png"
89
+ when ".tiff"
90
+ "image/tiff"
91
+ when ".ico"
92
+ "image/x-icon"
93
+ when ".txt"
94
+ "text/plain"
95
+ when ".pdf"
96
+ "application/pdf"
97
+ when ".swf"
98
+ "application/x-shockwave-flash"
99
+ else
100
+ "text/html"
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ opts = GetoptLong.new(
107
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ]
108
+ )
109
+
110
+ opts.each do |opt, arg|
111
+ case opt
112
+ when '--help'
113
+ puts <<-EOT
114
+
115
+ Usage:
116
+
117
+ moka server [port]
118
+
119
+ Start an extremely simple development server on http://localhost:8080/ or on the port specified as the first argument. This server eliminates the need to re-compile pages after each change, but it is only intended for development purpose. Currently, it only serves static HTML pages, and recognizes a limited number of content types.
120
+ EOT
121
+ exit
122
+ end
123
+ end
124
+
125
+ Moka::SimpleServer.new.run({ :Port => (ARGV.size > 0) ? ARGV[0].to_i : 8080 })
@@ -0,0 +1,28 @@
1
+ require "yaml"
2
+ require "fileutils"
3
+ require File.expand_path('../lib/utilities', File.dirname(__FILE__))
4
+ require File.expand_path('../lib/site_tree', File.dirname(__FILE__))
5
+
6
+ include Moka::SiteTree
7
+
8
+ manifest = YAML.load_file(File.expand_path("manifest.yml", MOKA_ROOT))
9
+ @site = SiteNode.new("site", manifest["site"])
10
+
11
+ puts "\nSite #{@site.name}"
12
+ puts "\n Variables:"
13
+ @site.variables.each do |var_name, var_value|
14
+ puts " #{var_name} = #{var_value.inspect}"
15
+ end
16
+
17
+ puts "\n Parameters:"
18
+ @site.params.each do |par_name, par_value|
19
+ puts " #{par_name} = #{par_value.inspect}"
20
+ end
21
+
22
+ puts "\n Groups:"
23
+ @site.groups.each do |group|
24
+ puts " #{group.name}"
25
+ end
26
+
27
+ puts ""
28
+
@@ -0,0 +1,10 @@
1
+ require "script_moka_loader"
2
+
3
+ if Moka::ScriptMokaLoader.in_moka_application?
4
+ puts "ERROR: cannot create a new moka project into an existing one."
5
+ exit
6
+ end
7
+
8
+ require File.expand_path('site_generator', File.dirname(__FILE__))
9
+
10
+ Moka::Generators::MokaSiteGenerator.start
@@ -0,0 +1,93 @@
1
+ require "rubygems"
2
+ require "thor"
3
+ require "thor/group"
4
+
5
+ module Moka
6
+ module Generators
7
+ class MokaSiteGenerator < Thor::Group
8
+ require "yaml"
9
+ require File.expand_path('../lib/utilities', File.dirname(__FILE__))
10
+ require File.expand_path('../lib/site_tree', File.dirname(__FILE__))
11
+
12
+ include Thor::Actions
13
+ include Moka::SiteTree
14
+
15
+ argument :site_name
16
+ class_option :template, :type => :string, :aliases => "-t"
17
+ class_option :vars, :aliases => %w(-v), :type => :hash
18
+
19
+ def self.source_root
20
+ File.expand_path('template/', File.dirname(__FILE__))
21
+ end
22
+
23
+ def create_app_dir
24
+ empty_directory(site_name)
25
+ end
26
+
27
+ def create_script_dir
28
+ directory('script', "#{site_name}/script")
29
+ end
30
+
31
+ def set_permissions
32
+ chmod("#{site_name}/script/moka", 0755)
33
+ end
34
+
35
+ def create_project_dir
36
+ unless options[:template].nil?
37
+ source_paths << "."
38
+ directory(File.join(options[:template], 'project'), "#{site_name}/project")
39
+ else
40
+ directory('project', "#{site_name}/project")
41
+ end
42
+ end
43
+
44
+ def create_compiled_dir
45
+ unless options[:template].nil?
46
+ directory(File.join(options[:template], 'compiled'), "#{site_name}/compiled")
47
+ else
48
+ empty_directory("#{site_name}/compiled")
49
+ empty_directory("#{site_name}/compiled/javascripts")
50
+ empty_directory("#{site_name}/compiled/images")
51
+ empty_directory("#{site_name}/compiled/stylesheets")
52
+ end
53
+ end
54
+
55
+ def create_manifest_file
56
+ unless options[:template].nil?
57
+ template(File.join(options[:template], 'manifest.yml'), File.join("#{site_name}", "manifest.yml"))
58
+ else
59
+ template('manifest.yml', File.join("#{site_name}", "manifest.yml"))
60
+ end
61
+ end
62
+
63
+ def update_variables
64
+ unless options[:vars].nil?
65
+ options[:vars].each do |var_name, var_value|
66
+ if Moka::SiteTree::RESERVED_NAMES.include? var_name.to_s
67
+ say_status "WARNING:", "variable '#{var_name}' is a reserved word, and will not be set as a variable", :yellow
68
+ end
69
+ end
70
+ options[:vars].delete_if {|var_name, var_value| Moka::SiteTree::RESERVED_NAMES.include? var_name.to_s }
71
+ @variables = YAML.load_file(File.join(site_name, "project", "site", "variables.yml"))
72
+ @variables.merge! options[:vars]
73
+ f = File.open( File.join(site_name, "project", "site", "variables.yml"), 'w' ) do |out|
74
+ YAML.dump( @variables, out )
75
+ end
76
+ say_status "update", File.join(site_name, "project", "site", "variables.yml"), :green
77
+ end
78
+ end
79
+
80
+ def update_manifest_file
81
+ unless options[:template].nil?
82
+ @manifest = YAML.load_file(File.join(site_name, "manifest.yml"))
83
+ @manifest['site']['name'] = site_name
84
+ f = File.open( File.join(site_name, "manifest.yml"), 'w' ) do |out|
85
+ YAML.dump( @manifest, out )
86
+ end
87
+ say_status "update", File.join(site_name, "manifest.yml"), :green
88
+ end
89
+ end
90
+
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ site:
3
+ name: <%= site_name %>
4
+ default_extension: html
@@ -0,0 +1 @@
1
+ # Here you can define your own custom helper methods
@@ -0,0 +1,14 @@
1
+ <div class="box">
2
+ <h3>Paragraphs</h3>
3
+ <%= Lipsum.paragraphs 2 %>
4
+ <h3>Quote</h3>
5
+ <blockquote>
6
+ <%= Lipsum.paragraphs 1 %>
7
+ </blockquote>
8
+ <h3>A List</h3>
9
+ <ul>
10
+ <% Lipsum.sentences(8) do |item| %>
11
+ <li><%= item %></li>
12
+ <% end %>
13
+ </ul>
14
+ </div>
@@ -0,0 +1,7 @@
1
+ <div id="logo">
2
+ <h1><a href="#"><%= @site.name.titleize %></a></h1>
3
+ <h2>Welcome aboard Moka. You're gonna love it!</h2>
4
+ </div>
5
+ <div id="nav">
6
+ <%= partial :navigation %>
7
+ </div>
@@ -0,0 +1,20 @@
1
+ <DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= @current_page.respond_to?(:title) ? @current_page.title : @current_page.name.titleize %></title>
5
+ <%= stylesheet_link_tag :all, :media => "screen" %>
6
+ </head>
7
+ <body>
8
+ <div id="wrap">
9
+ <div id="header">
10
+ <%= partial :header %>
11
+ </div>
12
+ <div id="content">
13
+ <%= partial :content %>
14
+ </div>
15
+ <div id="footer">
16
+ Proudly powered by Moka
17
+ </div>
18
+ </div>
19
+ </body>
20
+ </html>
@@ -0,0 +1,7 @@
1
+ <ul>
2
+ <% @current_group.pages.each do |page| %>
3
+ <li>
4
+ <%= link_to(page.respond_to?(:title) ? page.title : page.name.titleize, page, :class => current_page?(page) ? "selected" : "") %>
5
+ </li>
6
+ <% end %>
7
+ </ul>
@@ -0,0 +1,74 @@
1
+ body
2
+ font-family: Helvetica, Arial, sans-serif
3
+ font-size: 13px
4
+ background-color: #eee
5
+ padding: 0.5em
6
+
7
+ #wrap
8
+ margin: 0 auto
9
+ width: 960px
10
+ background-color: #fff
11
+ border: 1px solid #ccc
12
+ padding: 0
13
+ #header
14
+ background-color: #234
15
+ h1, h2, h3, h4, h5
16
+ color: #abc
17
+ margin: 0
18
+ padding: 0
19
+ font-weight: normal
20
+ h1
21
+ font-size: 2.5em
22
+ h2
23
+ font-size: 2em
24
+ a
25
+ color: #fff
26
+ text-decoration: none
27
+
28
+ #logo
29
+ padding: 2em 3em 1em 3em
30
+
31
+ #nav
32
+ padding: 0 3em
33
+ width: auto
34
+ background-color: #789
35
+ ul
36
+ margin: 0
37
+ padding: 0.5em 0
38
+ list-style: none
39
+ li
40
+ font-size: 1.4em
41
+ font-weight: bold
42
+ display: inline
43
+ a
44
+ margin-right: 0.5em
45
+ color: #cde
46
+ a.selected
47
+ color: #fff
48
+ a:hover
49
+ text-decoration: underline
50
+
51
+ #content
52
+ padding: 0 3em 2em 3em
53
+ margin: 0
54
+ h1, h2, h3, h4, h5
55
+ font-weight: bold
56
+ padding: 0
57
+ margin: 2em 0 0.5em 0
58
+ p
59
+ color: #333
60
+ margin: 0 0 1em 0
61
+ blockquote
62
+ font-style: italic
63
+ margin: 0
64
+ padding: 0 1em
65
+ p
66
+ color: #555
67
+
68
+ #footer
69
+ text-align: center
70
+ color: #999
71
+ background-color: #cde
72
+ border-top: 1px dotted #ccc
73
+ padding: 0.5em 0
74
+ font-size: 10px
@@ -0,0 +1,5 @@
1
+ # sets MOKA_ROOT variable and requires the Moka gem
2
+
3
+ MOKA_ROOT = File.expand_path("../../", File.dirname(__FILE__))
4
+ require "rubygems"
5
+ gem "moka", "0.1.1"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('config/boot', File.dirname(__FILE__))
4
+ require "commands"
@@ -0,0 +1,14 @@
1
+ module Moka
2
+ module ScriptMokaLoader
3
+ RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"]
4
+ SCRIPT_MOKA = File.join('script', 'moka')
5
+
6
+ def self.exec_script_moka!
7
+ exec RUBY, SCRIPT_MOKA, *ARGV if in_moka_application?
8
+ end
9
+
10
+ def self.in_moka_application?
11
+ File.exists?("manifest.yml")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module Moka
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 1
6
+ BUILD = "alpha"
7
+
8
+ STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{moka}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Luca Ongaro"]
9
+ s.date = %q{2010-11-16}
10
+ s.default_executable = %q{moka}
11
+ s.description = %q{Moka is a damn simple framework designed to build static websites like portfolios, showcases, minisites, HTML mockups, etc. Moka setup takes a single command, and it provides a hierarchical template system and some hyper-convenient helper functions so you never have to write more code than necessary. The result of your work is compiled to plain HTML, CSS and Javascript, so you just have to upload it to your server. Plus, don't forget the Lipsum helper functions to generate dummy text with a single line of code during development or in HTML mockups.}
12
+ s.email = %q{mail@lucaongaro.eu}
13
+ s.executables = ["moka"]
14
+ s.extra_rdoc_files = ["LICENSE.txt", "README.rdoc", "bin/moka", "lib/commands.rb", "lib/commands/compile.rb", "lib/commands/delete.rb", "lib/commands/group/delete.rb", "lib/commands/group/group_generator.rb", "lib/commands/group/inspect.rb", "lib/commands/group/new.rb", "lib/commands/group/template/groupdir/variables.yml", "lib/commands/inspect.rb", "lib/commands/lib/compiler.rb", "lib/commands/lib/helpers.rb", "lib/commands/lib/lipsum_constants.rb", "lib/commands/lib/lipsum_helpers.rb", "lib/commands/lib/page_scope.rb", "lib/commands/lib/partials_inclusion.rb", "lib/commands/lib/site_tree.rb", "lib/commands/lib/string_inflectors.rb", "lib/commands/lib/utilities.rb", "lib/commands/new.rb", "lib/commands/order_groups.rb", "lib/commands/order_pages.rb", "lib/commands/page/delete.rb", "lib/commands/page/inspect.rb", "lib/commands/page/new.rb", "lib/commands/page/page_generator.rb", "lib/commands/page/template/pagedir/variables.yml", "lib/commands/server.rb", "lib/commands/site/inspect.rb", "lib/commands/site/new.rb", "lib/commands/site/site_generator.rb", "lib/commands/site/template/manifest.yml", "lib/commands/site/template/project/lib/helpers.rb", "lib/commands/site/template/project/site/content.erb", "lib/commands/site/template/project/site/header.erb", "lib/commands/site/template/project/site/layout.erb", "lib/commands/site/template/project/site/navigation.erb", "lib/commands/site/template/project/site/variables.yml", "lib/commands/site/template/project/styles/style.sass", "lib/commands/site/template/script/config/boot.rb", "lib/commands/site/template/script/moka", "lib/script_moka_loader.rb", "lib/version.rb"]
15
+ s.files = ["LICENSE.txt", "Manifest", "README.rdoc", "Rakefile", "bin/moka", "lib/commands.rb", "lib/commands/compile.rb", "lib/commands/delete.rb", "lib/commands/group/delete.rb", "lib/commands/group/group_generator.rb", "lib/commands/group/inspect.rb", "lib/commands/group/new.rb", "lib/commands/group/template/groupdir/variables.yml", "lib/commands/inspect.rb", "lib/commands/lib/compiler.rb", "lib/commands/lib/helpers.rb", "lib/commands/lib/lipsum_constants.rb", "lib/commands/lib/lipsum_helpers.rb", "lib/commands/lib/page_scope.rb", "lib/commands/lib/partials_inclusion.rb", "lib/commands/lib/site_tree.rb", "lib/commands/lib/string_inflectors.rb", "lib/commands/lib/utilities.rb", "lib/commands/new.rb", "lib/commands/order_groups.rb", "lib/commands/order_pages.rb", "lib/commands/page/delete.rb", "lib/commands/page/inspect.rb", "lib/commands/page/new.rb", "lib/commands/page/page_generator.rb", "lib/commands/page/template/pagedir/variables.yml", "lib/commands/server.rb", "lib/commands/site/inspect.rb", "lib/commands/site/new.rb", "lib/commands/site/site_generator.rb", "lib/commands/site/template/manifest.yml", "lib/commands/site/template/project/lib/helpers.rb", "lib/commands/site/template/project/site/content.erb", "lib/commands/site/template/project/site/header.erb", "lib/commands/site/template/project/site/layout.erb", "lib/commands/site/template/project/site/navigation.erb", "lib/commands/site/template/project/site/variables.yml", "lib/commands/site/template/project/styles/style.sass", "lib/commands/site/template/script/config/boot.rb", "lib/commands/site/template/script/moka", "lib/script_moka_loader.rb", "lib/version.rb", "moka.gemspec"]
16
+ s.homepage = %q{https://github.com/DukeLeNoir/Moka}
17
+ s.post_install_message = %q{Welcome aboard Moka. You'll love it!}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Moka", "--main", "README.rdoc"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{moka}
21
+ s.rubygems_version = %q{1.3.6}
22
+ s.summary = %q{An damn simple static website framework.}
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 3
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_runtime_dependency(%q<thor>, [">= 0"])
30
+ s.add_runtime_dependency(%q<haml>, [">= 0"])
31
+ else
32
+ s.add_dependency(%q<thor>, [">= 0"])
33
+ s.add_dependency(%q<haml>, [">= 0"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<thor>, [">= 0"])
37
+ s.add_dependency(%q<haml>, [">= 0"])
38
+ end
39
+ end