lib/amp-html/railtie.rb in amp-html-1.1.0 vs lib/amp-html/railtie.rb in amp-html-1.2.0

- old
+ new

@@ -1,33 +1,39 @@ require 'rails/railtie' module AmpHtml class Railtie < ::Rails::Railtie + include ActionView::Helpers::AssetUrlHelper + initializer 'amp-html.mozaic' do Mozaic.configure do |config| ### Base - config.define_component 'amp/doctype' + config.define_component 'amp/doctype', '⚡': '' config.define_component 'amp/amp-link', rel: 'amphtml' do |options| - return false unless AmpHtml.configuration.split_view - href = options[:href].split('?').first - unless AmpHtml.configuration.split_view_default == 'amp' - options[:href] ||= "#{href}?#{{ amp: true }.to_query}" + if AmpHtml.configuration.split_view + href = options[:href].split('?').first + unless AmpHtml.configuration.split_view_default == 'amp' + options[:href] ||= "#{href}?#{{ amp: true }.to_query}" + else + options[:href] ||= href + end else - options[:href] ||= href + false end end config.define_component 'amp/canonical-link', rel: 'canonical' do |options| - return false unless AmpHtml.configuration.split_view - href = options[:href].split('?').first - if AmpHtml.configuration.split_view_default == 'amp' - options[:href] ||= "#{href}?#{{ amp: false }.to_query}" - else - options[:href] ||= href + if AmpHtml.configuration.split_view + href = options[:href].split('?').first + if AmpHtml.configuration.split_view_default == 'amp' + options[:href] ||= "#{href}?#{{ amp: false }.to_query}" + else + options[:href] ||= href + end end end config.define_component 'amp/head' config.define_component 'amp/components' @@ -99,9 +105,15 @@ end end initializer 'amp-html.assets' do Rails.application.config.assets.precompile += ['amp/application.css'] + Dir.glob Rails.root.join('app', 'assets', 'stylesheets', 'amp', 'packages', '**', '*') do |path| + next if File.directory? path + path = path.split('stylesheets').last + path.slice! 0 + Rails.application.config.assets.precompile += [path] + end end initializer 'amp-html.action_controller' do ActiveSupport.on_load :action_controller do include AmpHtml::BaseHelper