Skip to content

Instantly share code, notes, and snippets.

@tdreyno
Created May 15, 2014 14:01
Show Gist options
  • Save tdreyno/4a41d432fb073f13702b to your computer and use it in GitHub Desktop.
Save tdreyno/4a41d432fb073f13702b to your computer and use it in GitHub Desktop.
class Middleman::SplitterExtendion < ::Middleman::Extension
option :split_count, 2, 'How many files to split into'
option :split_files, nil, 'Which files to split'
register :splitter
def initialize(app, options_hash={}, &block)
super
require 'css_splitter/splitter'
end
helpers do
def split_stylesheet_link_tag(*sources)
options = sources.extract_options!
split_count = extensions[:splitter].options[:split_count]
sources.map do |source|
split_sources = (2..split_count).map { |index| "#{source}_split#{index}" }
split_sources << options
[
stylesheet_link_tag(source, options),
"<!--[if lte IE 9]>",
stylesheet_link_tag(*split_sources),
"<![endif]-->"
]
end.flatten.join("\n").html_safe
end
end
def split_file_paths
options[:split_files].inject({}) do |sum, name|
source = "stylesheets/#{name}"
sum["#{source}.css"] = (2..options[:split_count]).map { |index| "#{source}_split#{index}.css" }
sum
end
end
def manipulate_resource_list(resources)
resources + split_file_paths.inject([]) do |sum, (path, outputs)|
sum + outputs.map do |output|
SplitResource.new(
@app.sitemap,
output,
path
)
end
end
end
class SplitResource < ::Middleman::Sitemap::Resource
attr_accessor :output
def initialize(store, path, source_file)
# @request_path = ::Middleman::Util.normalize_path(source_file)
super(store, path, path)
end
def template?
true
end
def render(*)
$stderr.puts "Sup doooods" * 50
"Hello"
end
attr_reader :request_path
def binary?
false
end
def raw_data
{}
end
def ignored?
false
end
def metadata
@local_metadata.dup
end
end
end
activate :splitter, :split_files => [:test], :split_count => 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment