awestructx 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/awestruct +8 -0
- data/lib/awestruct/astruct.rb +22 -0
- data/lib/awestruct/astruct_mixin.rb +71 -0
- data/lib/awestruct/cli/auto.rb +20 -0
- data/lib/awestruct/cli/generate.rb +26 -0
- data/lib/awestruct/cli/invoker.rb +109 -0
- data/lib/awestruct/cli/options.rb +116 -0
- data/lib/awestruct/cli/server.rb +24 -0
- data/lib/awestruct/config.rb +30 -0
- data/lib/awestruct/context.rb +22 -0
- data/lib/awestruct/context_helper.rb +68 -0
- data/lib/awestruct/engine.rb +254 -0
- data/lib/awestruct/extensions/assets.rb +39 -0
- data/lib/awestruct/extensions/atomizer.rb +44 -0
- data/lib/awestruct/extensions/cachebuster.rb +12 -0
- data/lib/awestruct/extensions/coffeescripttransform.rb +42 -0
- data/lib/awestruct/extensions/data_dir.rb +31 -0
- data/lib/awestruct/extensions/disqus.rb +62 -0
- data/lib/awestruct/extensions/extend_string.rb +97 -0
- data/lib/awestruct/extensions/flattr.rb +42 -0
- data/lib/awestruct/extensions/google_analytics.rb +38 -0
- data/lib/awestruct/extensions/gsub.rb +20 -0
- data/lib/awestruct/extensions/indexifier.rb +17 -0
- data/lib/awestruct/extensions/intense_debate.rb +38 -0
- data/lib/awestruct/extensions/minify.rb +178 -0
- data/lib/awestruct/extensions/obfuscate.rb +32 -0
- data/lib/awestruct/extensions/paginator.rb +105 -0
- data/lib/awestruct/extensions/partial.rb +25 -0
- data/lib/awestruct/extensions/pipeline.rb +50 -0
- data/lib/awestruct/extensions/posts.rb +70 -0
- data/lib/awestruct/extensions/relative.rb +11 -0
- data/lib/awestruct/extensions/remotePartial.rb +17 -0
- data/lib/awestruct/extensions/sitemap.rb +85 -0
- data/lib/awestruct/extensions/sitemap.xml.haml +16 -0
- data/lib/awestruct/extensions/tag_cloud.html.haml +7 -0
- data/lib/awestruct/extensions/tag_cloud.rb +34 -0
- data/lib/awestruct/extensions/tagger.rb +107 -0
- data/lib/awestruct/extensions/template.atom.haml +39 -0
- data/lib/awestruct/handler_chain.rb +28 -0
- data/lib/awestruct/handler_chains.rb +65 -0
- data/lib/awestruct/handlers/base_handler.rb +92 -0
- data/lib/awestruct/handlers/base_sass_handler.rb +42 -0
- data/lib/awestruct/handlers/file_handler.rb +61 -0
- data/lib/awestruct/handlers/front_matter_handler.rb +80 -0
- data/lib/awestruct/handlers/haml_handler.rb +42 -0
- data/lib/awestruct/handlers/interpolation_handler.rb +28 -0
- data/lib/awestruct/handlers/layout_handler.rb +61 -0
- data/lib/awestruct/handlers/markdown_handler.rb +36 -0
- data/lib/awestruct/handlers/no_op_handler.rb +34 -0
- data/lib/awestruct/handlers/sass_handler.rb +14 -0
- data/lib/awestruct/handlers/scss_handler.rb +14 -0
- data/lib/awestruct/handlers/string_handler.rb +29 -0
- data/lib/awestruct/handlers/textile_handler.rb +43 -0
- data/lib/awestruct/handlers/yaml_handler.rb +25 -0
- data/lib/awestruct/layouts.rb +15 -0
- data/lib/awestruct/page.rb +128 -0
- data/lib/awestruct/page_loader.rb +72 -0
- data/lib/awestruct/pipeline.rb +49 -0
- data/lib/awestruct/site.rb +51 -0
- data/lib/awestruct/util/default_inflections.rb +45 -0
- data/lib/awestruct/util/inflector.rb +242 -0
- data/lib/awestruct/version.rb +4 -0
- data/lib/guard/awestruct.rb +38 -0
- metadata +427 -0
data/bin/awestruct
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'awestruct/astruct_mixin'
|
2
|
+
|
3
|
+
module Awestruct
|
4
|
+
|
5
|
+
class AStruct < Hash
|
6
|
+
|
7
|
+
include AStructMixin
|
8
|
+
|
9
|
+
def initialize(hash=nil)
|
10
|
+
hash.each{|k,v| self[k]=v } if hash
|
11
|
+
end
|
12
|
+
|
13
|
+
alias_method :original_entries, :entries
|
14
|
+
undef entries
|
15
|
+
|
16
|
+
def inspect
|
17
|
+
"AStruct{...}"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
|
2
|
+
module Awestruct
|
3
|
+
|
4
|
+
module AStructMixin
|
5
|
+
|
6
|
+
def self.extended(o)
|
7
|
+
class << o
|
8
|
+
alias_method :original_entries, :entries
|
9
|
+
undef entries
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def cascade_for_nils!
|
14
|
+
@cascade_for_nils = true
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def key?(key)
|
19
|
+
super( key ) || super( key.to_sym ) || super( key.to_s )
|
20
|
+
end
|
21
|
+
|
22
|
+
def [](key)
|
23
|
+
r = super( key ) || super( key.to_sym ) || super( key.to_s )
|
24
|
+
transform_entry( r )
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(sym, *args, &blk)
|
28
|
+
type = sym.to_s[-1,1]
|
29
|
+
name = sym.to_s.gsub(/[=!?]$/, '').to_sym
|
30
|
+
case type
|
31
|
+
when '='
|
32
|
+
self[name] = args.first
|
33
|
+
when '!'
|
34
|
+
__send__(name, *args, &blk)
|
35
|
+
when '?'
|
36
|
+
self[name]
|
37
|
+
else
|
38
|
+
if key?(name)
|
39
|
+
self[name]
|
40
|
+
elsif @cascade_for_nils
|
41
|
+
self[name] = AStruct.new.cascade_for_nils!
|
42
|
+
self[name]
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def transform_entry(entry)
|
51
|
+
r = case(entry)
|
52
|
+
when AStructMixin
|
53
|
+
entry
|
54
|
+
when Hash
|
55
|
+
#AStruct.new( entry )
|
56
|
+
entry.extend( AStructMixin )
|
57
|
+
when Array
|
58
|
+
entry.map!{|i| transform_entry(i)}
|
59
|
+
else
|
60
|
+
entry
|
61
|
+
end
|
62
|
+
r
|
63
|
+
end
|
64
|
+
|
65
|
+
def inspect
|
66
|
+
"AStruct{...}"
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'guard/awestruct'
|
2
|
+
|
3
|
+
module Awestruct
|
4
|
+
module CLI
|
5
|
+
class Auto
|
6
|
+
|
7
|
+
def initialize(path)
|
8
|
+
@path = path
|
9
|
+
end
|
10
|
+
|
11
|
+
def run()
|
12
|
+
Guard.setup
|
13
|
+
Guard.start( :guardfile=>File.dirname(__FILE__) + '/Guardfile',
|
14
|
+
:watchdir=>@path,
|
15
|
+
:watch_all_modifications=>true )
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'awestruct/engine'
|
2
|
+
|
3
|
+
module Awestruct
|
4
|
+
module CLI
|
5
|
+
class Generate
|
6
|
+
|
7
|
+
def initialize(config, profile=nil, base_url=nil, default_base_url='http://localhost:4242', force=false)
|
8
|
+
@profile = profile
|
9
|
+
@base_url = base_url
|
10
|
+
@default_base_url = default_base_url
|
11
|
+
@force = force
|
12
|
+
@engine = Awestruct::Engine.new( config )
|
13
|
+
end
|
14
|
+
|
15
|
+
def run()
|
16
|
+
begin
|
17
|
+
puts "Generating site"
|
18
|
+
@engine.run( @profile, @base_url, @default_base_url, @force )
|
19
|
+
rescue =>e
|
20
|
+
puts e
|
21
|
+
puts e.backtrace
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'awestruct/cli/options'
|
2
|
+
|
3
|
+
require 'awestruct/cli/generate'
|
4
|
+
require 'awestruct/cli/auto'
|
5
|
+
require 'awestruct/cli/server'
|
6
|
+
|
7
|
+
require 'pathname'
|
8
|
+
|
9
|
+
module Awestruct
|
10
|
+
module CLI
|
11
|
+
class Invoker
|
12
|
+
|
13
|
+
attr_reader :options
|
14
|
+
|
15
|
+
attr_reader :config
|
16
|
+
attr_reader :profile
|
17
|
+
|
18
|
+
def initialize(*options)
|
19
|
+
options = options.flatten
|
20
|
+
if ( ( ! options.empty? ) && ( options.first === Awestruct::CLI::Options ) )
|
21
|
+
@options = options.first
|
22
|
+
else
|
23
|
+
@options = Awestruct::CLI::Options.parse! options
|
24
|
+
end
|
25
|
+
@threads = []
|
26
|
+
@profile = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def invoke!
|
30
|
+
load_profile() unless ( options.init )
|
31
|
+
|
32
|
+
setup_config()
|
33
|
+
|
34
|
+
invoke_init() if ( options.init )
|
35
|
+
invoke_script() if ( options.script )
|
36
|
+
invoke_force() if ( options.force )
|
37
|
+
invoke_generate() if ( options.generate )
|
38
|
+
invoke_deploy() if ( options.deploy )
|
39
|
+
invoke_server() if ( options.server )
|
40
|
+
invoke_auto() if ( options.auto )
|
41
|
+
|
42
|
+
wait_for_completion()
|
43
|
+
end
|
44
|
+
|
45
|
+
def load_profile()
|
46
|
+
site_yaml_file = File.join( Dir.pwd, '_config', 'site.yml' )
|
47
|
+
if ( File.exist?( site_yaml_file ) )
|
48
|
+
site_yaml = YAML.load( File.read( site_yaml_file ) )
|
49
|
+
if site_yaml
|
50
|
+
profiles_data = site_yaml['profiles'] || {}
|
51
|
+
@profile = if profiles_data.nil?
|
52
|
+
nil
|
53
|
+
else
|
54
|
+
if options.profile
|
55
|
+
profiles_data[options.profile]
|
56
|
+
else
|
57
|
+
# if no profile given, pick the first with deploy config
|
58
|
+
options.profile, profile_data = profiles_data.select { |k,v| v && v['deploy'] }.first
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def setup_config()
|
66
|
+
@config = Awestruct::Config.new( Dir.pwd )
|
67
|
+
end
|
68
|
+
|
69
|
+
def invoke_init()
|
70
|
+
end
|
71
|
+
|
72
|
+
def invoke_script()
|
73
|
+
end
|
74
|
+
|
75
|
+
def invoke_force()
|
76
|
+
FileUtils.rm_rf( config.output_dir )
|
77
|
+
end
|
78
|
+
|
79
|
+
def invoke_generate()
|
80
|
+
Awestruct::CLI::Generate.new( config, profile, options.base_url, 'http://localhost:4242', options.force ).run
|
81
|
+
end
|
82
|
+
|
83
|
+
def invoke_deploy()
|
84
|
+
end
|
85
|
+
|
86
|
+
def invoke_auto()
|
87
|
+
run_in_thread( Awestruct::CLI::Auto.new( config.dir ) )
|
88
|
+
end
|
89
|
+
|
90
|
+
def invoke_server()
|
91
|
+
run_in_thread( Awestruct::CLI::Server.new( './_site', options.bind_addr, options.port ) )
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def run_in_thread(command)
|
98
|
+
@threads << Thread.new(command){|c| c.run}
|
99
|
+
end
|
100
|
+
|
101
|
+
def wait_for_completion()
|
102
|
+
@threads.each do |thr|
|
103
|
+
thr.join
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
require 'awestruct/version'
|
4
|
+
|
5
|
+
module Awestruct
|
6
|
+
module CLI
|
7
|
+
class Options
|
8
|
+
|
9
|
+
attr_accessor :generate
|
10
|
+
attr_accessor :server
|
11
|
+
attr_accessor :port
|
12
|
+
attr_accessor :bind_addr
|
13
|
+
attr_accessor :auto
|
14
|
+
attr_accessor :force
|
15
|
+
attr_accessor :init
|
16
|
+
attr_accessor :framework
|
17
|
+
attr_accessor :scaffold
|
18
|
+
attr_accessor :base_url
|
19
|
+
attr_accessor :profile
|
20
|
+
attr_accessor :deploy
|
21
|
+
attr_accessor :script
|
22
|
+
|
23
|
+
def initialize()
|
24
|
+
@generate = true
|
25
|
+
@server = false
|
26
|
+
@port = 4242
|
27
|
+
@bind_addr = '0.0.0.0'
|
28
|
+
@auto = false
|
29
|
+
@force = false
|
30
|
+
@init = false
|
31
|
+
@framework = 'compass'
|
32
|
+
@scaffold = true
|
33
|
+
@base_url = nil
|
34
|
+
@profile = nil
|
35
|
+
@deploy = false
|
36
|
+
@script = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.parse!(args)
|
40
|
+
Options.new.parse! args
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse!(args)
|
44
|
+
opts = OptionParser.new do |opts|
|
45
|
+
opts.on( '-i', '--init', 'Initialize a new project in the current directory' ) do |init|
|
46
|
+
self.init = init
|
47
|
+
self.generate = false
|
48
|
+
end
|
49
|
+
opts.on( '-f', '--framework FRAMEWORK', 'Specify a compass framework during initialization (bootstrap, blueprint, 960)' ) do |framework|
|
50
|
+
self.framework = framework
|
51
|
+
end
|
52
|
+
opts.on( '--[no-]scaffold', 'Create scaffolding during initialization (default: true)' ) do |s|
|
53
|
+
self.scaffold = s
|
54
|
+
end
|
55
|
+
opts.on( '--force', 'Force a regeneration' ) do |force|
|
56
|
+
self.force = force
|
57
|
+
end
|
58
|
+
opts.on( '-s', '--server', 'Serve generated site' ) do |s|
|
59
|
+
self.server = s
|
60
|
+
end
|
61
|
+
opts.on( '-u', '--url URL', 'Set site.base_url' ) do |url|
|
62
|
+
self.base_url = url
|
63
|
+
end
|
64
|
+
opts.on( '-d', '--dev', 'Run in development mode (--auto, --server and -profile development)' ) do |url|
|
65
|
+
self.server = true
|
66
|
+
self.auto = true
|
67
|
+
self.port = 4242
|
68
|
+
self.profile = 'development'
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on( '-P', '--profile PROFILE', 'Specify a profile' ) do |profile|
|
72
|
+
self.profile = profile
|
73
|
+
end
|
74
|
+
|
75
|
+
opts.on( '--deploy', 'Deploy site' ) do |deploy|
|
76
|
+
self.deploy = deploy
|
77
|
+
end
|
78
|
+
|
79
|
+
opts.on( '-a', '--auto', 'Auto-generate when changes are noticed' ) do |a|
|
80
|
+
self.auto = a
|
81
|
+
end
|
82
|
+
opts.on( '-p', '--port PORT', Integer, 'Server port (default: 4242)' ) do |port|
|
83
|
+
self.port = port
|
84
|
+
end
|
85
|
+
opts.on( '-b', '--bind ADDR', 'Server address (default: 0.0.0.0)' ) do |bind_addr|
|
86
|
+
self.bind_addr = bind_addr
|
87
|
+
end
|
88
|
+
opts.on( '-g', '--[no-]generate', 'Generated site' ) do |g|
|
89
|
+
self.generate = g
|
90
|
+
end
|
91
|
+
opts.on( '--run SCRIPT', 'Force a regeneration' ) do |script|
|
92
|
+
self.script = script
|
93
|
+
end
|
94
|
+
|
95
|
+
opts.separator ''
|
96
|
+
opts.separator "Common options:"
|
97
|
+
|
98
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
99
|
+
puts opts
|
100
|
+
exit
|
101
|
+
end
|
102
|
+
|
103
|
+
opts.on_tail("-v", "--version", "Display the version") do
|
104
|
+
puts "Awestruct: #{Awestruct::VERSION}"
|
105
|
+
puts "http://awestruct.org/"
|
106
|
+
exit
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
opts.parse!(args)
|
111
|
+
self
|
112
|
+
end # parse()
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
|
3
|
+
module Awestruct
|
4
|
+
module CLI
|
5
|
+
|
6
|
+
WEBrick::HTTPUtils::DefaultMimeTypes.store('atom', 'application/atom+xml')
|
7
|
+
WEBrick::HTTPUtils::DefaultMimeTypes.store('appcache', 'text/cache-manifest')
|
8
|
+
|
9
|
+
class Server
|
10
|
+
attr_reader :server
|
11
|
+
|
12
|
+
def initialize(path, bind_addr='0.0.0.0', port=4242)
|
13
|
+
@path = path
|
14
|
+
@bind_addr = bind_addr
|
15
|
+
@port = port
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
@server = WEBrick::HTTPServer.new( :DocumentRoot=>@path, :Port=>@port, :BindAddress=>@bind_addr )
|
20
|
+
@server.start
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
module Awestruct
|
3
|
+
|
4
|
+
class Config
|
5
|
+
|
6
|
+
attr_accessor :dir
|
7
|
+
attr_accessor :layouts_dir
|
8
|
+
attr_accessor :config_dir
|
9
|
+
attr_accessor :extension_dir
|
10
|
+
attr_accessor :input_dir
|
11
|
+
attr_accessor :output_dir
|
12
|
+
attr_accessor :skin_dir
|
13
|
+
attr_accessor :tmp_dir
|
14
|
+
attr_accessor :ignore
|
15
|
+
|
16
|
+
def initialize(dir = Dir.pwd)
|
17
|
+
@dir = Pathname.new( dir )
|
18
|
+
@layouts_dir = Pathname.new( File.join(dir, '_layouts') )
|
19
|
+
@config_dir = Pathname.new( File.join(dir, '_config') )
|
20
|
+
@input_dir = Pathname.new( File.join(dir, '') )
|
21
|
+
@output_dir = Pathname.new( File.join(dir, '_site') )
|
22
|
+
@extension_dir = Pathname.new( File.join(dir, '_ext') )
|
23
|
+
@skin_dir = Pathname.new( File.join(dir, '_skin') )
|
24
|
+
@tmp_dir = Pathname.new( File.join(dir, '_tmp') )
|
25
|
+
@ignore = File.exists?(ignore_file = File.join(dir, ".awestruct_ignore")) ? Dir[*IO.read(ignore_file).each_line.map(&:strip)] : []
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
require 'awestruct/astruct'
|
3
|
+
|
4
|
+
module Awestruct
|
5
|
+
|
6
|
+
class Context < Awestruct::AStruct
|
7
|
+
attr_accessor :site
|
8
|
+
attr_accessor :page
|
9
|
+
|
10
|
+
def initialize(hash)
|
11
|
+
super
|
12
|
+
@page = hash[:page]
|
13
|
+
@site = hash[:site]
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
"Awestruct::Context{:page=>#{self.page.inspect}}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|