broadway 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,6 @@ requirements = %w(builders processors mixins resources).map { |dir| Dir["#{this}
15
15
  if defined?(::Sinatra)
16
16
  requirements << Dir["#{this}/sinatra/**/*"]
17
17
  end
18
-
19
18
  requirements.flatten.each { |file| require file if File.extname(file) == ".rb" }
20
19
 
21
20
  module Broadway
@@ -59,6 +58,30 @@ module Broadway
59
58
  site.index_path
60
59
  end
61
60
  end
61
+ # from Rack::Utils
62
+ module Utils
63
+ def unescape(s)
64
+ s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){
65
+ [$1.delete('%')].pack('H*')
66
+ }
67
+ end
68
+
69
+ def parse_query(qs, d = nil)
70
+ params = {}
71
+ (qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
72
+ k, v = p.split('=', 2).map { |x| unescape(x) }
73
+ if cur = params[k]
74
+ if cur.class == Array
75
+ params[k] << v
76
+ else
77
+ params[k] = [cur, v]
78
+ end
79
+ else
80
+ params[k] = v
81
+ end
82
+ end
83
+ end
84
+ end
62
85
  end
63
86
 
64
87
  def Broadway(*args, &block)
@@ -13,10 +13,19 @@ module Broadway
13
13
  unless @assets
14
14
  @assets = []
15
15
  if self.data.has_key?("asset")
16
- @assets << ::Broadway::Asset.new(self, "asset", data["asset"])
16
+ options = data["asset"].is_a?(Hash) ? data["asset"] : {:src => data["asset"]}
17
+ @assets << ::Broadway::Asset.new(self, "asset", options.symbolize_keys)
17
18
  elsif self.data.has_key?("assets")
18
- self.data["assets"].each do |name, asset|
19
- @assets << ::Broadway::Asset.new(self, name, asset)
19
+ if self.data["assets"].is_a?(Array)
20
+ self.data["assets"].each do |asset|
21
+ options = asset.is_a?(Hash) ? asset : {:src => asset}
22
+ @assets << ::Broadway::Asset.new(self, "asset", options.symbolize_keys)
23
+ end
24
+ elsif self.data["assets"].is_a?(Hash)
25
+ self.data["assets"].each do |name, asset|
26
+ options = asset.is_a?(Hash) ? asset : {:src => asset}
27
+ @assets << ::Broadway::Asset.new(self, name, options.symbolize_keys)
28
+ end
20
29
  end
21
30
  end
22
31
  end
@@ -5,7 +5,11 @@ module Broadway
5
5
  end
6
6
 
7
7
  module InstanceMethods
8
- attr_accessor :parent, :children, :show_children
8
+ attr_accessor :parent, :children, :show_children, :categories
9
+
10
+ def categories
11
+ @categories ||= []
12
+ end
9
13
 
10
14
  def show_children
11
15
  unless defined?(@show_children)
@@ -31,22 +35,6 @@ module Broadway
31
35
  @children ||= []
32
36
  @children
33
37
  end
34
-
35
- =begin
36
- def children
37
- unless @children
38
- key = self.categories.last
39
- length = self.path.split("/").length
40
- @children = site.send("find_#{short_name.pluralize}_by_category", key)
41
- @children.delete_if do |child|
42
- (child.path == self.path) ||
43
- (child.path.split("/").length <= length)
44
- end
45
- end
46
-
47
- @children
48
- end
49
- =end
50
38
 
51
39
  def show_children?
52
40
  return true if self.data.blank?
@@ -0,0 +1,32 @@
1
+ module Broadway
2
+ module Linkable
3
+ def self.included(base)
4
+ base.send :include, InstanceMethods
5
+ end
6
+
7
+ module InstanceMethods
8
+ attr_accessor :links
9
+
10
+ def links
11
+ unless @links
12
+ @links = []
13
+ if self.data.has_key?("link")
14
+ options = data["link"].is_a?(Hash) ? data["link"] : {:href => data["link"]}
15
+ @links << ::Broadway::Link.new(self, options.symbolize_keys)
16
+ elsif self.data.has_key?("links")
17
+ self.data["links"].each do |link|
18
+ options = link.is_a?(Hash) ? link : {:href => link}
19
+ @links << ::Broadway::Link.new(self, options.symbolize_keys)
20
+ end
21
+ end
22
+ end
23
+
24
+ @links
25
+ end
26
+
27
+ def link
28
+ links.first
29
+ end
30
+ end
31
+ end
32
+ end
@@ -31,6 +31,11 @@ module Broadway
31
31
  def draft?
32
32
  state == "draft"
33
33
  end
34
+
35
+ def updated_at
36
+ date
37
+ end
38
+ alias created_at updated_at
34
39
  end
35
40
  end
36
41
  end
@@ -35,9 +35,9 @@ module Broadway
35
35
 
36
36
  def initialize(link, site, options = {})
37
37
  link.site = site
38
- link.href = options[:href]
39
- link.title = options[:title]
40
- link.categories = options[:categories]
38
+ link.href = options[:href] unless options[:href].blank?
39
+ link.title = options[:title] unless options[:title].blank?
40
+ link.categories = options[:categories] unless options[:categories].blank?
41
41
  end
42
42
 
43
43
  end
@@ -92,7 +92,7 @@ module Broadway
92
92
  post.kind = "page" if post.file.slug == "index"
93
93
  post.slug = Broadway::Slug.new(post.file.slug, post)
94
94
  post.data = post.file.header
95
- post.title = post.data["title"].blank? ? post.slug.titleize : post.data["title"]
95
+ post.title = (post.data["title"].blank? ? post.slug.titleize : post.data["title"]).to_s
96
96
  if post.title.downcase == "index"
97
97
  post.title = ::File.basename(post.file.directory).titleize
98
98
  end
@@ -12,7 +12,7 @@ module Broadway
12
12
  def initialize(resource, name, options = {})
13
13
  self.resource = resource
14
14
  self.name = name
15
- self.data = options.recursively_symbolize_keys!
15
+ self.data = options
16
16
  self.path = options.delete(:path) || options.delete(:src) || options.delete(:url) || options.delete(:href)
17
17
  options.each do |k,v|
18
18
  self.send("#{k}=", v) if self.respond_to?(k)
@@ -28,5 +28,9 @@ module Broadway
28
28
  def site
29
29
  resource.site
30
30
  end
31
+
32
+ def extension
33
+ ::File.extname(self.path).split(".").last
34
+ end
31
35
  end
32
36
  end
@@ -57,6 +57,7 @@ module Broadway
57
57
  # then, we need to know where to look for _settings.yml
58
58
  source = overrides[:source] || DEFAULTS[:source]
59
59
  settings_file = overrides[:settings] || DEFAULTS[:settings]
60
+ settings_file = ::File.join(source, "_config.yml") unless ::File.exists?(settings_file)
60
61
  # Get configuration from <source>/_config.yml
61
62
  begin
62
63
  settings = YAML.load_file(settings_file).recursively_symbolize_keys!
@@ -4,13 +4,27 @@ module Broadway
4
4
  include Broadway::Processable
5
5
  include Broadway::Convertible
6
6
  include Broadway::Configurable
7
- include Broadway::Resourceful
8
7
  include Broadway::Hierarchical
9
8
  include Broadway::Sortable
10
9
  include Broadway::Taggable
10
+ include Broadway::Resourceful
11
11
 
12
12
  # link category is the menu it's in, or null
13
- attr_accessor :href, :rel, :target, :resource, :categories
13
+ attr_accessor :href, :rel, :target, :resource
14
+
15
+ def href=(value)
16
+ @href = value
17
+ @url = nil
18
+ @href
19
+ end
20
+
21
+ def uri
22
+ @uri ||= Broadway::Uri.new(href)
23
+ end
24
+
25
+ def inspect
26
+ "#<#{self.class.name.to_s} @href='#{self.href.to_s}' @rel='#{self.rel.to_s}' @target='#{self.target.to_s}'/>"
27
+ end
14
28
 
15
29
  end
16
30
  end
@@ -5,6 +5,7 @@ module Broadway
5
5
  include Broadway::Processable
6
6
  include Broadway::Convertible
7
7
  include Broadway::Resourceful
8
+ include Broadway::Hierarchical
8
9
  include Broadway::Readable
9
10
  include Broadway::Configurable
10
11
  include Broadway::Sluggable
@@ -12,8 +13,8 @@ module Broadway
12
13
  include Broadway::Taggable
13
14
  include Broadway::Layoutable
14
15
  include Broadway::Assetable
15
- include Broadway::Hierarchical
16
16
  include Broadway::Publishable
17
+ include Broadway::Linkable
17
18
  include Broadway::Themeable
18
19
 
19
20
  def sluggify
@@ -39,10 +40,7 @@ module Broadway
39
40
  def format
40
41
  extension
41
42
  end
42
- def updated_at
43
- date
44
- end
45
- alias created_at updated_at
43
+
46
44
  def body
47
45
  read
48
46
  end
@@ -99,6 +97,35 @@ module Broadway
99
97
  def parent_path
100
98
  ("/" + categories.join("/")).squeeze("/")
101
99
  end
100
+
101
+ class << self
102
+ def yaml(attributes = nil, &block)
103
+ @yaml = [attributes, block]
104
+ end
105
+
106
+ def to_yaml(record)
107
+ result = "---\n"
108
+ @yaml[0].each do |attribute|
109
+ result << "#{attribute.to_s}: \"#{record.send(attribute)}\"\n"
110
+ end
111
+ result << "\n"
112
+ result << record.instance_eval(&@yaml[1])
113
+ result
114
+ end
115
+
116
+ def from_yaml(content)
117
+ if content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
118
+ self.data = YAML.load($1)
119
+ self.data.each do |k, v|
120
+ if self.respond_to?("#{k}=")
121
+ self[k] = v
122
+ end
123
+ end
124
+ content = content[($1.size + $2.size)..-1]
125
+ end
126
+ self.body = content
127
+ end
128
+ end
102
129
 
103
130
  end
104
131
  end
@@ -0,0 +1,49 @@
1
+ module Broadway
2
+ class Uri
3
+ def initialize(url, query = {})
4
+ unless query.blank?
5
+ url << "?" unless url =~ /\?/
6
+ url << query.map do |k, v|
7
+ url << "#{k}=#{v}"
8
+ end.join("&")
9
+ end
10
+ @uri = URI.parse(url)
11
+ end
12
+
13
+ def url
14
+ @uri.to_s
15
+ end
16
+
17
+ def to_s
18
+ url
19
+ end
20
+
21
+ def path
22
+ uri.path
23
+ end
24
+
25
+ def host
26
+ uri.host
27
+ end
28
+
29
+ def http?
30
+ scheme == "http"
31
+ end
32
+
33
+ def https?
34
+ scheme == "https"
35
+ end
36
+
37
+ def scheme
38
+ uri.scheme
39
+ end
40
+
41
+ def query
42
+ uri.query
43
+ end
44
+
45
+ def query_hash
46
+ @query_hash ||= Broadway::Utils.parse_query(query)
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: broadway
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lance Pollard
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-24 00:00:00 -05:00
18
+ date: 2010-09-07 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -70,6 +70,7 @@ files:
70
70
  - lib/broadway/mixins/convertible.rb
71
71
  - lib/broadway/mixins/hierarchical.rb
72
72
  - lib/broadway/mixins/layoutable.rb
73
+ - lib/broadway/mixins/linkable.rb
73
74
  - lib/broadway/mixins/pageable.rb
74
75
  - lib/broadway/mixins/processable.rb
75
76
  - lib/broadway/mixins/publishable.rb
@@ -91,6 +92,7 @@ files:
91
92
  - lib/broadway/resources/post.rb
92
93
  - lib/broadway/resources/site.rb
93
94
  - lib/broadway/resources/slug.rb
95
+ - lib/broadway/resources/uri.rb
94
96
  - lib/broadway/run.rb
95
97
  - lib/broadway/sinatra/app.rb
96
98
  - lib/broadway/sinatra/helpers/collection_helper.rb