staticmatic3 2.1.9

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.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +16 -0
  3. data/Gemfile.lock +43 -0
  4. data/LICENSE +20 -0
  5. data/README.md +154 -0
  6. data/Rakefile +45 -0
  7. data/VERSION.yml +5 -0
  8. data/bin/staticmatic +142 -0
  9. data/lib/staticmatic.rb +22 -0
  10. data/lib/staticmatic/ambiguous_template_error.rb +19 -0
  11. data/lib/staticmatic/base.rb +149 -0
  12. data/lib/staticmatic/compass.rb +5 -0
  13. data/lib/staticmatic/compass/app_integration.rb +21 -0
  14. data/lib/staticmatic/compass/configuration_defaults.rb +44 -0
  15. data/lib/staticmatic/compass/installer.rb +15 -0
  16. data/lib/staticmatic/configuration.rb +56 -0
  17. data/lib/staticmatic/deployers/aws-s3.rb +108 -0
  18. data/lib/staticmatic/deployers/config/amazon.yml +7 -0
  19. data/lib/staticmatic/error.rb +17 -0
  20. data/lib/staticmatic/helpers.rb +12 -0
  21. data/lib/staticmatic/helpers/assets_helper.rb +116 -0
  22. data/lib/staticmatic/helpers/current_path_helper.rb +22 -0
  23. data/lib/staticmatic/helpers/form_helper.rb +23 -0
  24. data/lib/staticmatic/helpers/render_helper.rb +14 -0
  25. data/lib/staticmatic/helpers/tag_helper.rb +35 -0
  26. data/lib/staticmatic/helpers/url_helper.rb +59 -0
  27. data/lib/staticmatic/mixins/build.rb +41 -0
  28. data/lib/staticmatic/mixins/helpers.rb +15 -0
  29. data/lib/staticmatic/mixins/render.rb +110 -0
  30. data/lib/staticmatic/mixins/rescue.rb +12 -0
  31. data/lib/staticmatic/mixins/server.rb +7 -0
  32. data/lib/staticmatic/mixins/setup.rb +16 -0
  33. data/lib/staticmatic/server.rb +87 -0
  34. data/lib/staticmatic/template_error.rb +44 -0
  35. data/lib/staticmatic/templates/rescues/default.haml +7 -0
  36. data/lib/staticmatic/templates/rescues/template.haml +18 -0
  37. data/spec/base_spec.rb +13 -0
  38. data/spec/compass_integration_spec.rb +28 -0
  39. data/spec/helpers/asset_helper_spec.rb +41 -0
  40. data/spec/helpers/custom_helper_spec.rb +17 -0
  41. data/spec/render_spec.rb +44 -0
  42. data/spec/rescue_spec.rb +36 -0
  43. data/spec/sandbox/test_site/config/compass.rb +1 -0
  44. data/spec/sandbox/test_site/config/site.rb +0 -0
  45. data/spec/sandbox/test_site/site/sub_folder/another_sub_folder/index.html +1 -0
  46. data/spec/sandbox/test_site/site/sub_folder/another_sub_folder/index.html.html +1 -0
  47. data/spec/sandbox/test_site/site/sub_folder/index.html +1 -0
  48. data/spec/sandbox/test_site/src/_helpers/application_helper.rb +5 -0
  49. data/spec/sandbox/test_site/src/_layouts/alternate_layout.haml +3 -0
  50. data/spec/sandbox/test_site/src/_layouts/default.haml +7 -0
  51. data/spec/sandbox/test_site/src/_layouts/projects.haml +1 -0
  52. data/spec/sandbox/test_site/src/_partials/menu.haml +1 -0
  53. data/spec/sandbox/test_site/src/_partials/partial_with_error.haml +1 -0
  54. data/spec/sandbox/test_site/src/hello_world.erb +1 -0
  55. data/spec/sandbox/test_site/src/index.haml +5 -0
  56. data/spec/sandbox/test_site/src/layout_test.haml +2 -0
  57. data/spec/sandbox/test_site/src/page_one.haml +3 -0
  58. data/spec/sandbox/test_site/src/page_two.haml +2 -0
  59. data/spec/sandbox/test_site/src/page_with_error.haml +5 -0
  60. data/spec/sandbox/test_site/src/page_with_partial_error.haml +3 -0
  61. data/spec/sandbox/test_site/src/stylesheets/application.sass +5 -0
  62. data/spec/sandbox/test_site/src/stylesheets/css_with_error.sass +5 -0
  63. data/spec/sandbox/test_site/src/stylesheets/nested/a_nested_stylesheet.sass +0 -0
  64. data/spec/sandbox/test_site/src/stylesheets/partials/_forms.sass +2 -0
  65. data/spec/sandbox/test_site/src/stylesheets/sassy.scss +12 -0
  66. data/spec/server_spec.rb +11 -0
  67. data/spec/spec_helper.rb +14 -0
  68. data/spec/template_error_spec.rb +23 -0
  69. data/staticmatic.gemspec +158 -0
  70. data/staticmatic3.gemspec +164 -0
  71. data/website/Gemfile +1 -0
  72. data/website/config/site.rb +17 -0
  73. data/website/site/docs/compass_integration.html +70 -0
  74. data/website/site/docs/getting_started.html +49 -0
  75. data/website/site/docs/helpers.html +22 -0
  76. data/website/site/images/bycurve21.gif +0 -0
  77. data/website/site/images/curve21.jpg +0 -0
  78. data/website/site/images/homepage-build.jpg +0 -0
  79. data/website/site/images/homepage-previewing.jpg +0 -0
  80. data/website/site/images/homepage-templating.jpg +0 -0
  81. data/website/site/stylesheets/ie.css +5 -0
  82. data/website/site/stylesheets/print.css +372 -0
  83. data/website/site/stylesheets/screen.css +488 -0
  84. data/website/src/helpers/content_helper.rb +10 -0
  85. data/website/src/layouts/default.haml +15 -0
  86. data/website/src/pages/development.haml +9 -0
  87. data/website/src/pages/docs/_menu.haml +4 -0
  88. data/website/src/pages/docs/_requires_prerelease.haml +4 -0
  89. data/website/src/pages/docs/compass_integration.haml +54 -0
  90. data/website/src/pages/docs/getting_started.haml +31 -0
  91. data/website/src/pages/docs/helpers.haml +1 -0
  92. data/website/src/pages/index.haml +27 -0
  93. data/website/src/stylesheets/_base.scss +43 -0
  94. data/website/src/stylesheets/_defaults.scss +260 -0
  95. data/website/src/stylesheets/ie.scss +10 -0
  96. data/website/src/stylesheets/print.scss +33 -0
  97. data/website/src/stylesheets/screen.scss +73 -0
  98. metadata +285 -0
@@ -0,0 +1,19 @@
1
+ class StaticMatic::AmbiguousTemplateError < StandardError
2
+ attr_reader :template_name
3
+
4
+ def initialize(template_name, ambiguous_templates)
5
+ @template_name = template_name
6
+ @ambiguous_templates = ambiguous_templates
7
+ end
8
+
9
+ def message
10
+ <<-MESSAGE
11
+ Ambiguous request when searching for a template for filename `#{@template_name}`:
12
+ There is more than one type of template available for rendering.
13
+
14
+ Templates causing the ambiguity:
15
+ #{@ambiguous_templates.join "\n"}
16
+ MESSAGE
17
+ end
18
+
19
+ end
@@ -0,0 +1,149 @@
1
+ module StaticMatic
2
+ class Base
3
+
4
+ include StaticMatic::RenderMixin
5
+ include StaticMatic::BuildMixin
6
+ include StaticMatic::SetupMixin
7
+ include StaticMatic::HelpersMixin
8
+ include StaticMatic::ServerMixin
9
+ include StaticMatic::RescueMixin
10
+
11
+ attr_accessor :configuration, :mode
12
+ attr_reader :src_dir, :site_dir
13
+
14
+ def current_file
15
+ @current_file_stack[0] || ""
16
+ end
17
+
18
+ def self.extensions
19
+ @extensions ||= (Tilt.mappings.map { |k,v| k } << "slim")
20
+ end
21
+
22
+ def extensions
23
+ self.class.extensions
24
+ end
25
+
26
+ def ensure_extension(filename)
27
+ ext = File.extname(filename)
28
+ ext.length > 0 ? filename : "#{filename}.#{configuration.default_template_engine}"
29
+ end
30
+
31
+ def initialize(base_dir, mode = :preview)
32
+ @configuration = Configuration.new
33
+ @current_file_stack = []
34
+ @mode = mode
35
+
36
+ @default_layout_name = "default"
37
+
38
+ @scope = Object.new
39
+ @scope.instance_variable_set("@staticmatic", self)
40
+ @scope.instance_eval do
41
+ extend StaticMatic::Helpers
42
+ end
43
+
44
+ @base_dir = base_dir
45
+
46
+ load_configuration
47
+
48
+ @src_dir = File.join(@base_dir, @configuration.site_dir)
49
+ @site_dir = File.join(@base_dir, @configuration.build_dir)
50
+
51
+ configure_compass
52
+ load_helpers
53
+ end
54
+
55
+ def load_configuration
56
+ configuration = StaticMatic::Configuration.new
57
+ config_file = File.join(@base_dir, "config", "site.rb")
58
+
59
+ if File.exists?(config_file)
60
+ config = File.read(config_file)
61
+ eval(config)
62
+ end
63
+
64
+ @configuration = configuration
65
+ end
66
+
67
+ def base_dir
68
+ @base_dir
69
+ end
70
+
71
+ def run(command)
72
+ puts "Site root is: #{@base_dir}"
73
+
74
+ if %w(build setup preview).include?(command)
75
+ send(command)
76
+ else
77
+ puts "#{command} is not a valid StaticMatic command"
78
+ end
79
+ end
80
+
81
+ def determine_template_path(name, ext, dir = '')
82
+ # remove src path if present
83
+ dir.gsub! /^#{@src_dir}\//, ''
84
+
85
+ default_template_name = "#{name}.#{configuration.default_template_engine}"
86
+ default_template = File.join(@src_dir, dir, default_template_name)
87
+
88
+ if File.exists? default_template
89
+ default_template
90
+ else
91
+ context = File.join(@src_dir, dir, name)
92
+ possible_templates = Dir[context + '.*'].select do |fname|
93
+ extensions.include? File.extname(fname).sub(/^\./, '')
94
+ end
95
+
96
+ if possible_templates.count > 1
97
+ raise StaticMatic::AmbiguousTemplateError.new("#{name}#{ext}", possible_templates)
98
+ end
99
+
100
+ possible_templates.first
101
+ end
102
+ end
103
+
104
+ def expand_path(path_info)
105
+ dirname, basename = File.split(path_info)
106
+
107
+ extname = File.extname(path_info).sub(/^\./, '')
108
+ filename = basename.chomp(".#{extname}")
109
+
110
+ if extname.empty?
111
+ dir = File.join(dirname, filename)
112
+ is_dir = path_info[-1, 1] == '/'
113
+ if is_dir
114
+ dirname = dir
115
+ filename = 'index'
116
+ end
117
+ extname = 'html'
118
+ end
119
+
120
+ [ dirname, filename, extname ]
121
+ end
122
+
123
+ def configure_compass
124
+ Compass.configuration.project_path = @base_dir
125
+
126
+ compass_config_path = File.join(@base_dir, "config", "compass.rb")
127
+
128
+ if File.exists?(compass_config_path)
129
+ Compass.add_configuration(compass_config_path)
130
+ end
131
+
132
+ options = configuration.engine_options
133
+ compass_options = Compass.configuration.to_sass_engine_options
134
+
135
+ options['sass'] = compass_options.merge(options['sass'] || {})
136
+ options['scss'] = compass_options.merge(options['scss'] || {})
137
+ end
138
+
139
+ # TODO OPTIMIZE: caching, maybe?
140
+ def src_file_paths(*exts)
141
+ Dir["#{@src_dir}/**/*.{#{ exts.join(',') }}"].reject do |path|
142
+ # reject any files with a prefixed underscore, as
143
+ # well as any files in a folder with a prefixed underscore
144
+ path.split('/').map {|x| x.match('^\_')}.any?
145
+ end
146
+ end
147
+
148
+ end
149
+ end
@@ -0,0 +1,5 @@
1
+ ["installer", "configuration_defaults", "app_integration"].each do |file|
2
+ require File.join(File.dirname(__FILE__), "compass", file)
3
+ end
4
+
5
+ Compass.add_configuration(:staticmatic)
@@ -0,0 +1,21 @@
1
+ module Compass
2
+ module AppIntegration
3
+
4
+ module Staticmatic
5
+
6
+ extend self
7
+
8
+ def installer(*args)
9
+ Installer.new(*args)
10
+ end
11
+
12
+ def configuration
13
+ Compass::Configuration::Data.new('staticmatic').extend(ConfigurationDefaults)
14
+ end
15
+
16
+ end
17
+
18
+ register :staticmatic, 'Compass::AppIntegration::Staticmatic'
19
+
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ module Compass
2
+ module AppIntegration
3
+ module Staticmatic
4
+ module ConfigurationDefaults
5
+ def project_type_without_default
6
+ :staticmatic
7
+ end
8
+
9
+ def http_path
10
+ "/"
11
+ end
12
+
13
+ def sass_dir_without_default
14
+ "src"
15
+ end
16
+
17
+ def javascripts_dir_without_default
18
+ "build"
19
+ end
20
+
21
+ def css_dir_without_default
22
+ "build"
23
+ end
24
+
25
+ def images_dir_without_default
26
+ "build"
27
+ end
28
+
29
+ def default_http_images_path
30
+ "images"
31
+ end
32
+
33
+ def default_http_javascripts_path
34
+ "javascripts"
35
+ end
36
+
37
+ def default_cache_dir
38
+ ".sass-cache"
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,15 @@
1
+ module Compass
2
+ module AppIntegration
3
+ module Staticmatic
4
+ class Installer < Compass::Installers::ManifestInstaller
5
+ def completed_configuration
6
+ nil
7
+ end
8
+
9
+ def finalize(options = {})
10
+ puts manifest.welcome_message if manifest.welcome_message
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,56 @@
1
+ module StaticMatic
2
+ class Configuration
3
+ attr_accessor :preview_server
4
+ attr_accessor :preview_server_host
5
+ attr_accessor :preview_server_port
6
+ attr_accessor :ssl_enable
7
+ attr_accessor :ssl_private_key_path
8
+ attr_accessor :ssl_certificate_path
9
+
10
+ attr_accessor :site_dir
11
+ attr_accessor :build_dir
12
+
13
+ attr_accessor :use_extensions_for_page_links
14
+ attr_accessor :default_template_engine
15
+
16
+ attr_accessor :engine_options, :preview_engine_options
17
+ attr_accessor :reverse_ext_mappings
18
+
19
+ def initialize
20
+ self.preview_server = Rack::Handler::WEBrick
21
+ self.preview_server_host = "localhost"
22
+ self.preview_server_port = 4000
23
+
24
+ self.use_extensions_for_page_links = true
25
+ self.default_template_engine = 'haml'
26
+
27
+ self.site_dir = 'src'
28
+ self.build_dir = 'build'
29
+
30
+ self.engine_options = {
31
+ 'haml' => {}, 'sass' => {}, 'scss' => {},
32
+ }
33
+ self.preview_engine_options = self.engine_options.clone
34
+
35
+ # TODO: discover a way of auto-detecting these. one can hope.
36
+ self.reverse_ext_mappings = {
37
+ 'sass' => 'css',
38
+ 'scss' => 'css',
39
+ 'less' => 'css',
40
+
41
+ 'coffee' => 'js',
42
+
43
+ 'builder' => 'xml',
44
+ 'yajl' => 'json'
45
+ }
46
+
47
+ %w{
48
+ creole erb haml liquid radius mab markdown md
49
+ mediawiki mkd mw nokogiri rdoc rhtml slim textile wiki
50
+ }.each do |ext|
51
+ @reverse_ext_mappings[ext] = 'html'
52
+ end
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,108 @@
1
+ require 'aws/s3'
2
+ require 'yaml'
3
+
4
+ class StaticExe < Thor
5
+
6
+ desc "s3_deploy DIRECTORY", "Deploys your static website an Amazon's S3 bucket"
7
+ method_option :env, :type => :string, :aliases => "-e"
8
+ method_option :skip_build, :type => :boolean, :aliases => "-k"
9
+ def s3_deploy(directory = '.')
10
+ return if needs_setup? directory
11
+
12
+ invoke :build, directory unless options[:skip_build]
13
+
14
+ if build_files(directory).empty?
15
+ say 'Your build/ folder is empty', :red
16
+ say 'Nothing to do.'
17
+ return
18
+ end
19
+
20
+ amazon_config = YAML::load File.read(amazon_config_path directory)
21
+ env = options[:env] || 'development'
22
+ bucket_name = amazon_config['Buckets'][env]
23
+
24
+ connect_to_amazon_s3(amazon_config,env,bucket_name)
25
+
26
+ build_files(directory).each do |file|
27
+ contents = File.read file
28
+ s3path = file.sub(%r{^\./build/},'')
29
+
30
+ say " upload ", :cyan; say s3path
31
+ AWS::S3::S3Object.store(s3path, contents, bucket_name, :access => :public_read)
32
+ end
33
+ say 'Done.'
34
+ end
35
+
36
+ desc "s3_upload FILE [FILE ...]", "Upload select files to your Amazon S3 bucket."
37
+ method_option :directory, :type => :string, :aliases => "-d", :default => '.'
38
+ method_option :env, :type => :string, :aliases => "-e"
39
+ method_option :skip_build, :type => :boolean, :aliases => "-k"
40
+ def s3_upload(*files)
41
+ return if needs_setup? options[:directory]
42
+
43
+ if files.length == 0
44
+ say 'No files selected.', :red
45
+ say 'Nothing to do.'
46
+ return
47
+ end
48
+
49
+ amazon_config = YAML::load File.read(amazon_config_path '.')
50
+ env = options[:env] || 'development'
51
+ bucket_name = amazon_config['Buckets'][env]
52
+
53
+ connect_to_amazon_s3(amazon_config,env,bucket_name)
54
+
55
+ files.each do |file|
56
+
57
+ unless File.exists? file
58
+ say " Does not exist ", :red; say file; next
59
+ end
60
+
61
+ contents = File.read file
62
+ s3path = file.sub(%r{^(\./)?build/},'')
63
+
64
+ say " upload ", :cyan; say s3path
65
+ AWS::S3::S3Object.store(s3path, contents, bucket_name, :access => :public_read)
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def connect_to_amazon_s3(config,env,bucket_name)
72
+ say 'Uploading to Amazon S3...', :cyan
73
+ say 'Establishing connection to Amazon S3...'
74
+ AWS::S3::Base.establish_connection!(config['AccessKeys'])
75
+
76
+ say "Grabbing #{env} bucket '#{bucket_name}'"
77
+ buckets = AWS::S3::Service.buckets
78
+ unless buckets.map {|b| b.name}.include? bucket_name
79
+ say 'The bucket ', :red
80
+ say "'#{bucket_name}' "
81
+ say 'does not exist!', :red
82
+ say 'Nothing to do.'
83
+ return
84
+ end
85
+ end
86
+
87
+ def amazon_config_path(directory)
88
+ File.join(directory, 'config','amazon.yml')
89
+ end
90
+
91
+ def needs_setup?(directory)
92
+ config_file = amazon_config_path(directory)
93
+
94
+ unless File.exists? config_file
95
+ say 'You need an Amazon S3 config file.', :red
96
+ response = ask 'Would you like to generate one now? [Y/n]'
97
+
98
+ if response == '' || response.downcase == 'y'
99
+ copy_file lib_path('deployers/config/amazon.yml'), config_file
100
+ say 'Done.'
101
+ say 'Edit this config file to specify your Amazon S3 access keys, ' +
102
+ 'and then try again.'
103
+ say 'For more information, visit http://aws.amazon.com/s3/'
104
+ end
105
+ return true
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,7 @@
1
+ AccessKeys:
2
+ :access_key_id: Your-access-key-here
3
+ :secret_access_key: Your-secres-access-key-here
4
+
5
+ Buckets:
6
+ development: Your-development-bucket
7
+ production: Your-production-bucket
@@ -0,0 +1,17 @@
1
+ module StaticMatic
2
+ class Error < StandardError
3
+ attr_reader :line
4
+
5
+ attr_reader :filename
6
+
7
+ def initialize(lineno, filename, message)
8
+ @line = lineno
9
+ @filename = filename
10
+ @message = message
11
+ end
12
+
13
+ def message
14
+ "#{@filename}, line #{@line}: #{@message}"
15
+ end
16
+ end
17
+ end