brite 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.ruby +56 -0
  2. data/COPYING.rdoc +30 -0
  3. data/HISTORY.rdoc +16 -2
  4. data/README.rdoc +35 -27
  5. data/bin/brite-server +1 -1
  6. data/lib/brite.rb +2 -1
  7. data/lib/brite.yml +56 -0
  8. data/lib/brite/command.rb +100 -55
  9. data/lib/brite/config.rb +122 -40
  10. data/lib/brite/controller.rb +46 -104
  11. data/lib/brite/layout.rb +27 -13
  12. data/lib/brite/model.rb +107 -0
  13. data/lib/brite/page.rb +229 -0
  14. data/lib/brite/part.rb +88 -0
  15. data/lib/brite/post.rb +41 -0
  16. data/lib/brite/server.rb +88 -93
  17. data/lib/brite/site.rb +150 -0
  18. data/lib/brite/version.rb +21 -0
  19. data/test/fixture/brite.yml +3 -0
  20. data/test/fixture/example-page.page +8 -0
  21. data/test/fixture/example-post.post +9 -0
  22. data/test/helper.rb +5 -0
  23. data/test/test_config.rb +23 -0
  24. data/test/test_page.rb +28 -0
  25. data/test/test_site.rb +37 -0
  26. metadata +104 -109
  27. data/LICENSE +0 -205
  28. data/Syckfile +0 -76
  29. data/lib/brite/meta/data.rb +0 -26
  30. data/lib/brite/meta/package +0 -8
  31. data/lib/brite/meta/profile +0 -19
  32. data/lib/brite/models/model.rb +0 -97
  33. data/lib/brite/models/page.rb +0 -142
  34. data/lib/brite/models/post.rb +0 -9
  35. data/lib/brite/models/site.rb +0 -46
  36. data/lib/brite/rackup.rb +0 -6
  37. data/lib/plugins/sow/brite/awesome/Sowfile +0 -11
  38. data/lib/plugins/sow/brite/awesome/about.page +0 -28
  39. data/lib/plugins/sow/brite/awesome/assets/custom.less +0 -96
  40. data/lib/plugins/sow/brite/awesome/assets/fade.png +0 -0
  41. data/lib/plugins/sow/brite/awesome/assets/highlight.css +0 -96
  42. data/lib/plugins/sow/brite/awesome/assets/highlight.js +0 -1
  43. data/lib/plugins/sow/brite/awesome/assets/jquery.js +0 -19
  44. data/lib/plugins/sow/brite/awesome/assets/jquery.tabs.js +0 -1
  45. data/lib/plugins/sow/brite/awesome/assets/reset.css +0 -57
  46. data/lib/plugins/sow/brite/awesome/assets/ruby.png +0 -0
  47. data/lib/plugins/sow/brite/awesome/brite.yaml +0 -3
  48. data/lib/plugins/sow/brite/awesome/history.page +0 -15
  49. data/lib/plugins/sow/brite/awesome/index.page +0 -18
  50. data/lib/plugins/sow/brite/awesome/legal.page +0 -28
  51. data/lib/plugins/sow/brite/awesome/logs.page +0 -14
  52. data/lib/plugins/sow/brite/awesome/page.layout +0 -75
  53. data/lib/plugins/sow/brite/blog1/.rsync-filter +0 -12
  54. data/lib/plugins/sow/brite/blog1/2011/01/sample.html +0 -293
  55. data/lib/plugins/sow/brite/blog1/2011/01/sample.post +0 -44
  56. data/lib/plugins/sow/brite/blog1/Sowfile +0 -10
  57. data/lib/plugins/sow/brite/blog1/assets/images/bg.jpg +0 -0
  58. data/lib/plugins/sow/brite/blog1/assets/images/icon.jpg +0 -0
  59. data/lib/plugins/sow/brite/blog1/assets/styles/class.css +0 -15
  60. data/lib/plugins/sow/brite/blog1/assets/styles/id.css +0 -85
  61. data/lib/plugins/sow/brite/blog1/assets/styles/misc.css +0 -0
  62. data/lib/plugins/sow/brite/blog1/assets/styles/print.css +0 -76
  63. data/lib/plugins/sow/brite/blog1/assets/styles/reset.css +0 -77
  64. data/lib/plugins/sow/brite/blog1/assets/styles/tag.css +0 -68
  65. data/lib/plugins/sow/brite/blog1/brite.yml +0 -3
  66. data/lib/plugins/sow/brite/blog1/index.page +0 -23
  67. data/lib/plugins/sow/brite/blog1/page.layout +0 -88
  68. data/lib/plugins/sow/brite/blog1/post.layout +0 -25
  69. data/meta/data.rb +0 -26
  70. data/meta/package +0 -8
  71. data/meta/profile +0 -19
@@ -1,144 +1,139 @@
1
1
  require 'fileutils'
2
+ require 'tmpdir'
2
3
  require 'optparse'
4
+
5
+ require 'rack'
3
6
  require 'rack/server'
4
7
  require 'rack/handler'
5
8
  require 'rack/builder'
6
9
  require 'rack/directory'
7
10
  require 'rack/file'
8
11
 
12
+ require 'brite/config'
13
+
9
14
  module Brite
10
15
 
11
16
  # Brite::Server is a Rack-based server useful for testing sites locally.
12
- # not all sites --in fact, most sites, can not be fully previewed via
13
- # static files. A webserver is required to render and navigate a site
14
- # completely. So this light server is provided to facilitate this.
15
- class Server < ::Rack::Server
16
-
17
- class Options
18
- def parse!(args)
19
- args, options = args.dup, {}
20
-
21
- opt_parser = OptionParser.new do |opts|
22
- opts.banner = "Usage: brite-server [options]"
23
-
24
- opts.on("-p", "--port=port", Integer,
25
- "Runs server on the specified port.", "Default: 3000") { |v| options[:Port] = v }
26
-
27
- opts.on("-b", "--binding=ip", String,
28
- "Binds server to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v }
29
-
30
- opts.on("-c", "--config=file", String,
31
- "Use custom rackup configuration file.") { |v| options[:config] = v }
32
-
33
- opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:daemonize] = true }
34
-
35
- opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true }
17
+ # Most sites cannot be fully previewed by loading static files into a browser.
18
+ # Rather, a webserver is required to render and navigate a site completely.
19
+ # So this light server is provided to facilitate this.
20
+ #
21
+ class Server
36
22
 
37
- opts.on("-e", "--environment=name", String,
38
- "Specifies the environment to run this server under (test/development/production).",
39
- "Default: development") { |v| options[:environment] = v }
23
+ # Rack configuration file.
24
+ RACK_FILE = 'brite.ru'
40
25
 
41
- opts.separator ""
26
+ #
27
+ def self.start(argv)
28
+ new(argv).start
29
+ end
42
30
 
43
- opts.on_tail("-h", "--help", "Show this help message.") { puts opts; exit }
44
- end
31
+ # Server options, parsed from command line.
32
+ attr :options
45
33
 
46
- opt_parser.parse!(args)
34
+ # Setup new instance of Brite::Server.
35
+ def initialize(argv)
36
+ @options = ::Rack::Server::Options.new.parse!(argv)
47
37
 
48
- options[:server] = args.shift
38
+ @root = argv.first || Dir.pwd
49
39
 
50
- return options
51
- end
52
- end
40
+ @options[:app] = app
41
+ @options[:pid] = "#{tmp_dir}/pids/server.pid"
53
42
 
54
- #
55
- def initialize(*)
56
- super
57
- set_environment
43
+ @options[:Port] ||= '4444'
58
44
  end
59
45
 
60
- #
61
- def opt_parser
62
- Options.new
63
- end
46
+ # THINK: Should we be using a local tmp directory instead?
47
+ # Then again, why do we need them at all, really?
64
48
 
65
- #
66
- def set_environment
67
- ENV["BRITE_ENV"] ||= options[:environment]
49
+ # Temporary directory used by the rack server.
50
+ def tmp_dir
51
+ @tmp_dir ||= File.join(Dir.tmpdir, 'brite', root)
68
52
  end
69
53
 
70
- #
54
+ # Start the server.
71
55
  def start
72
- puts "=> Booting #{server}"
73
- puts "=> On http://#{options[:Host]}:#{options[:Port]}"
74
- puts "=> Call with -d to detach" unless options[:daemonize]
75
- trap(:INT) { exit }
76
- puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
56
+ ensure_brite_site
77
57
 
78
- #Create required tmp directories if not found
58
+ # create required tmp directories if not found
79
59
  %w(cache pids sessions sockets).each do |dir_to_make|
80
- FileUtils.mkdir_p(File.join('.cache', dir_to_make))
60
+ FileUtils.mkdir_p(File.join(tmp_dir, dir_to_make))
81
61
  end
82
62
 
83
- super
84
- ensure
85
- # The '-h' option calls exit before @options is set.
86
- # If we call 'options' with it unset, we get double help banners.
87
- puts 'Exiting' unless @options && options[:daemonize]
63
+ ::Rack::Server.start(options)
88
64
  end
89
65
 
90
- def middleware
91
- middlewares = []
92
- #middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize]
93
- #middlewares << [Rails::Rack::Debugger] if options[:debugger]
94
- Hash.new(middlewares)
66
+ # Ensure root is a Brite Site.
67
+ def ensure_brite_site
68
+ return true if File.exist?(rack_file)
69
+ return true if config.file
70
+ abort "Not a brite site."
95
71
  end
96
72
 
97
- def log_path
98
- ".cache/brite.log"
73
+ # Load Brite configuration.
74
+ def config
75
+ @config ||= Brite::Config.new(root)
99
76
  end
100
77
 
101
- def default_options
102
- super.merge({
103
- :Port => 3000,
104
- :environment => (ENV['BRITE_ENV'] || "development").dup,
105
- :daemonize => false,
106
- :debugger => false,
107
- :pid => ".cache/pids/server.pid",
108
- :config => nil
109
- })
78
+ # Site root directory.
79
+ def root
80
+ @root
110
81
  end
111
82
 
112
- #
113
- def root
114
- Dir.pwd
83
+ # Configuration file for server.
84
+ def rack_file
85
+ RACK_FILE
115
86
  end
116
87
 
88
+ # If the site has a `brite.ru` file, that will be used to start the server,
89
+ # otherwise a standard Rack::Directory server ise used.
117
90
  def app
118
- @app ||= begin
119
- config_file = options[:config]
120
- if config_file && ::File.exist?(config_file)
121
- app, options = Rack::Builder.parse_file(config_file, opt_parser)
122
- self.options.merge!(options)
91
+ @app ||= (
92
+ if ::File.exist?(rack_file)
93
+ app, options = Rack::Builder.parse_file(rack_file, opt_parser)
94
+ @options.merge!(options)
123
95
  app
124
96
  else
125
97
  root = self.root
126
- app, options = Rack::Builder.new do
98
+ Rack::Builder.new do
99
+ use Index, root
127
100
  run Rack::Directory.new("#{root}")
128
101
  end
129
- #self.options.merge!(options)
130
- app
102
+ end
103
+ )
104
+ end
105
+
106
+ # Rack middleware to serve `index.html` file by default.
107
+ class Index
108
+ def initialize(app, root)
109
+ @app = app
110
+ @root = root || Dir.pwd
111
+ end
112
+
113
+ def call(env)
114
+ path = Rack::Utils.unescape(env['PATH_INFO'])
115
+ index_file = File.join(@root, path, 'index.html')
116
+ if File.exists?(index_file)
117
+ [200, {'Content-Type' => 'text/html'}, File.new(index_file)]
118
+ else
119
+ @app.call(env) #Rack::Directory.new(@root).call(env)
131
120
  end
132
121
  end
133
122
  end
134
123
 
135
- end
124
+ #
125
+ #def log_path
126
+ # "_brite.log"
127
+ #end
136
128
 
137
- end
129
+ #
130
+ #def middleware
131
+ # middlewares = []
132
+ # #middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize]
133
+ # #middlewares << [Rails::Rack::Debugger] if options[:debugger]
134
+ # Hash.new(middlewares)
135
+ #end
138
136
 
139
- ## The static content rooted in the current working directory
140
- ## Eg. Dir.pwd =&gt; http://0.0.0.0:3000/
141
- #root = Dir.pwd
142
- #puts ">>> Serving: #{root}"
143
- #run Rack::Directory.new("#{root}")
137
+ end
144
138
 
139
+ end
@@ -0,0 +1,150 @@
1
+ require 'brite/model'
2
+ #require 'brite/page'
3
+ #require 'brite/post'
4
+ #require 'brite/part'
5
+
6
+ module Brite
7
+
8
+ # TODO: Limit Neapolitan to Markup formats only ?
9
+
10
+ #
11
+ class Site #< Model
12
+
13
+ # New Site model.
14
+ #
15
+ # @param [String] location
16
+ # The directory of the site's files.
17
+ #
18
+ def initialize(location, options={})
19
+ @location = location
20
+ @config = Config.new(location)
21
+
22
+ options.each do |k,v|
23
+ __send__("#{k}=", v)
24
+ end
25
+
26
+ @pages = []
27
+ @posts = []
28
+ @parts = []
29
+ @layouts = []
30
+
31
+ @tags = nil
32
+ @posts_by_tag = nil
33
+
34
+ load_site
35
+ end
36
+
37
+ #
38
+ attr :location
39
+
40
+ # Access to site configuration.
41
+ attr :config
42
+
43
+ # Returns and Array of Page instances.
44
+ attr :pages
45
+
46
+ # Returns and Array of Post instances.
47
+ attr :posts
48
+
49
+ #
50
+ attr :parts
51
+
52
+ #
53
+ attr :layouts
54
+
55
+ # Returns a String of the site's URL.
56
+ def url
57
+ @url ||= config.url
58
+ end
59
+
60
+ # Change site URL.
61
+ attr_writer :url
62
+
63
+ # Returns an Array of all tags used in all posts.
64
+ def tags
65
+ @tags ||= (
66
+ list = []
67
+ posts.each{ |post| list.concat(post.tags) }
68
+ list.uniq.sort
69
+ )
70
+ end
71
+
72
+ # Returns a Hash posts indexed by tag.
73
+ def posts_by_tag
74
+ @posts_by_tag ||= (
75
+ chart ||= Hash.new{|h,k|h[k]=[]}
76
+ posts.each do |post|
77
+ post.tags.each do |tag|
78
+ chart[tag] << post
79
+ end
80
+ end
81
+ chart
82
+ )
83
+ end
84
+
85
+ #
86
+ def inspect
87
+ "#<Brite::Site @url=#{url.inspect}>"
88
+ end
89
+
90
+ #private
91
+
92
+ def load_site
93
+ Dir.chdir(location) do
94
+ files = Dir['**/*']
95
+ files.each do |file|
96
+ name = File.basename(file)
97
+ ext = File.extname(file)
98
+ case ext
99
+ when '.layout'
100
+ layouts << Layout.new(self, file)
101
+ when '.part'
102
+ parts << Part.new(self, file)
103
+ when '.page' #*%w{.markdown .rdoc .textile .whtml}
104
+ page = Page.new(self, file)
105
+ pages << page unless page.draft
106
+ when '.post'
107
+ post = Post.new(self, file)
108
+ posts << post unless post.draft
109
+ end
110
+ end
111
+ end
112
+
113
+ @posts.sort!{ |a,b| b.date <=> a.date }
114
+ end
115
+
116
+ #
117
+ #def page_defaults
118
+ # { :stencil => config.stencil,
119
+ # :layout => config.layout,
120
+ # :author => config.author
121
+ # }
122
+ #end
123
+
124
+ public
125
+
126
+ #
127
+ # Lookup layout by name.
128
+ #
129
+ def lookup_layout(name)
130
+ layouts.find do |layout|
131
+ config.layout_path.any? { |path|
132
+ File.join(path, name) == layout.name
133
+ } or name == layout.name
134
+ end
135
+ end
136
+
137
+ #
138
+ #
139
+ #
140
+ def lookup_partial(name)
141
+ parts.find do |part|
142
+ config.partial_path.any? { |path|
143
+ File.join(path, name) == part.name
144
+ } or name == part.name
145
+ end
146
+ end
147
+
148
+ end
149
+
150
+ end
@@ -0,0 +1,21 @@
1
+ module Brite
2
+
3
+ # Access to project metadata as given in `brite.yaml` which
4
+ # is soft linked to the `.ruby` project file.
5
+ #
6
+ # @return [Hash] project metadata
7
+ def self.metadata
8
+ @metadata ||= (
9
+ require 'yaml'
10
+ YAML.load(File.dirname(__FILE__) + '/../brite.yml')
11
+ )
12
+ end
13
+
14
+ # If constant is missing, check project metadata.
15
+ #
16
+ # @raise [NameError] uninitialized constant
17
+ def self.const_missing(name)
18
+ metadata[name.to_s.downcase] || super(name)
19
+ end
20
+
21
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ post_slug: "%Y/%M/%D/$name"
3
+
@@ -0,0 +1,8 @@
1
+ ---
2
+ author: trans
3
+
4
+ --- rdoc
5
+
6
+ # Hello World
7
+
8
+ This is an example post.
@@ -0,0 +1,9 @@
1
+ ---
2
+ author: trans
3
+ date : 2011-11-11
4
+
5
+ --- rdoc
6
+
7
+ # Hello World
8
+
9
+ This is an example post.
@@ -0,0 +1,5 @@
1
+ require 'lemon'
2
+ require 'ae'
3
+
4
+ require 'brite'
5
+
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ testcase Brite::Config do
4
+
5
+ method :location do
6
+
7
+ test "config loads given location" do
8
+ config = Brite::Config.new('test/fixture')
9
+ config.assert.location == 'text/fixture'
10
+ end
11
+
12
+ end
13
+
14
+ method :file do
15
+
16
+ test "config find configuraiton file" do
17
+ config = Brite::Config.new('test/fixture')
18
+ config.file.assert == 'test/fixture/brite.yml'
19
+ end
20
+
21
+ end
22
+
23
+ end