broadway 0.0.3.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/README.markdown +155 -0
  2. data/lib/broadway.rb +64 -4
  3. data/lib/broadway/{core_ext.rb → ext.rb} +40 -6
  4. data/lib/broadway/filters/erb.rb +10 -0
  5. data/lib/broadway/filters/haml.rb +10 -0
  6. data/lib/broadway/filters/liquid.rb +14 -0
  7. data/lib/broadway/filters/markdown.rb +10 -0
  8. data/lib/broadway/filters/textile.rb +11 -0
  9. data/lib/broadway/migrators/blogger.rb +7 -0
  10. data/lib/broadway/migrators/wordpress.rb +7 -0
  11. data/lib/broadway/mixins/assetable.rb +48 -0
  12. data/lib/broadway/mixins/configurable.rb +32 -0
  13. data/lib/broadway/mixins/convertible.rb +25 -0
  14. data/lib/broadway/mixins/hierarchical.rb +61 -0
  15. data/lib/broadway/mixins/layoutable.rb +18 -0
  16. data/lib/broadway/mixins/pageable.rb +5 -0
  17. data/lib/broadway/mixins/processable.rb +44 -0
  18. data/lib/broadway/mixins/publishable.rb +36 -0
  19. data/lib/broadway/mixins/readable.rb +73 -0
  20. data/lib/broadway/mixins/resourceful.rb +27 -0
  21. data/lib/broadway/mixins/sluggable.rb +36 -0
  22. data/lib/broadway/mixins/sortable.rb +24 -0
  23. data/lib/broadway/mixins/taggable.rb +46 -0
  24. data/lib/broadway/mixins/themeable.rb +39 -0
  25. data/lib/broadway/processors/link.rb +45 -0
  26. data/lib/broadway/processors/post.rb +117 -0
  27. data/lib/broadway/processors/site.rb +77 -0
  28. data/lib/broadway/processors/tree.rb +121 -0
  29. data/lib/broadway/resources/asset.rb +28 -0
  30. data/lib/broadway/resources/configuration.rb +114 -0
  31. data/lib/broadway/resources/file.rb +88 -0
  32. data/lib/broadway/resources/layout.rb +28 -0
  33. data/lib/broadway/resources/link.rb +16 -0
  34. data/lib/broadway/resources/post.rb +63 -0
  35. data/lib/broadway/resources/site.rb +164 -0
  36. data/lib/broadway/resources/slug.rb +69 -0
  37. data/lib/broadway/sinatra/app.rb +21 -0
  38. data/lib/broadway/sinatra/helpers/collection_helper.rb +2 -1
  39. data/lib/broadway/sinatra/helpers/partial_helper.rb +5 -5
  40. data/lib/broadway/sinatra/helpers/text_helper.rb +5 -11
  41. data/lib/broadway/sinatra/processor.rb +84 -0
  42. data/lib/broadway/tasks.rb +1 -0
  43. data/lib/broadway/tasks/default.rake +85 -0
  44. metadata +46 -41
  45. data/README.textile +0 -306
  46. data/Rakefile +0 -85
  47. data/lib/broadway/api.rb +0 -51
  48. data/lib/broadway/asset.rb +0 -17
  49. data/lib/broadway/base.rb +0 -120
  50. data/lib/broadway/convertible.rb +0 -91
  51. data/lib/broadway/page.rb +0 -71
  52. data/lib/broadway/post.rb +0 -112
  53. data/lib/broadway/rails.rb +0 -3
  54. data/lib/broadway/resource.rb +0 -128
  55. data/lib/broadway/runner.rb +0 -62
  56. data/lib/broadway/sinatra.rb +0 -5
  57. data/lib/broadway/sinatra/base.rb +0 -90
  58. data/lib/broadway/sinatra/helpers.rb +0 -7
  59. data/lib/broadway/site.rb +0 -421
  60. data/lib/broadway/static_file.rb +0 -32
data/Rakefile DELETED
@@ -1,85 +0,0 @@
1
- require 'rake'
2
- require "rake/rdoctask"
3
- require 'rake/gempackagetask'
4
- require File.join(File.expand_path(File.dirname(__FILE__)), 'lib', 'broadway', 'base')
5
-
6
- def files(path, from = __FILE__, &block)
7
- Dir.glob(File.join(File.dirname(from), path)) {|file| yield file}
8
- end
9
-
10
- APP_ROOT = defined?(RAILS_ROOT) ? RAILS_ROOT : File.dirname(__FILE__)
11
- RAILS_ROOT = File.dirname(__FILE__)
12
-
13
- # http://docs.rubygems.org/read/chapter/20
14
- spec = Gem::Specification.new do |s|
15
- s.name = "broadway"
16
- s.author = "Lance Pollard"
17
- s.version = "0.0.3.5"
18
- s.date = "Mon Mar 22 20:12:47 -0700 2010"
19
- s.summary = "Write Posts in Textile and Markdown, built it into a Rails or Sinatra Blog"
20
- s.homepage = "http://github.com/viatropos/broadway"
21
- s.email = "lancejpollard@gmail.com"
22
- s.description = "Broadway: Static and Dynamic Site Generator"
23
- s.has_rdoc = true
24
- s.rubyforge_project = "broadway"
25
- s.platform = Gem::Platform::RUBY
26
- s.files = %w(README.textile Rakefile) +
27
- Dir["{broadway,lib,spec}/**/*"] -
28
- Dir["spec/tmp"]
29
- s.extra_rdoc_files = %w(README.textile)
30
- s.require_path = "lib"
31
- s.add_dependency("nokogiri")
32
- s.add_dependency("activesupport", ">= 2.3.5")
33
- s.add_dependency("activerecord", ">= 2.3.5")
34
- end
35
-
36
- desc "Create .gemspec file (useful for github)"
37
- task :gemspec do
38
- File.open("#{spec.name}.gemspec", "w") do |f|
39
- f.puts spec.to_ruby
40
- end
41
- end
42
-
43
- desc "Build the gem into the current directory"
44
- task :gem => :gemspec do
45
- `gem build #{spec.name}.gemspec`
46
- end
47
-
48
- desc "Print a list of the files to be put into the gem"
49
- task :manifest => :clean do
50
- File.open("Manifest", "w") do |f|
51
- spec.files.each do |file|
52
- f.puts file
53
- end
54
- end
55
- end
56
-
57
- desc "Publish gem to rubygems"
58
- task :publish => [:package] do
59
- %x[gem push pkg/#{spec.name}-#{spec.version}.gem]
60
- end
61
-
62
- Rake::GemPackageTask.new(spec) do |pkg|
63
- pkg.gem_spec = spec
64
- end
65
-
66
- desc "Install the gem locally"
67
- task :install => [:package] do
68
- sh %{gem install pkg/#{spec.name}-#{spec.version} --no-ri --no-rdoc}
69
- end
70
-
71
- desc "Generate the rdoc"
72
- Rake::RDocTask.new do |rdoc|
73
- files = ["README.textile", "lib/**/*.rb"]
74
- rdoc.rdoc_files.add(files)
75
- rdoc.main = "README.textile"
76
- rdoc.title = "Broadway: A New Way of Googling"
77
- end
78
-
79
- desc "Run the rspec"
80
- task :default => :spec
81
-
82
- desc "Run Broadway Benchmarks"
83
- task :benchmark do
84
- files("spec/benchmarks/*") {|file| system("ruby #{file}") }
85
- end
@@ -1,51 +0,0 @@
1
- module Broadway
2
- module API
3
-
4
- def Post.to_xml(site)
5
- xml = Nokogiri::XML::Builder.new { |xml|
6
- xml.send("posts", :type => "array") {
7
- site.posts.each do |post|
8
- xml.post {
9
- xml.title post.data["title"]
10
- xml.url post.url
11
- xml.categories post.categories.join(",")
12
- xml.date(:type => "date") {
13
- xml.text post.date.to_s
14
- }
15
- xml.slug post.slug
16
- xml.published(:type => "boolean") {
17
- xml.text post.published.to_s
18
- }
19
- xml.tags post.tags.join(",")
20
- }
21
- end
22
- }
23
- }
24
- xml.to_xml
25
- end
26
-
27
- def Page.to_xml(site)
28
- xml = Nokogiri::XML::Builder.new { |xml|
29
- xml.send("pages", :type => "array") {
30
- site.pages.each do |post|
31
- xml.page {
32
- xml.title post.data["title"]
33
- xml.url post.url
34
- xml.categories post.categories.join(",")
35
- xml.date(:type => "date") {
36
- xml.text post.date.to_s
37
- }
38
- xml.slug post.slug
39
- xml.published(:type => "boolean") {
40
- xml.text post.published.to_s
41
- }
42
- xml.tags post.tags.join(",")
43
- }
44
- end
45
- }
46
- }
47
- xml.to_xml
48
- end
49
-
50
- end
51
- end
@@ -1,17 +0,0 @@
1
- module Broadway
2
-
3
- class Asset
4
- attr_accessor :url, :title, :tooltip, :thumb
5
-
6
- def initialize(options = {})
7
- options.each do |k,v|
8
- self.send "#{k}=", v
9
- end
10
- end
11
-
12
- def inspect
13
- "#<Broadway:Asset @url=#{self.url.inspect} @title=#{self.title.inspect}>"
14
- end
15
- end
16
-
17
- end
@@ -1,120 +0,0 @@
1
- def files(path, from = __FILE__, &block)
2
- Dir.glob(File.join(File.dirname(from), path)) {|file| yield file}
3
- end
4
-
5
- def require_local(path, from = __FILE__)
6
- files(path, from) {|file| require file}
7
- end
8
-
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"
16
-
17
- # core
18
- require "fileutils"
19
- require "time"
20
- require "yaml"
21
- require "nokogiri"
22
- require "cgi"
23
-
24
- # stdlib
25
-
26
- # 3rd party
27
- require "redcloth"
28
-
29
- $:.push(File.dirname(__FILE__))
30
- require "core_ext"
31
- require "convertible"
32
- require "resource"
33
- require "site"
34
- require "asset"
35
- require "page"
36
- require "post"
37
- require "static_file"
38
- require "runner"
39
-
40
- module Broadway
41
- VERSION = "0.0.3"
42
- # Default options. Overriden by values in _config.yml or command-line opts.
43
- # (Strings rather symbols used for compatability with YAML)
44
- DEFAULTS = {
45
- :auto => false,
46
- :server => false,
47
- :server_port => 4000,
48
-
49
- :source => ".",
50
- :destination => "_site",
51
-
52
- :lsi => false,
53
- :pygments => false,
54
- :markdown => "maruku",
55
- :permalink => "pretty",
56
- :url_type => "relative",
57
- :url => "http://localhost:4567",
58
- :locales => "locales",
59
- :language => "en-US",
60
-
61
- :maruku => {
62
- :use_tex => false,
63
- :use_divs => false,
64
- :png_engine => "blahtex",
65
- :png_dir => "images/latex",
66
- :png_url => "/images/latex"
67
- },
68
-
69
- :layouts => "_layouts",
70
- :posts_include => [".textile", ".markdown"],
71
- :theme_path => "themes",
72
- :theme_versions => ["main"]
73
- }
74
-
75
- # Generate a Broadway configuration Hash by merging the default options
76
- # with anything in _config.yml, and adding the given options on top
77
- # +override+ is a Hash of config directives
78
- #
79
- # Returns Hash
80
- def self.configuration(override)
81
- # _config.yml may override default source location, but until
82
- # then, we need to know where to look for _config.yml
83
- source = override[:source] || Broadway::DEFAULTS[:source]
84
-
85
- # Get configuration from <source>/_config.yml
86
- config_file = File.join(source, "_config.yml")
87
- begin
88
- config = YAML.load_file(config_file).recursive_symbolize_keys!
89
- raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash)
90
- $stdout.puts "Configuration from #{config_file}"
91
- rescue => err
92
- $stderr.puts "WARNING: Could not read configuration. Using defaults (and options)."
93
- $stderr.puts "\t" + err.to_s
94
- config = {}
95
- end
96
-
97
- # Merge DEFAULTS < _config.yml < override
98
- config = Broadway::DEFAULTS.deep_merge(config).merge(override)
99
-
100
- config
101
- end
102
-
103
- def self.build(options = {})
104
- self.process(:build, options)
105
- end
106
-
107
- def self.generate(options = {})
108
- self.process(:process, options)
109
- end
110
-
111
- def self.process(method, options = {})
112
- options = Broadway.configuration(options)
113
-
114
- site = Broadway::Site.new(options)
115
-
116
- site.send method
117
-
118
- site
119
- end
120
- end
@@ -1,91 +0,0 @@
1
- # Convertible provides methods for converting a pagelike item
2
- # from a certain type of markup into actual content
3
- #
4
- # Requires
5
- # self.site -> Jekyll::Site
6
- # self.content=
7
- # self.data=
8
- # self.ext=
9
- # self.output=
10
- require 'liquid'
11
- module Broadway
12
- module Convertible
13
- # Return the contents as a string
14
- def to_s
15
- self.content || ''
16
- end
17
-
18
- def read(attribute = nil)
19
- self.content = IO.read(self.path)
20
- if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
21
- if attribute
22
- output = YAML.load($1)[attribute] || ""
23
- return output
24
- end
25
- self.content = self.content[($1.size + $2.size)..-1]
26
- end
27
- result = self.render(site.layouts, site.site_payload)
28
- self.content = self.output = nil
29
- result
30
- end
31
-
32
- # Read the YAML frontmatter
33
- # +base+ is the String path to the dir containing the file
34
- # +name+ is the String filename of the file
35
- # You can also get the content from xml, so this might not need to run
36
- # Returns nothing
37
- def read_yaml(path)
38
- return if !File.exists?(path) || File.directory?(path)
39
-
40
- self.content = IO.read(path)
41
-
42
- if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
43
- self.content = self.content[($1.size + $2.size)..-1]
44
-
45
- self.data.merge!(YAML.load($1))
46
- end
47
-
48
- self.data ||= {}
49
- end
50
-
51
- # Transform the contents based on the file extension.
52
- #
53
- # Returns nothing
54
- def transform
55
- case self.content_type
56
- when 'textile'
57
- self.ext = ".html"
58
- self.content = self.site.textile(self.content)
59
- when 'markdown'
60
- self.ext = ".html"
61
- self.content = self.site.markdown(self.content)
62
- end
63
- end
64
-
65
- # Determine which formatting engine to use based on this convertible's
66
- # extension
67
- #
68
- # Returns one of :textile, :markdown or :unknown
69
- def content_type
70
- case self.ext[1..-1]
71
- when /textile/i
72
- return 'textile'
73
- when /markdown/i, /mkdn/i, /md/i, /mkd/i
74
- return 'markdown'
75
- end
76
- return 'unknown'
77
- end
78
-
79
- # Add any necessary layouts to this convertible document
80
- # +layouts+ is a Hash of {"name" => "layout"}
81
- # +site_payload+ is the site payload hash
82
- #
83
- # Returns nothing
84
- def do_layout(payload, layouts)
85
- info = { :filters => [], :registers => { :site => self.site } }
86
- # render and transform content (this becomes the final content of the object)
87
- payload["content_type"] = self.content_type
88
- self.output = Liquid::Template.parse(self.content).render(payload, info)
89
- end
90
- end
91
- end
@@ -1,71 +0,0 @@
1
- module Broadway
2
-
3
- class Page
4
- include Comparable
5
- include Convertible
6
- include Resource
7
-
8
- # Initialize a new Page.
9
- # +site+ is the Site
10
- # +base+ is the String path to the <source>
11
- # +dir+ is the String path between <source> and the file
12
- # +name+ is the String filename of the file
13
- #
14
- # Returns <Page>
15
- def initialize(options = {})
16
- self.site = options[:site]
17
- self.path = options[:path] if options.has_key?(:path)
18
- self.data = {}
19
- self.dir = path =~ /\// ? File.dirname(path.gsub(/#{site.config[:source]}\/?/, "")).gsub(/^\//, "") : path
20
- self.slug = self.dir == "." ? "" : File.basename(self.dir)
21
- self.ext = File.extname(path)
22
- self.basename = File.basename(path).split('.')[0..-2].first
23
-
24
- self.categories ||= []
25
- self.categories.concat self.dir.split('/').reject { |x| x.empty? }
26
- self.children ||= []
27
- process(options) unless options.has_key?(:process) and options[:process] == false
28
- end
29
-
30
- # The generated relative url of this page
31
- # e.g. /about
32
- #
33
- # Returns <String>
34
- def url
35
- return permalink if permalink
36
- @url ||= {
37
- "slug" => CGI.escape(slug),
38
- "categories" => categories[0..-2].join('/')
39
- }.inject(template) { |result, token|
40
- result.gsub(/:#{token.first}/, token.last)
41
- }.gsub(/#{site.config[:posts]}/, "").squeeze("/")
42
- end
43
-
44
- def template
45
- if self.site.permalink_style == :pretty
46
- "/:categories/:slug"
47
- else
48
- "/:categories/:slug.html"
49
- end
50
- end
51
-
52
- def <=>(other)
53
- return self.position <=> other.position
54
- end
55
-
56
- # Add any necessary layouts to this post
57
- # +layouts+ is a Hash of {"slug" => "layout"}
58
- # +site_payload+ is the site payload hash
59
- #
60
- # Returns nothing
61
- def render(layouts, site_payload)
62
- payload = {"page" => self.data, "site" => {}}.deep_merge(site_payload)
63
- do_layout(payload, layouts)
64
- end
65
-
66
- def inspect
67
- "#<Broadway:Page @url=#{self.url.inspect} @slug=#{self.slug.inspect} @categories=#{self.categories.inspect} @tags=#{self.tags.inspect} @data=#{self.data.inspect}>"
68
- end
69
- end
70
-
71
- end
@@ -1,112 +0,0 @@
1
- module Broadway
2
-
3
- class Post
4
- include Comparable
5
- include Convertible
6
- include Resource
7
-
8
- SRC_MATCHER = /^(.+\/)*(?:(\d+-\d+-\d+)-)?(.*)(\.[^.]+)$/
9
- URL_MATCHER = /^(.+\/)*(.*)$/
10
-
11
- # Post name validator. Post filenames must be like:
12
- # 2008-11-05-my-awesome-post.textile
13
- #
14
- # Returns <Bool>
15
- def self.valid?(name, site)
16
- site.config[:posts_include].include?(File.extname(name))
17
- end
18
-
19
- # Initialize this Post instance.
20
- # +site+ is the Site
21
- # +base+ is the String path to the dir containing the post file
22
- # +name+ is the String filename of the post file
23
- # +categories+ is an Array of Strings for the categories for this post
24
- #
25
- # Returns <Post>
26
- def initialize(options = {})
27
- self.site = options[:site]
28
- self.path = options[:path] if options.has_key?(:path)
29
- self.data = {}
30
-
31
- n, cats, date, slug, ext = *path.match(SRC_MATCHER)
32
- n, cats, slug = *path.match(URL_MATCHER) unless slug
33
- self.date = Time.parse(date) if date
34
- self.slug = slug
35
- self.ext = ext
36
- self.dir = options.has_key?(:dir) ? options[:dir] : File.dirname(path.gsub(/#{site.config[:source]}\/?/, ""))
37
- base = self.dir == "." ? "" : self.dir
38
- self.categories = base.split('/').reject { |x| x.empty? }
39
-
40
- process(options)
41
- end
42
-
43
- # Spaceship is based on Post#date, slug
44
- #
45
- # Returns -1, 0, 1
46
- def <=>(other)
47
- if self.date and other.date
48
- self.date <=> other.date
49
- else
50
- self.position <=> other.position
51
- end
52
- end
53
-
54
- def template
55
- case self.site.permalink_style
56
- when :pretty
57
- "/:categories/:year/:month/:day/:title"
58
- when :none
59
- "/:categories/:title.html"
60
- when :date
61
- "/:categories/:year/:month/:day/:title.html"
62
- else
63
- self.site.permalink_style.to_s
64
- end
65
- end
66
-
67
- # The generated relative url of this post
68
- # e.g. /2008/11/05/my-awesome-post.html
69
- #
70
- # Returns <String>
71
- def url
72
- return permalink if permalink
73
- @url ||= {
74
- "year" => date ? date.strftime("%Y") : "",
75
- "month" => date ? date.strftime("%m") : "",
76
- "day" => date ? date.strftime("%d") : "",
77
- "title" => CGI.escape(slug),
78
- "categories" => categories.join('/')
79
- }.inject(template) { |result, token|
80
- result.gsub(/:#{token.first}/, token.last)
81
- }.gsub(/#{site.config[:posts]}/, "").squeeze("/")
82
- end
83
-
84
- # Add any necessary layouts to this post
85
- # +layouts+ is a Hash of {"name" => "layout"}
86
- # +site_payload+ is the site payload hash
87
- #
88
- # Returns nothing
89
- def render(layouts, site_payload)
90
- payload = {"site" => {}, "page" => self.to_liquid}.deep_merge(site_payload)
91
- do_layout(payload, layouts)
92
- end
93
-
94
- # Convert this post into a Hash for use in Liquid templates.
95
- #
96
- # Returns <Hash>
97
- def to_liquid
98
- { "title" => self.title || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '),
99
- "url" => self.url,
100
- "date" => self.date,
101
- "id" => self.id,
102
- "categories" => self.categories,
103
- "tags" => self.tags,
104
- "content" => self.content }.deep_merge(self.data)
105
- end
106
-
107
- def inspect
108
- "#<Broadway:Post @url=#{self.url.inspect} @categories=#{self.categories.inspect} @tags=#{self.tags.inspect} @data=#{self.data.inspect}>"
109
- end
110
- end
111
-
112
- end