Class: Mill
- Inherits:
-
Object
- Object
- Mill
- Defined in:
- lib/mill/resources/feed.rb,
lib/mill.rb,
lib/mill/version.rb,
lib/mill/resource.rb,
lib/mill/navigator.rb,
lib/mill/file_types.rb,
lib/mill/resources/text.rb,
lib/mill/resources/image.rb,
lib/mill/resources/robots.rb,
lib/mill/resources/generic.rb,
lib/mill/resources/sitemap.rb,
lib/mill/resources/redirect.rb
Overview
Defined Under Namespace
Constant Summary collapse
- DefaultResourceClasses =
[ Resource::Text, Resource::Image, Resource::Generic, ]
- SchemasDir =
Path.new(__FILE__).dirname / 'mill' / 'schemas'
- DefaultSchemaTypes =
{ feed: SchemasDir / 'atom.xsd', sitemap: SchemasDir / 'sitemap.xsd', }
- VERSION =
'0.1'- FileTypes =
{ text: %w{ text/plain text/html }, image: %w{ image/gif image/jpeg image/png image/tiff image/vnd.microsoft.icon image/x-icon }, generic: %w{ text/css application/font-sfnt application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf application/javascript application/x-javascript text/javascript application/pdf }, }
Instance Attribute Summary collapse
-
#beta_ssh_location ⇒ Object
Returns the value of attribute beta_ssh_location.
-
#feed_resource ⇒ Object
Returns the value of attribute feed_resource.
-
#input_dir ⇒ Object
Returns the value of attribute input_dir.
-
#input_file_type_order ⇒ Object
Returns the value of attribute input_file_type_order.
-
#link_elem_attrs ⇒ Object
Returns the value of attribute link_elem_attrs.
-
#navigator ⇒ Object
Returns the value of attribute navigator.
-
#navigator_items ⇒ Object
Returns the value of attribute navigator_items.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
-
#redirects ⇒ Object
Returns the value of attribute redirects.
-
#resource_classes ⇒ Object
Returns the value of attribute resource_classes.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#robots_resource ⇒ Object
Returns the value of attribute robots_resource.
-
#schema_types ⇒ Object
Returns the value of attribute schema_types.
-
#shorten_uris ⇒ Object
Returns the value of attribute shorten_uris.
-
#site_control_date ⇒ Object
Returns the value of attribute site_control_date.
-
#site_email ⇒ Object
Returns the value of attribute site_email.
-
#site_title ⇒ Object
Returns the value of attribute site_title.
-
#site_uri ⇒ Object
Returns the value of attribute site_uri.
-
#sitemap_resource ⇒ Object
Returns the value of attribute sitemap_resource.
-
#ssh_location ⇒ Object
Returns the value of attribute ssh_location.
Instance Method Summary collapse
- #add_resource(resource) ⇒ Object
- #build ⇒ Object
- #clean ⇒ Object
- #feed_author_email ⇒ Object
- #feed_author_name ⇒ Object
- #feed_author_uri ⇒ Object
- #feed_generator ⇒ Object
- #file_type(file) ⇒ Object
- #find_resource(uri) ⇒ Object
- #home_resource ⇒ Object
-
#initialize(params = {}) ⇒ Mill
constructor
A new instance of Mill.
- #load ⇒ Object
- #load_others ⇒ Object
- #public_resources ⇒ Object
- #publish(mode = :final) ⇒ Object
- #schema_for_type(type) ⇒ Object
- #server ⇒ Object
- #tag_uri ⇒ Object
- #update_resource(resource) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Mill
Returns a new instance of Mill.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mill.rb', line 64 def initialize(params={}) @resource_classes = {} @resources = [] @resources_by_uri = {} @schema_types = {} @schemas = {} @shorten_uris = true @input_file_type_order = [:generic, :image, :text] @link_elem_attrs = %w{ img/@src script/@src a/@href link/@href stylesheet/@href } params.each { |k, v| send("#{k}=", v) } end |
Instance Attribute Details
#beta_ssh_location ⇒ Object
Returns the value of attribute beta_ssh_location.
40 41 42 |
# File 'lib/mill.rb', line 40 def beta_ssh_location @beta_ssh_location end |
#feed_resource ⇒ Object
Returns the value of attribute feed_resource.
36 37 38 |
# File 'lib/mill.rb', line 36 def feed_resource @feed_resource end |
#input_dir ⇒ Object
Returns the value of attribute input_dir.
30 31 32 |
# File 'lib/mill.rb', line 30 def input_dir @input_dir end |
#input_file_type_order ⇒ Object
Returns the value of attribute input_file_type_order.
48 49 50 |
# File 'lib/mill.rb', line 48 def input_file_type_order @input_file_type_order end |
#link_elem_attrs ⇒ Object
Returns the value of attribute link_elem_attrs.
49 50 51 |
# File 'lib/mill.rb', line 49 def link_elem_attrs @link_elem_attrs end |
#navigator ⇒ Object
Returns the value of attribute navigator.
43 44 45 |
# File 'lib/mill.rb', line 43 def navigator @navigator end |
#navigator_items ⇒ Object
Returns the value of attribute navigator_items.
44 45 46 |
# File 'lib/mill.rb', line 44 def navigator_items @navigator_items end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
31 32 33 |
# File 'lib/mill.rb', line 31 def output_dir @output_dir end |
#redirects ⇒ Object
Returns the value of attribute redirects.
47 48 49 |
# File 'lib/mill.rb', line 47 def redirects @redirects end |
#resource_classes ⇒ Object
Returns the value of attribute resource_classes.
45 46 47 |
# File 'lib/mill.rb', line 45 def resource_classes @resource_classes end |
#resources ⇒ Object
Returns the value of attribute resources.
41 42 43 |
# File 'lib/mill.rb', line 41 def resources @resources end |
#robots_resource ⇒ Object
Returns the value of attribute robots_resource.
38 39 40 |
# File 'lib/mill.rb', line 38 def robots_resource @robots_resource end |
#schema_types ⇒ Object
Returns the value of attribute schema_types.
46 47 48 |
# File 'lib/mill.rb', line 46 def schema_types @schema_types end |
#shorten_uris ⇒ Object
Returns the value of attribute shorten_uris.
42 43 44 |
# File 'lib/mill.rb', line 42 def shorten_uris @shorten_uris end |
#site_control_date ⇒ Object
Returns the value of attribute site_control_date.
35 36 37 |
# File 'lib/mill.rb', line 35 def site_control_date @site_control_date end |
#site_email ⇒ Object
Returns the value of attribute site_email.
34 35 36 |
# File 'lib/mill.rb', line 34 def site_email @site_email end |
#site_title ⇒ Object
Returns the value of attribute site_title.
32 33 34 |
# File 'lib/mill.rb', line 32 def site_title @site_title end |
#site_uri ⇒ Object
Returns the value of attribute site_uri.
33 34 35 |
# File 'lib/mill.rb', line 33 def site_uri @site_uri end |
#sitemap_resource ⇒ Object
Returns the value of attribute sitemap_resource.
37 38 39 |
# File 'lib/mill.rb', line 37 def sitemap_resource @sitemap_resource end |
#ssh_location ⇒ Object
Returns the value of attribute ssh_location.
39 40 41 |
# File 'lib/mill.rb', line 39 def ssh_location @ssh_location end |
Instance Method Details
#add_resource(resource) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/mill.rb', line 115 def add_resource(resource) resource.mill = self begin # ;;warn "loading #{resource.class.type} resource #{resource.uri} as #{resource.class}" resource.load rescue => e warn "Failed to load resource #{resource.uri} (#{resource.class}): #{e}" raise end @resources << resource end |
#build ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/mill.rb', line 201 def build warn "building #{@resources.length} resources..." @resources.each do |resource| begin resource.build rescue => e warn "Failed to build resource #{resource.uri}: #{e}" raise end end end |
#clean ⇒ Object
179 180 181 182 |
# File 'lib/mill.rb', line 179 def clean @output_dir.rmtree if @output_dir.exist? @output_dir.mkpath end |
#feed_author_email ⇒ Object
171 172 173 |
# File 'lib/mill.rb', line 171 def @site_email end |
#feed_author_name ⇒ Object
163 164 165 |
# File 'lib/mill.rb', line 163 def @site_title end |
#feed_author_uri ⇒ Object
167 168 169 |
# File 'lib/mill.rb', line 167 def @site_uri end |
#feed_generator ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/mill.rb', line 153 def feed_generator [ 'Mill', { uri: Addressable::URI.parse('http://github.com/jslabovitz/mill'), version: Mill::VERSION, } ] end |
#file_type(file) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/mill.rb', line 102 def file_type(file) if file.directory? || file.basename.to_s[0] == '.' return :ignore else MIME::Types.of(file.to_s).each do |mime_type| if (type = @file_types[mime_type.content_type]) return type end end end nil end |
#find_resource(uri) ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/mill.rb', line 131 def find_resource(uri) uri = Addressable::URI.parse(uri.to_s) unless uri.kind_of?(Addressable::URI) resource = @resources_by_uri[uri] if resource.nil? && @shorten_uris uri.path = uri.path.sub(%r{\.html$}, '') resource = @resources_by_uri[uri] end resource end |
#home_resource ⇒ Object
141 142 143 |
# File 'lib/mill.rb', line 141 def home_resource find_resource('/') or raise "Can't find home" end |
#load ⇒ Object
184 185 186 187 188 189 190 191 |
# File 'lib/mill.rb', line 184 def load warn "loading resources..." build_file_types build_resource_classes build_schemas load_files load_others end |
#load_others ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/mill.rb', line 193 def load_others make_redirects make_feed make_sitemap make_robots make_navigator end |
#public_resources ⇒ Object
175 176 177 |
# File 'lib/mill.rb', line 175 def public_resources @resources.select(&:public) end |
#publish(mode = :final) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/mill.rb', line 213 def publish(mode=:final) location = case mode when :final @ssh_location when :beta @beta_ssh_location else raise "Unknown publish mode: #{mode.inspect}" end raise "Must specify SSH location" unless location system('rsync', # '--dry-run', '--archive', '--delete-after', '--progress', # '--verbose', @output_dir.to_s + '/', location, ) end |
#schema_for_type(type) ⇒ Object
145 146 147 |
# File 'lib/mill.rb', line 145 def schema_for_type(type) @schemas[type] end |
#server ⇒ Object
234 235 236 237 238 239 |
# File 'lib/mill.rb', line 234 def server SimpleServer.run!( root: @output_dir, multihosting: false, ) end |
#tag_uri ⇒ Object
149 150 151 |
# File 'lib/mill.rb', line 149 def tag_uri "tag:#{@site_uri.host.downcase},#{@site_control_date}:" end |
#update_resource(resource) ⇒ Object
127 128 129 |
# File 'lib/mill.rb', line 127 def update_resource(resource) @resources_by_uri[resource.uri] = resource end |