amp-html 1.0.1 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3fe2287cdfe4c4e9affc65691e2cd219a08680b27e8aa437119ec78b011a44e
4
- data.tar.gz: d3953a2516a7a75a89045629535644e35e150913d3344bae5dde63168b8556fb
3
+ metadata.gz: 545c3ea0572405fdb0d68675d7eeabc50ec1b7dcf39142f60781f7e6a7f18f04
4
+ data.tar.gz: 2674f97ab93a296c165c861f48edad638b5ad172ac2029ccaf77045faa7bd47e
5
5
  SHA512:
6
- metadata.gz: 5036faefbf235d67e07aa407f6a0f27d38c7e5b86a9afe0cb5426ce3ccedc42c3bbe985ef88988d3572ef098107870f659c7dbd70679d7ba30d3087a309020d7
7
- data.tar.gz: 62d92bf61441f2ebb85f3bc7428b4c4a55dbc91f6c90878b884531d6388702066b9961a5e4da0857c3d998c1fffa80fcd9b9fd59242ec2c449e3603711c51528
6
+ metadata.gz: 179936be1a66a8449d283f8e9ee5644a2d903e16d0dae2bd752e619d2bedfb3a73347d852688f3f88eb4de245c083a659d150c91e94773ba827e8af8f079c1ae
7
+ data.tar.gz: 8d86222cce4f0d7189dc0ca3dade379a3fee5ed73c9e19a4946d7ad02de1430ce396fd3747315ab94b1ee6e6c92946dcfe51cf4df1eb5f46ddfb51213c3ce12e
@@ -4,6 +4,11 @@
4
4
 
5
5
  * nothing yet
6
6
 
7
+ ### 1.1.0 - 2018/01/17
8
+
9
+ * features
10
+ * new controller methods (`amp=`, `amp_path`)
11
+
7
12
  ### 1.0.1 - 2018/01/14
8
13
 
9
14
  * enhancements
data/README.md CHANGED
@@ -8,14 +8,14 @@ amp-html is a universal solution to integrate the [AMP Project](https://www.ampp
8
8
 
9
9
  Use the powerful features of AMP to make your Rails app consistently fast, beautiful and high-performing across devices and distribution platforms.
10
10
 
11
- [**Follow the Getting Started Guide**](https://github.com/jonhue/amp-html/wiki/Getting-started)
11
+ [**Follow the Getting Started Guide**](https://github.com/jonhue/amp-html/wiki/Getting-started), [Demo](https://hello-amp.herokuapp.com)
12
12
 
13
13
  ---
14
14
 
15
15
  ## Navigation
16
16
 
17
17
  * [Information](#information)
18
- * [Quick info (Latest release, Dependencies)](#quick-info)
18
+ * [Quick info](#quick-info)
19
19
  * [The amp-html wiki](#the-amp-html-wiki)
20
20
  * [Bug reports](#bug-reports)
21
21
  * [Example applications](#example-applications)
@@ -26,8 +26,15 @@ Use the powerful features of AMP to make your Rails app consistently fast, beaut
26
26
  * [Generators](#generators)
27
27
  * [Test and validate AMP](#test-and-validate-amp)
28
28
  * [Usage](#usage)
29
+ * [Views](#views)
30
+ * [Controllers](#controllers)
29
31
  * [SplitView](#splitview)
30
32
  * [Guides](#guides)
33
+ * [Getting started](#getting-started)
34
+ * [Utilizing features](#utilizing-features)
35
+ * [Essentials](#essentials)
36
+ * [Powerful features](#powerful-features)
37
+ * [Testing](#testing)
31
38
  * [Components](#components)
32
39
  * [Configuration](#configuration)
33
40
  * [To Do](#to-do)
@@ -40,7 +47,7 @@ Use the powerful features of AMP to make your Rails app consistently fast, beaut
40
47
 
41
48
  ### Quick info
42
49
 
43
- #### Latest release: 1.0.0
50
+ #### Latest release: 1.0.1
44
51
 
45
52
  [**Changelog**](CHANGELOG.md), [Grab it from Rubygems](https://rubygems.org/gems/amp-html)
46
53
 
@@ -121,16 +128,77 @@ Lastly, make sure to remove Turbolinks from your apps asset pipeline (`app/asset
121
128
 
122
129
  ## Usage
123
130
 
131
+ ### Views
132
+
133
+ You can check whether your document is using AMP or not by using the `amp?` method:
134
+
135
+ ```haml
136
+ - if amp?
137
+ = component 'amp/mustache' do
138
+ -# ...
139
+ ```
140
+
141
+ **Note:** This method is also available at controller level.
142
+
143
+ When you are using [SplitView](#splitview) along with media/form/etc. elements, you don't have to use `amp?` to render the appropriate element. amp-html automatically overrides the default Rails helpers if your document is using AMP.
144
+
145
+ ### Controllers
146
+
147
+ If you are using [SplitView](#splitview), you are able to override the default format (`html`/`amp`) by passing the `amp` parameter. However in a lot of cases you want to specify the format from within the path of the URL:
148
+
149
+ ```ruby
150
+ class PostsController < ApplicationController
151
+
152
+ def index
153
+ amp_path # to use `'amp'` as path
154
+ amp_path 'custom-path' # to use `'custom-path'` as path
155
+ end
156
+
157
+ end
158
+ ```
159
+
160
+ You are also able to manually enable or disable AMP for a specific controller action:
161
+
162
+ ```ruby
163
+ class PostsController < ApplicationController
164
+
165
+ def index
166
+ amp # to enable AMP
167
+ amp = false # to disable AMP
168
+ end
169
+
170
+ end
171
+ ```
172
+
124
173
  ### SplitView
125
174
 
175
+ SplitView allows you to serve `html` and `amp` versions of your views. To get started, enable and configure SplitView:
176
+
177
+ ```ruby
178
+ AmpHtml.configure do |config|
179
+ config.split_view = true
180
+ config.split_view_default = 'amp'
181
+ end
182
+ ```
183
+
184
+ Now you can use amp-html's [view](#views) and [controller](#controllers) methods to determine whether a document uses `html` or `amp` as format.
185
+
126
186
  ---
127
187
 
128
188
  ## Guides
129
189
 
190
+ Whether you are just getting started or you are looking to implement some of the powerful features of amp-html, the guides in the amp-html wiki are here to your rescue.
191
+
192
+ https://github.com/jonhue/amp-html/wiki/Guides
193
+
130
194
  ---
131
195
 
132
196
  ## Components
133
197
 
198
+ amp-html is component based. You can learn more about components and find the full reference in the amp-html wiki.
199
+
200
+ https://github.com/jonhue/amp-html/wiki/Docs
201
+
134
202
  ---
135
203
 
136
204
  ## Configuration
@@ -21,5 +21,13 @@ module AmpHtml
21
21
  return File.binread(File.join(Rails.application.assets_manifest.dir, asset))
22
22
  end
23
23
 
24
+ def amp= value = true
25
+ params[:amp] = value
26
+ end
27
+
28
+ def amp_path scope = 'amp'
29
+ params[:amp] = true if request.fullpath.include?("/#{scope}")
30
+ end
31
+
24
32
  end
25
33
  end
@@ -1,6 +1,6 @@
1
- <% if options[:components]&.include? :form %><script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
1
+ <% if options[:components]&.include? :audio %><script async custom-element="amp-audio" src="https://cdn.ampproject.org/v0/amp-audio-0.1.js"></script>
2
+ <% elsif options[:components]&.include? :font %><script async custom-element="amp-font" src="https://cdn.ampproject.org/v0/amp-font-0.1.js"></script>
3
+ <% elsif options[:components]&.include? :form %><script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
2
4
  <% elsif options[:components]&.include? :mustache %><script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script>
3
5
  <% elsif options[:components]&.include? :selector %><script async custom-element="amp-selector" src="https://cdn.ampproject.org/v0/amp-selector-0.1.js"></script>
4
- <% elsif options[:components]&.include? :audio %><script async custom-element="amp-audio" src="https://cdn.ampproject.org/v0/amp-audio-0.1.js"></script>
5
- <% elsif options[:components]&.include? :video %><script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script>
6
- <% elsif options[:components]&.include? :font %><script async custom-element="amp-font" src="https://cdn.ampproject.org/v0/amp-font-0.1.js"></script><% end %>
6
+ <% elsif options[:components]&.include? :video %><script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script><% end %>
@@ -1,2 +1 @@
1
- <%= content_tag 'amp-font', options do %>
2
- <% end %>
1
+ <%= content_tag 'amp-font', options %>
@@ -1 +1 @@
1
- <%= tag 'amp-img', options %>
1
+ <%= content_tag 'amp-img', options %>
@@ -12,16 +12,20 @@ module AmpHtml
12
12
  config.define_component 'amp/doctype'
13
13
  config.define_component 'amp/amp-link', rel: 'amphtml' do |options|
14
14
  return false unless AmpHtml.configuration.split_view
15
- options[:href] = options[:href].split('?').first
15
+ href = options[:href].split('?').first
16
16
  unless AmpHtml.configuration.split_view_default == 'amp'
17
- options[:href] = "#{options[:href]}?#{{ amp: true }.to_query}"
17
+ options[:href] ||= "#{href}?#{{ amp: true }.to_query}"
18
+ else
19
+ options[:href] ||= href
18
20
  end
19
21
  end
20
22
  config.define_component 'amp/canonical-link', rel: 'canonical' do |options|
21
23
  return false unless AmpHtml.configuration.split_view
22
- options[:href] = options[:href].split('?').first
24
+ href = options[:href].split('?').first
23
25
  if AmpHtml.configuration.split_view_default == 'amp'
24
- options[:href] = "#{options[:href]}?#{{ amp: false }.to_query}"
26
+ options[:href] ||= "#{href}?#{{ amp: false }.to_query}"
27
+ else
28
+ options[:href] ||= href
25
29
  end
26
30
  end
27
31
  config.define_component 'amp/head'
@@ -1,5 +1,5 @@
1
1
  module AmpHtml
2
2
 
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1.0'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amp-html
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Hübotter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-14 00:00:00.000000000 Z
11
+ date: 2018-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties