broadway 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -297,4 +297,10 @@ Post objects are built out of the path to the file
297
297
 
298
298
  h3. Posts from XML
299
299
 
300
- Post objects are built out of everything in the XML. If the XML node is referencing a file outside of itself, then it falls into the first category.
300
+ Post objects are built out of everything in the XML. If the XML node is referencing a file outside of itself, then it falls into the first category.
301
+
302
+ h3. Graphics
303
+
304
+ http://www.iconarchive.com/show/mac-icons-by-artua/Microphone-icon.html
305
+ http://www.iconarchive.com/show/vista-multimedia-icons-by-icons-land/Microphone-Disabled-icon.html
306
+ http://www.iconarchive.com/show/play-stop-pause-icons-by-icons-land/Microphone-Disabled-icon.html
data/lib/broadway/base.rb CHANGED
@@ -7,74 +7,76 @@ def require_local(path, from = __FILE__)
7
7
  end
8
8
 
9
9
  require "rubygems"
10
- require 'redcloth'
11
- require 'nokogiri'
12
- require 'active_support'
13
- require 'action_mailer'
14
- require 'action_view'
15
- require 'action_view/base'
10
+ require "redcloth"
11
+ require "nokogiri"
12
+ require "active_support"
13
+ require "action_mailer"
14
+ require "action_view"
15
+ require "action_view/base"
16
16
 
17
17
  # core
18
- require 'fileutils'
19
- require 'time'
20
- require 'yaml'
21
- require 'nokogiri'
22
- require 'cgi'
23
- require 'sinatra'
24
- require 'sinatra/base'
25
- require 'sinatra_more'
26
- require 'haml'
18
+ require "fileutils"
19
+ require "time"
20
+ require "yaml"
21
+ require "nokogiri"
22
+ require "cgi"
23
+ require "sinatra"
24
+ require "sinatra/base"
25
+ require "sinatra_more"
26
+ require "haml"
27
27
 
28
28
  # stdlib
29
29
 
30
30
  # 3rd party
31
- require 'redcloth'
31
+ require "redcloth"
32
32
 
33
33
  $:.push(File.dirname(__FILE__))
34
- require 'core_ext'
35
- require 'convertible'
36
- require 'resource'
37
- require 'site'
38
- require 'asset'
39
- require 'page'
40
- require 'post'
41
- require 'static_file'
42
- require 'runner'
34
+ require "core_ext"
35
+ require "convertible"
36
+ require "resource"
37
+ require "site"
38
+ require "asset"
39
+ require "page"
40
+ require "post"
41
+ require "static_file"
42
+ require "runner"
43
43
  require "helpers"
44
44
 
45
45
  module Broadway
46
- VERSION = "0.0.1"
46
+ VERSION = "0.0.2"
47
47
  # Default options. Overriden by values in _config.yml or command-line opts.
48
48
  # (Strings rather symbols used for compatability with YAML)
49
49
  DEFAULTS = {
50
- :auto => false,
51
- :server => false,
52
- :server_port => 4000,
53
-
54
- :source => '.',
55
- :destination => File.join('..', '_posts'),
56
-
57
- :lsi => false,
58
- :pygments => false,
59
- :markdown => 'maruku',
60
- :permalink => 'pretty',
61
- :url_type => 'relative',
62
- :url => 'http://localhost:4567',
63
- :language => 'en-US',
50
+ :auto => false,
51
+ :server => false,
52
+ :server_port => 4000,
53
+
54
+ :source => ".",
55
+ :destination => "_site",
64
56
 
65
- :maruku => {
66
- :use_tex => false,
67
- :use_divs => false,
68
- :png_engine => 'blahtex',
69
- :png_dir => 'images/latex',
70
- :png_url => '/images/latex'
57
+ :lsi => false,
58
+ :pygments => false,
59
+ :markdown => "maruku",
60
+ :permalink => "pretty",
61
+ :url_type => "relative",
62
+ :url => "http://localhost:4567",
63
+ :locales => "locales",
64
+ :language => "en-US",
65
+
66
+ :maruku => {
67
+ :use_tex => false,
68
+ :use_divs => false,
69
+ :png_engine => "blahtex",
70
+ :png_dir => "images/latex",
71
+ :png_url => "/images/latex"
71
72
  },
72
73
 
73
- :layouts => "_layouts",
74
- :posts => "",#"_posts"
75
- :posts_include => [".textile", ".markdown"]
74
+ :layouts => "_layouts",
75
+ :posts_include => [".textile", ".markdown"],
76
+ :theme_path => "themes",
77
+ :theme_versions => ["main"]
76
78
  }
77
-
79
+
78
80
  # Generate a Broadway configuration Hash by merging the default options
79
81
  # with anything in _config.yml, and adding the given options on top
80
82
  # +override+ is a Hash of config directives
@@ -86,7 +88,7 @@ module Broadway
86
88
  source = override[:source] || Broadway::DEFAULTS[:source]
87
89
 
88
90
  # Get configuration from <source>/_config.yml
89
- config_file = File.join(source, '_config.yml')
91
+ config_file = File.join(source, "_config.yml")
90
92
  begin
91
93
  config = YAML.load_file(config_file)
92
94
  raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash)
@@ -100,7 +102,7 @@ module Broadway
100
102
  # Merge DEFAULTS < _config.yml < override
101
103
  Broadway::DEFAULTS.deep_merge(config).deep_merge(override)
102
104
  end
103
-
105
+
104
106
  def self.build(options = {})
105
107
  self.process(:build, options)
106
108
  end
@@ -22,10 +22,16 @@ module Broadway
22
22
  end
23
23
 
24
24
  def theme_partial(template, options = {})
25
- partial(File.join(c(:theme_path), template.to_s), options)
25
+ theme = File.join(c(:theme_path), c(:theme))
26
+ version = nil
27
+ if options.has_key?(:locals) and options[:locals].has_key?(:theme_version)
28
+ version = options[:locals][:theme_version]
29
+ else
30
+ version = "main"
31
+ end
32
+ partial(File.join(theme, version, template.to_s), options)
26
33
  end
27
34
 
28
35
  end
29
36
  end
30
37
  end
31
-
data/lib/broadway/main.rb CHANGED
@@ -15,11 +15,28 @@ def site
15
15
  end
16
16
 
17
17
  def default_locals(locals = {})
18
- locals#.merge(site.config.dup).merge({:menu => menu})
18
+ {
19
+ :environment => Sinatra::Application.environment,
20
+ :theme_version => "main"
21
+ }.merge(locals)
19
22
  end
20
23
 
21
- def theme_path
22
- site.config[:theme_path]
24
+ def default_options(options = {})
25
+ if params.has_key?("layout") and params["layout"] == false
26
+ options[:layout] = false
27
+ else
28
+ options[:layout] = !request.xhr?
29
+ end
30
+ options
31
+ end
32
+
33
+ def theme_path(version = "main")
34
+ File.join(site.config[:theme_path], site.config[:theme], version)
35
+ end
36
+
37
+ # "main" is the default, so remove it
38
+ def theme_versions
39
+ site.config[:theme_versions]
23
40
  end
24
41
 
25
42
  def pages
@@ -31,15 +48,22 @@ Sinatra::Application.class_eval do
31
48
  register SinatraMore::RoutingPlugin
32
49
  end
33
50
 
34
- def page_path(page)
35
- content_path(page, "index")
51
+ def page_path(page, version)
52
+ content_path(page, version, "index")
53
+ end
54
+
55
+ def post_path(post, version)
56
+ content_path(post, version, "show")
36
57
  end
37
58
 
38
- def post_path(post)
39
- content_path(post, "show")
59
+ def c(path)
60
+ result = site.config
61
+ path.to_s.split(".").each { |node| result = result[node.to_sym] if result }
62
+ result.nil? ? [] : result
40
63
  end
41
64
 
42
- def content_path(content, action)
65
+ def content_path(content, version, action)
66
+ # first check if it's in the posts directory (where textile files are)
43
67
  path = File.join(content.dir, action).squeeze("/")
44
68
  exists = false
45
69
  extensions = %w(html haml erb html.haml html.erb)
@@ -48,17 +72,17 @@ def content_path(content, action)
48
72
  exists = true if File.exists?("#{target_path}.#{ext}")
49
73
  end
50
74
  return path if exists
75
+ # then check if it's in the theme directory
51
76
  checked = [target_path]
52
- path = target_path = File.join(site.config[:theme_path], path).squeeze("/")
77
+ path = target_path = File.join(theme_path(version), content.layout, action).squeeze("/")
53
78
  exists = false
54
79
  extensions.each do |ext|
55
80
  exists = true if File.exists?(File.join(site.config[:source], "#{target_path}.#{ext}"))
56
81
  end
57
82
  return path if exists
58
- if content.url == "/"
59
- return File.join(site.config[:theme_path], "index")
60
- end
83
+ return File.join(theme_path(version), "index") if content.url == "/"
61
84
  checked << target_path
62
- puts "Couldn't find paths for #{content.class.to_s.downcase.split(":").last} ('#{content.url}'): #{checked.inspect}"
85
+
86
+ puts "Couldn't find any paths for #{content.class.to_s.downcase.split(":").last} '#{content.url}': #{checked.inspect}"
63
87
  return nil
64
88
  end
data/lib/broadway/page.rb CHANGED
@@ -3,7 +3,7 @@ module Broadway
3
3
  class Page
4
4
  include Convertible
5
5
 
6
- attr_accessor :site
6
+ attr_accessor :site, :position # order
7
7
  attr_accessor :name, :ext, :basename, :dir, :path, :slug
8
8
  attr_accessor :data, :content, :output, :categories, :tags, :children
9
9
 
@@ -50,17 +50,29 @@ module Broadway
50
50
  end
51
51
 
52
52
  def show_children?
53
- self.data && (!self.data.has_key?("show_children") || self.data["show_children"] == true)
53
+ return true if self.data.nil?
54
+ if self.data.has_key?("show_children")
55
+ return self.data["show_children"] == "true" || self.data["show_children"] == true
56
+ end
57
+ return true
54
58
  end
55
59
 
56
60
  def title
57
61
  self.data && (self.data['title'] || self.name)
58
62
  end
59
63
 
64
+ def excerpt
65
+ self.data && self.data['excerpt']
66
+ end
67
+
60
68
  def parent
61
69
  url ? site.find_page_by_url(url[1..-1].split("/").first) : nil
62
70
  end
63
71
 
72
+ def layout
73
+ self.data and self.data.has_key?("layout") ? self.data["layout"] : self.categories.first
74
+ end
75
+
64
76
  # The generated relative url of this page
65
77
  # e.g. /about
66
78
  #
@@ -83,6 +95,10 @@ module Broadway
83
95
  end
84
96
  end
85
97
 
98
+ def <=>(other)
99
+ return self.position <=> other.position
100
+ end
101
+
86
102
  # Extract information from the page filename
87
103
  # +name+ is the String filename of the page file
88
104
  #
data/lib/broadway/post.rb CHANGED
@@ -19,7 +19,7 @@ module Broadway
19
19
  attr_accessor :site
20
20
  # where the file is
21
21
  attr_accessor :path, :dir, :name, :basename, :ext
22
- attr_accessor :data, :content, :output
22
+ attr_accessor :data, :content, :output, :position # order
23
23
  attr_accessor :date, :slug, :published, :tags, :categories, :asset
24
24
 
25
25
  # Initialize this Post instance.
@@ -76,7 +76,11 @@ module Broadway
76
76
  #
77
77
  # Returns -1, 0, 1
78
78
  def <=>(other)
79
- return self.url <=> other.url
79
+ if self.date and other.date
80
+ self.date <=> other.date
81
+ else
82
+ self.position <=> other.position
83
+ end
80
84
  end
81
85
 
82
86
  # The UID for this post (useful in feeds)
@@ -91,6 +95,10 @@ module Broadway
91
95
  url ? site.find_page_by_url(url[1..-1].split("/").first) : nil
92
96
  end
93
97
 
98
+ def layout
99
+ self.data and self.data.has_key?("layout") ? self.data["layout"] : self.categories.first
100
+ end
101
+
94
102
  # The full path and filename of the post.
95
103
  # Defined in the YAML of the post body
96
104
  # (Optional)
@@ -11,27 +11,43 @@ module Broadway
11
11
  end
12
12
 
13
13
  def run(&block)
14
- begin
15
- Net::HTTP.start(url.host, url.port) do |http|
16
- self.content.each do |item|
17
- response = http.get(item.url)
18
- # if the file doesn't exist or is not rendered correctly
19
- next if error?(response, item.url, false)
20
- write_dir = File.expand_path(File.join(site.config[:destination], item.dir))
21
- name = File.join(write_dir, "index.html")
22
- FileUtils.mkdir_p(write_dir)
23
- text = ""
24
- text << "---\n"
25
- text << "categories: #{item.categories.sort.join(" ")}\n"
26
- text << "---\n"
27
- text << response.body
28
- yield text if block_given?
29
- File.write(name, text)
14
+ versions = site.config[:theme_versions]
15
+ puts "Connecting to... #{url.scheme}://#{url.host}:#{url.port}"
16
+ item_url = nil
17
+ versions.each do |version|
18
+ prefix = version == "main" ? "" : version
19
+ begin
20
+ Net::HTTP.start(url.host, url.port) do |http|
21
+ self.content.each do |item|
22
+ if block_given?
23
+ item_url = yield(item)
24
+ else
25
+ if prefix == "touch"
26
+ item_url = "/touch#{item.url.gsub(".", "")}?layout=false"
27
+ else
28
+ item_url = ("/" + File.join(prefix, item.url.gsub(".", ""))).squeeze("/")
29
+ end
30
+ end
31
+ puts "Connecting to... #{url.scheme}://#{url.host}:#{url.port}#{item_url}"
32
+ item_dir = File.expand_path(File.join(site.config[:destination], prefix, item.url).squeeze("/"))
33
+ response = http.get(item_url)
34
+ # if the file doesn't exist or is not rendered correctly
35
+ next if error?(response, item_url, false)
36
+ FileUtils.mkdir_p(item_dir)
37
+ name = File.join(item_dir, "index.html").squeeze("/")
38
+ text = ""
39
+ # text << "---\n"
40
+ # text << "categories: #{item.categories.sort.join(" ")}\n"
41
+ # text << "---\n"
42
+ text << response.body
43
+ puts "Writing... #{name}"
44
+ File.open(name, "w") {|f| f.write(text) }
45
+ end
30
46
  end
47
+ rescue Exception => e
48
+ puts e.inspect
49
+ raise "Make sure you've started the server, run: 'ruby app.rb'"
31
50
  end
32
- rescue Exception => e
33
- puts e.inspect
34
- raise "Make sure you've started the server, run: 'ruby app.rb'"
35
51
  end
36
52
  end
37
53
 
data/lib/broadway/site.rb CHANGED
@@ -32,10 +32,10 @@ module Broadway
32
32
  end
33
33
 
34
34
  def merge_extra_config!(config)
35
- locale = File.join("locales", "#{config[:language]}.yml")
36
- if File.exists?(locale)
37
- config.merge!(YAML.load_file(locale))
38
- end
35
+ locale = File.join(config[:locales], "#{config[:language]}.yml")
36
+
37
+ config.merge!(YAML.load_file(locale)) if File.exists?(locale)
38
+
39
39
  config_dir = "config"
40
40
  return unless File.exists?(config_dir)
41
41
  Dir.glob("#{config_dir}/**/*").each do |file|
@@ -212,12 +212,15 @@ module Broadway
212
212
 
213
213
  # lists are xml files we've collect, but we want to make sure we've
214
214
  # created all the posts we need to beforehand
215
+ # this also sorts everything
215
216
  list = File.join(config[:source], "index.xml")
216
217
  lists << list if File.exists?(list)
217
218
  lists.each do |path|
218
219
  new_tree(path)
219
220
  end
220
221
 
222
+ sort!
223
+
221
224
  # finally, we have set all the initial variables on the
222
225
  # pages and posts we need, now we can process them to find
223
226
  # the content and generate the urls
@@ -254,13 +257,14 @@ module Broadway
254
257
  def parse_tree(parent)
255
258
  result = []
256
259
  return result if parent.nil? || parent.children.nil? || parent.children.empty?
257
- parent.children.each do |child|
260
+ parent.children.each_with_index do |child, index|
258
261
  next unless child.elem?
259
262
  content = child.children.empty? ? post_from_xml(child) : page_from_xml(child)
260
263
  next unless content
261
264
  if content.respond_to?(:children)
262
265
  content.children.concat parse_tree(child)
263
266
  end
267
+ content.position = index
264
268
  result << content
265
269
  end
266
270
  result
@@ -281,7 +285,7 @@ module Broadway
281
285
  path = (content["src"] || content["url"] || "").gsub(/^\//, "")
282
286
  post ||= new_post(path)
283
287
  return unless post
284
- %w(title image excerpt menu_title tooltip show_children content).each do |key|
288
+ %w(title image excerpt menu_title tooltip show_children content layout).each do |key|
285
289
  post.data[key] = content[key] if content.has_attribute?(key)
286
290
  end
287
291
  post
@@ -295,12 +299,29 @@ module Broadway
295
299
  path = (content["src"] || content["url"] || "").gsub(/^\//, "")
296
300
  page ||= new_page(path)
297
301
  return unless page
298
- %w(title image excerpt menu_title tooltip show_children content).each do |key|
302
+ %w(title image excerpt menu_title tooltip show_children content layout).each do |key|
299
303
  page.data[key] = content[key] if content.has_attribute?(key)
300
304
  end
301
305
  page
302
306
  end
303
307
 
308
+ # sort all pages and posts
309
+ # determined by index.xml file (and later, for dates)
310
+ def sort!
311
+ sort_content(:page, self.pages)
312
+ sort_content(:post, self.posts)
313
+ end
314
+
315
+ def sort_content(type, contents)
316
+
317
+ method = type.to_s.pluralize
318
+ unnumbered = self.send(method).select { |content| content.position.nil? }
319
+ start_index = self.send(method).length - unnumbered.length
320
+ unnumbered.each_with_index { |content, index| content.position = start_index + index }
321
+ self.send(method).sort!
322
+ self.send(method)
323
+ end
324
+
304
325
  # While in Jekyll this method renders the content explicitly,
305
326
  # I'm using Sinatra, partly because I like having the flexibility
306
327
  # of using their get/post methods, and partly because I don't have
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Lance Pollard