Skip to content
This repository has been archived by the owner on Sep 23, 2019. It is now read-only.

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhue committed Jan 19, 2018
1 parent 964838c commit c422893
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 46 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

### master

* nothing yet
* features
* automatically load controller action specific stylesheets
* enhancements
* allow options to be passed to the `amp/doctype` component
* bugfixes
* fix `amp/canonical-link` component for apps without SplitView

### 1.1.0 - 2018/01/17

Expand Down
4 changes: 4 additions & 0 deletions DEPRECATIONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Deprecations

### master

* remove `inherit_stylesheets` configuration option

### 1.0.0 - 2018/01/14

* deprecated previously available view helper methods
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,10 @@ You can configure amp-html by passing a block to `configure`. This can be done i

```ruby
AmpHtml.configure do |config|
config.inherit_stylesheets = false
config.split_view = false
end
```

* `inherit_stylesheets` Use your regular stylesheets bundled with `app/assets/stylesheets/application.css` in your AMP views. Takes a boolean. Defaults to `false`.
* `split_view` Enable SplitView to allow for AMP enabled and AMP disabled versions of your views. Takes a boolean. Defaults to `false`.
* `split_view_default` The default view version if no `amp` param is present in the request. Must be either `'amp'` or `'html'`. Defaults to `'amp'`.

Expand Down
23 changes: 14 additions & 9 deletions app/helpers/amp_html/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ def amp?
end
end

# Fix for accessing AMP assets in different environments
def get_asset name
if Rails.application.assets
asset = Rails.application.assets[name]
return asset.to_s if asset
end
asset = Rails.application.assets_manifest.assets[name]
return nil unless asset
return File.binread(File.join(Rails.application.assets_manifest.dir, asset))
def amp_packaged_css
global = Rails.application.assets.find_asset('amp/application.css').to_s
package = Rails.application.assets.find_asset("amp/packages/#{params[:controller]}/#{action_name}.css").to_s
# if Rails.env.development?
# ::Sass::Engine.new(global + package, {
# syntax: :scss,
# cache: false,
# read_cache: false,
# style: :compressed
# }).render
# else
# global + package
# end
global + package
end

def amp= value = true
Expand Down
4 changes: 2 additions & 2 deletions app/views/mozaic/amp/_doctype.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<html >
<%= content_tag 'html', options do %>
<%= block %>
</html>
<% end %>
3 changes: 1 addition & 2 deletions app/views/mozaic/amp/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
<%= get_asset 'application.css' if AmpHtml.configuration.inherit_stylesheets %>
<%= get_asset 'amp/application.css' %>
<%= amp_packaged_css %>
<%= area :css %>
</style>
2 changes: 0 additions & 2 deletions lib/amp-html/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ def self.configure

class Configuration

attr_accessor :inherit_stylesheets
attr_accessor :split_view
attr_accessor :split_view_default

def initialize
@inherit_stylesheets = false
@split_view = false
@split_view_default = 'amp'
end
Expand Down
21 changes: 14 additions & 7 deletions lib/amp-html/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Railtie < ::Rails::Railtie

### 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
Expand All @@ -20,12 +20,13 @@ class Railtie < ::Rails::Railtie
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'
Expand Down Expand Up @@ -101,6 +102,12 @@ class Railtie < ::Rails::Railtie

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
Expand Down
3 changes: 2 additions & 1 deletion lib/generators/amp_html_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def create_layout
end

def create_assets
template 'application.css', 'app/assets/stylesheets/amp/application.css'
template 'application.sass', 'app/assets/stylesheets/amp/application.sass'
template '.keep-file', 'app/assets/stylesheets/amp/packages/.keep'
end

def create_initializer
Expand Down
Empty file.
15 changes: 0 additions & 15 deletions lib/generators/templates/application.css

This file was deleted.

6 changes: 6 additions & 0 deletions lib/generators/templates/application.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This is a manifest file that'll be compiled into amp/application.css, which will include all the files
// listed below.
//
// This manifest is only used for application wide styles. Add view specific files to the /packages subfolder.
//
// Don't use `require_tree .` in this file, as that would include all view specific files in this manifest.
4 changes: 0 additions & 4 deletions lib/generators/templates/initializer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
AmpHtml.configure do |config|

# Use your regular stylesheets bundled with `app/assets/stylesheets/application.css` in your AMP views. Takes a boolean.
# config.inherit_stylesheets = false


### SplitView

# Enable SplitView to allow for AMP enabled and AMP disabled versions of your views. Takes a boolean.
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/layout.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<%%= component 'amp/head' %>
<title>Hello AMP world</title>
<%% if AmpHtml.configuration.split_view %><%%= component 'amp/canonical-link', href: request.original_url %><%% end %>
<%%= component 'amp/canonical-link', href: request.original_url %>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<%%= csrf_meta_tags %>
</head>
Expand Down

0 comments on commit c422893

Please sign in to comment.