awestructx 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/bin/awestruct +8 -0
  2. data/lib/awestruct/astruct.rb +22 -0
  3. data/lib/awestruct/astruct_mixin.rb +71 -0
  4. data/lib/awestruct/cli/auto.rb +20 -0
  5. data/lib/awestruct/cli/generate.rb +26 -0
  6. data/lib/awestruct/cli/invoker.rb +109 -0
  7. data/lib/awestruct/cli/options.rb +116 -0
  8. data/lib/awestruct/cli/server.rb +24 -0
  9. data/lib/awestruct/config.rb +30 -0
  10. data/lib/awestruct/context.rb +22 -0
  11. data/lib/awestruct/context_helper.rb +68 -0
  12. data/lib/awestruct/engine.rb +254 -0
  13. data/lib/awestruct/extensions/assets.rb +39 -0
  14. data/lib/awestruct/extensions/atomizer.rb +44 -0
  15. data/lib/awestruct/extensions/cachebuster.rb +12 -0
  16. data/lib/awestruct/extensions/coffeescripttransform.rb +42 -0
  17. data/lib/awestruct/extensions/data_dir.rb +31 -0
  18. data/lib/awestruct/extensions/disqus.rb +62 -0
  19. data/lib/awestruct/extensions/extend_string.rb +97 -0
  20. data/lib/awestruct/extensions/flattr.rb +42 -0
  21. data/lib/awestruct/extensions/google_analytics.rb +38 -0
  22. data/lib/awestruct/extensions/gsub.rb +20 -0
  23. data/lib/awestruct/extensions/indexifier.rb +17 -0
  24. data/lib/awestruct/extensions/intense_debate.rb +38 -0
  25. data/lib/awestruct/extensions/minify.rb +178 -0
  26. data/lib/awestruct/extensions/obfuscate.rb +32 -0
  27. data/lib/awestruct/extensions/paginator.rb +105 -0
  28. data/lib/awestruct/extensions/partial.rb +25 -0
  29. data/lib/awestruct/extensions/pipeline.rb +50 -0
  30. data/lib/awestruct/extensions/posts.rb +70 -0
  31. data/lib/awestruct/extensions/relative.rb +11 -0
  32. data/lib/awestruct/extensions/remotePartial.rb +17 -0
  33. data/lib/awestruct/extensions/sitemap.rb +85 -0
  34. data/lib/awestruct/extensions/sitemap.xml.haml +16 -0
  35. data/lib/awestruct/extensions/tag_cloud.html.haml +7 -0
  36. data/lib/awestruct/extensions/tag_cloud.rb +34 -0
  37. data/lib/awestruct/extensions/tagger.rb +107 -0
  38. data/lib/awestruct/extensions/template.atom.haml +39 -0
  39. data/lib/awestruct/handler_chain.rb +28 -0
  40. data/lib/awestruct/handler_chains.rb +65 -0
  41. data/lib/awestruct/handlers/base_handler.rb +92 -0
  42. data/lib/awestruct/handlers/base_sass_handler.rb +42 -0
  43. data/lib/awestruct/handlers/file_handler.rb +61 -0
  44. data/lib/awestruct/handlers/front_matter_handler.rb +80 -0
  45. data/lib/awestruct/handlers/haml_handler.rb +42 -0
  46. data/lib/awestruct/handlers/interpolation_handler.rb +28 -0
  47. data/lib/awestruct/handlers/layout_handler.rb +61 -0
  48. data/lib/awestruct/handlers/markdown_handler.rb +36 -0
  49. data/lib/awestruct/handlers/no_op_handler.rb +34 -0
  50. data/lib/awestruct/handlers/sass_handler.rb +14 -0
  51. data/lib/awestruct/handlers/scss_handler.rb +14 -0
  52. data/lib/awestruct/handlers/string_handler.rb +29 -0
  53. data/lib/awestruct/handlers/textile_handler.rb +43 -0
  54. data/lib/awestruct/handlers/yaml_handler.rb +25 -0
  55. data/lib/awestruct/layouts.rb +15 -0
  56. data/lib/awestruct/page.rb +128 -0
  57. data/lib/awestruct/page_loader.rb +72 -0
  58. data/lib/awestruct/pipeline.rb +49 -0
  59. data/lib/awestruct/site.rb +51 -0
  60. data/lib/awestruct/util/default_inflections.rb +45 -0
  61. data/lib/awestruct/util/inflector.rb +242 -0
  62. data/lib/awestruct/version.rb +4 -0
  63. data/lib/guard/awestruct.rb +38 -0
  64. metadata +427 -0
@@ -0,0 +1,32 @@
1
+ module Awestruct
2
+ module Extensions
3
+ module Obfuscate
4
+
5
+ def mail_to(email, options={})
6
+ index = email.index('@') or raise "email needs to contain @"
7
+ index += 3
8
+ parts = [ email[0...index], email[index..-1] ]
9
+ "<a\nclass='#{options[:class]}\nhref=\"mailto:x@y\"\n'\nhref\n = '#{hex('mailto:' + percent(email))}\n'>#{hex(parts[0])}<!--\nmailto:abuse@hotmail.com\n</a>\n-->#{hex(parts[1])}</a>"
10
+ end
11
+
12
+ private
13
+
14
+ def hex(s)
15
+ result = ''
16
+ s.each_codepoint do |cp|
17
+ result << "&#x%x;" % [cp]
18
+ end
19
+ result
20
+ end
21
+
22
+ def percent(s)
23
+ result = ''
24
+ s.each_codepoint do |cp|
25
+ result << "%%%x" % [cp]
26
+ end
27
+ result
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,105 @@
1
+ module Awestruct
2
+ module Extensions
3
+ class Paginator
4
+
5
+ module Paginated
6
+ attr_accessor :window
7
+ attr_accessor :next_page
8
+ attr_accessor :previous_page
9
+ attr_accessor :current_page
10
+ attr_accessor :current_page_index
11
+ attr_accessor :pages
12
+
13
+ def links
14
+ html = %Q(<div class="pagination-links">)
15
+ unless ( previous_page.nil? )
16
+ html += %Q(<a href="#{previous_page.url}" class="previous-link">Previous</a> )
17
+ end
18
+ first_skip = false
19
+ second_skip = false
20
+ pages.each_with_index do |page, i|
21
+ if ( i == current_page_index )
22
+ html += %Q(<span class="current-page">#{i+1}</span> )
23
+ elsif ( i <= window )
24
+ html += %Q(<a href="#{page.url}" class="page-link">#{i+1}</a> )
25
+ elsif ( ( i > window ) && ( i < ( current_page_index - window ) ) && ! first_skip )
26
+ html += %Q(<span class="skip">...</span>)
27
+ first_skip = true
28
+ elsif ( ( i > ( current_page_index + window ) ) && ( i < ( ( pages.size - window ) - 1 ) ) && ! second_skip )
29
+ html += %Q(<span class="skip">...</span>)
30
+ second_skip = true
31
+ elsif ( ( i >= ( current_page_index - window ) ) && ( i <= ( current_page_index + window ) ) )
32
+ html += %Q(<a href="#{page.url}" class="page-link">#{i+1}</a> )
33
+ elsif ( i >= ( ( pages.size - window ) - 1 ) )
34
+ html += %Q(<a href="#{page.url}" class="page-link">#{i+1}</a> )
35
+ end
36
+ end
37
+ unless ( next_page.nil? )
38
+ html += %Q(<a href="#{next_page.url}" class="next-link">Next</a> )
39
+ end
40
+ html += %Q(</div>)
41
+ html
42
+ end
43
+
44
+ end
45
+
46
+ def initialize(prop_name, input_path, opts={})
47
+ @prop_name = prop_name
48
+ @input_path = input_path
49
+ @per_page = opts[:per_page] || 20
50
+ @window_size = opts[:window_size] || 2
51
+ @remove_input = opts.has_key?( :remove_input ) ? opts[:remove_input] : true
52
+ @output_prefix = opts[:output_prefix] || File.dirname( @input_path )
53
+ @collection = opts[:collection]
54
+ end
55
+
56
+ def execute(site)
57
+ removal_path = nil
58
+ all = @collection || site.send( @prop_name )
59
+ i = 1
60
+ paginated_pages = []
61
+ all.each_slice( @per_page ) do |slice|
62
+ page = site.engine.find_and_load_site_page( @input_path )
63
+ removal_path ||= page.output_path
64
+ slice.extend( Paginated )
65
+ page.send( "#{@prop_name}=", slice )
66
+ if ( i == 1 )
67
+ page.output_path = File.join( @output_prefix, File.basename( @input_path ) + ".html" )
68
+ else
69
+ page.output_path = File.join( @output_prefix, "page/#{i}.html" )
70
+ end
71
+ page.paginate_generated = true
72
+ site.pages << page
73
+ paginated_pages << page
74
+ i = i + 1
75
+ end
76
+
77
+ if ( @remove_input )
78
+ site.pages.reject!{|page|
79
+ ( ! page.paginate_generated && ( page.output_path == removal_path ) )
80
+ }
81
+ end
82
+
83
+ prev_page = nil
84
+ paginated_pages.each_with_index do |page,i|
85
+ slice = page.send( @prop_name )
86
+
87
+ slice.current_page = page
88
+ slice.current_page_index = i
89
+ slice.pages = paginated_pages
90
+ slice.window = 1
91
+
92
+ if ( prev_page != nil )
93
+ prev_page.send( @prop_name ).next_page = page
94
+ page.send( @prop_name ).previous_page = prev_page
95
+ end
96
+
97
+ prev_page = page
98
+ end
99
+
100
+ paginated_pages.first
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,25 @@
1
+ module Awestruct
2
+ module Extensions
3
+ module Partial
4
+
5
+ def partial(path, params = {})
6
+ filename = File.join( '_partials', path )
7
+
8
+ if !File.exists?( filename )
9
+ return nil
10
+ end
11
+
12
+ page = site.engine.load_site_page( filename )
13
+
14
+ return nil if !page
15
+
16
+ params.each do |k,v|
17
+ page.send( "#{k}=", v )
18
+ end if params
19
+
20
+ page.content
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,50 @@
1
+
2
+ Dir[ File.join( File.dirname(__FILE__), '*.rb' ) ].each do |f|
3
+ require f
4
+ end
5
+
6
+ module Awestruct
7
+ module Extensions
8
+ class Pipeline
9
+
10
+ attr_reader :before_extensions
11
+ attr_reader :extensions
12
+ attr_reader :after_extensions
13
+ attr_reader :helpers
14
+ attr_reader :transformers
15
+
16
+ def initialize(&block)
17
+ @extensions = []
18
+ @helpers = []
19
+ @transformers = []
20
+ instance_eval &block if block
21
+ end
22
+
23
+ def extension(ext)
24
+ @extensions << ext
25
+ ext.transform(@transformers) if ext.respond_to?('transform')
26
+ end
27
+
28
+ def helper(helper)
29
+ @helpers << helper
30
+ end
31
+
32
+ def transformer(transformer)
33
+ @transformers << transformer
34
+ end
35
+
36
+ def execute(site)
37
+ extensions.each do |ext|
38
+ ext.execute( site )
39
+ end
40
+ end
41
+
42
+ def watch(watched_dirs)
43
+ extensions.each do |ext|
44
+ ext.watch( watched_dirs ) if ext.respond_to?('watch')
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,70 @@
1
+ module Awestruct
2
+ module Extensions
3
+ class Posts
4
+
5
+ def initialize(path_prefix='', assign_to=:posts)
6
+ @path_prefix = path_prefix
7
+ @assign_to = assign_to
8
+ end
9
+
10
+ def execute(site)
11
+ posts = []
12
+
13
+ site.pages.each do |page|
14
+ year, month, day, slug = nil
15
+
16
+ if ( page.relative_source_path =~ /^#{@path_prefix}\// )
17
+ if ( page.relative_source_path =~ /^#{@path_prefix}\/(20[01][0-9])-([01][0-9])-([0123][0-9])-([^.]+)\..*$/ )
18
+ year = $1
19
+ month = $2
20
+ day = $3
21
+ slug = $4
22
+ page.date = Time.utc( year.to_i, month.to_i, day.to_i )
23
+ elsif (page.date?)
24
+ page.relative_source_path =~ /^#{@path_prefix}\/(.*)\..*$/
25
+ date = page.date;
26
+ if date.kind_of? String
27
+ date = Time.parse page.date
28
+ end
29
+ year = date.year
30
+ month = date.month
31
+ day = date.day
32
+ page.date = Time.utc(year, month, day)
33
+ slug = $1
34
+ end
35
+
36
+ # if a date was found create a post
37
+ if( year and month and day)
38
+ page.slug = slug
39
+ #context = OpenStruct.new({
40
+ #:site=>site,
41
+ #:page=>page,
42
+ #})
43
+ context = page.create_context
44
+ #page.body = page.render( context )
45
+ page.output_path = "#{@path_prefix}/#{year}/#{month}/#{day}/#{slug}.html"
46
+ #page.layout = 'post'
47
+ posts << page
48
+ end
49
+ end
50
+ end
51
+
52
+ posts = posts.sort_by{|each| [each.date, each.sequence || 0, File.mtime( each.source_path ), each.slug ] }.reverse
53
+
54
+ last = nil
55
+ singular = @assign_to.to_s.singularize
56
+ posts.each do |e|
57
+ if ( last != nil )
58
+ e.send( "next_#{singular}=", last )
59
+ last.send( "previous_#{singular}=", e )
60
+ end
61
+ last = e
62
+ end
63
+
64
+ site.send( "#{@assign_to}=", posts )
65
+
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,11 @@
1
+ require 'pathname'
2
+
3
+ module Awestruct
4
+ module Extensions
5
+ module Relative
6
+ def relative(href)
7
+ Pathname.new(href).relative_path_from(Pathname.new(File.dirname(page.output_path))).to_s
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'open-uri'
2
+
3
+ module Awestruct
4
+ module Extensions
5
+ module RemotePartial
6
+
7
+ def remotePartial(url)
8
+
9
+ page = open(url)
10
+ return nil if !page
11
+ page.read
12
+
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,85 @@
1
+ # Generates a sitemap for search engines. Defaults to /sitemap.xml
2
+ # Ignores images, css, robots, atoms, javascript files.
3
+ # Add a sitemap.yml file to add files that for one reason or
4
+ # another won't be hanging off of site (e.g. they're in .htaccess)
5
+ require 'ostruct'
6
+
7
+ module Awestruct
8
+ module Extensions
9
+ class Sitemap
10
+
11
+ def execute( site )
12
+
13
+ # Go through all of the site's pages and add sitemap metadata
14
+ sitemap_pages = []
15
+ entries = site.pages
16
+ entries.each { |entry| sitemap_pages << set_sitemap_data( entry ) if valid_sitemap_entry( entry ) } if entries
17
+
18
+ # Generate sitemap pages for stuff in _config/sitemap.yml
19
+ site.sitemap.pages.each do |entry|
20
+ page = Awestruct::Page.new( site )
21
+ page.output_path = entry.url
22
+ page.date = entry.date( nil )
23
+ page.priority = entry.priority( nil )
24
+ page.change_frequency = entry.change_frequency( nil )
25
+ sitemap_pages << page
26
+ end if site.sitemap
27
+
28
+ # Generate the correct urls for each page in the sitemap
29
+ site.engine.set_urls( sitemap_pages )
30
+
31
+ # Create a sitemap.xml file from our template
32
+ sitemap = File.join( File.dirname(__FILE__), 'sitemap.xml.haml' )
33
+ page = site.engine.load_page( sitemap )
34
+ page.output_path = 'sitemap.xml'
35
+ page.sitemap_entries = sitemap_pages
36
+
37
+ # Add the sitemap to our site
38
+ site.pages << page
39
+ end
40
+
41
+ protected
42
+
43
+ def set_sitemap_data( page )
44
+ site = page.site
45
+ munge_date( page )
46
+ page.priority ||= (site.priority or 0.1)
47
+ page.change_frequency ||= (site.change_frequency or 'never')
48
+ page
49
+ end
50
+
51
+ def munge_date( page )
52
+ date = page.date
53
+ if date
54
+ begin
55
+ if date.kind_of? String
56
+ page.lastmod = Time.parse( page.date ).strftime( "%Y-%m-%d" )
57
+ else
58
+ page.lastmod = date.strftime( "%Y-%m-%d" )
59
+ end
60
+ rescue Exception => e
61
+ puts "[ERROR] Cannot parse date #{date.to_s}: #{e}"
62
+ end
63
+ else
64
+ page.lastmod = Time.now.strftime( "%Y-%m-%d" )
65
+ end
66
+ end
67
+
68
+ def valid_sitemap_entry( page )
69
+ page.output_filename != '.htaccess' &&
70
+ page.output_filename != 'screen.css' &&
71
+ page.output_filename != 'print.css' &&
72
+ page.output_filename != 'ie.css' &&
73
+ page.output_filename != 'robots.txt' &&
74
+ page.output_extension != '.atom' &&
75
+ page.output_extension != '.scss' &&
76
+ page.output_extension != '.css' &&
77
+ page.output_extension != '.png' &&
78
+ page.output_extension != '.jpg' &&
79
+ page.output_extension != '.gif' &&
80
+ page.output_extension != '.js'
81
+ end
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,16 @@
1
+ ---
2
+ ---
3
+ !!! XML
4
+
5
+ %urlset{ :xmlns=>'http://www.sitemaps.org/schemas/sitemap/0.9' }
6
+ - unless page.sitemap_entries.empty?
7
+ - for entry in page.sitemap_entries
8
+ %url
9
+ %loc= "#{entry.site.base_url}#{entry.url}"
10
+ - if entry.lastmod
11
+ %lastmod= entry.lastmod
12
+ - if entry.priority
13
+ %priority= entry.priority
14
+ - if entry.change_frequency
15
+ %changefreq= entry.change_frequency
16
+
@@ -0,0 +1,7 @@
1
+ ---
2
+ ---
3
+
4
+ .tag-cloud
5
+ - for tag in page.tags
6
+ %span.tag{:class=>"tag-#{tag.group}"}
7
+ %a{:href=>tag.primary_page.url}= tag
@@ -0,0 +1,34 @@
1
+ module Awestruct
2
+ module Extensions
3
+ class TagCloud
4
+
5
+ def initialize(tagged_items_property, output_path='tags', opts={})
6
+ @tagged_items_property = tagged_items_property
7
+ @output_path = output_path
8
+ @layout = opts[:layout].to_s
9
+ @title = opts[:title] || 'Tags'
10
+ end
11
+
12
+ def execute(site)
13
+ page = site.engine.load_page( File.join( File.dirname( __FILE__ ), 'tag_cloud.html.haml' ) )
14
+ page.output_path = File.join( @output_path )
15
+ page.layout = @layout
16
+ page.title = @title
17
+ page.tags = site.send( "#{@tagged_items_property}_tags" ) || []
18
+ site.pages << page
19
+ site.send( "#{@tagged_items_property}_tag_cloud=", LazyPage.new( page ) )
20
+ end
21
+
22
+ end
23
+
24
+ class LazyPage
25
+ def initialize(page)
26
+ @page = page
27
+ end
28
+ def to_s
29
+ @page.content
30
+ end
31
+ end
32
+
33
+ end
34
+ end