Skip to content

Commit

Permalink
Merge pull request #83 from jedcn/support-meta
Browse files Browse the repository at this point in the history
Supporting meta names and properties
  • Loading branch information
jedcn authored Apr 23, 2017
2 parents bc602e1 + f0e26a5 commit 1a3b8a6
Show file tree
Hide file tree
Showing 23 changed files with 523 additions and 402 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ Encoding:

FileName:
Exclude:
- Gemfile
- reveal-ck.gemspec
- lib/reveal-ck.rb
- files/reveal-ck/Guardfile

Metrics/BlockLength:
Exclude:
- bin/reveal-ck
- reveal-ck.gemspec
- spec/**/*.rb

Metrics/MethodLength:
Exclude:
- lib/reveal-ck/config.rb
- lib/reveal-ck/builders/create_index_html.rb
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ bugs are fixed.

### Added

* Nothing
* By default, the <head prefix="XYZ"/> value now supports
http://ogp.me/. This is configurable.

Additionally, it is now possible to supply <meta>s with properties
and names by putting entries into the config.yml.

Big thanks to @sue445 without which this wouldn't have happened.

See https://github.com/jedcn/reveal-ck/pull/82 for details.

### Changed

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ end

task default: :ci

task test: [:spec, :cucumber]
task test: %i[spec cucumber]
12 changes: 6 additions & 6 deletions bin/reveal-ck
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class RevealCKExecutable
command :generate do |c|
default_file = FileList['slides.*'].first
c.desc 'The file containing your slide content'
c.flag [:f, :file], default_value: default_file
c.flag %i[f file], default_value: default_file

c.desc 'The directory for generated slides. Default based on slide file.'
c.flag [:d, :dir]
c.flag %i[d dir]

c.action do |_, options, _|
slides_file = options[:file]
Expand Down Expand Up @@ -51,16 +51,16 @@ class RevealCKExecutable
command :serve, :server do |c|
default_file = FileList['slides.*'].first
c.desc 'The file containing your slide content'
c.flag [:f, :file], default_value: default_file
c.flag %i[f file], default_value: default_file

c.desc 'The directory to serve up. Default is based on slide file.'
c.flag [:d, :dir]
c.flag %i[d dir]

c.desc 'The port to serve on'
c.flag [:p, :port], default_value: 10_000
c.flag %i[p port], default_value: 10_000

c.desc 'The host to serve on'
c.flag [:h, :host], default_value: 'localhost'
c.flag %i[h host], default_value: 'localhost'

c.desc 'Exit after starting + n seconds (for testing only)'
c.flag ['test-quit-after-starting'], type: Integer
Expand Down
37 changes: 19 additions & 18 deletions examples/programmatic_slides.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative '../lib/reveal-ck'
require 'active_support/core_ext/string/strip'

intro_slide =
RevealCK::Slide.new(
Expand All @@ -9,11 +10,11 @@
link: 'http://hakim.se',
twitter: 'hakimel'
)
quote_content = <<eos
For years there has been a theory that millions of monkeys typing at
random on millions of typewriters would reproduce the entire works of
Shakespeare. The Internet has proven this theory to be untrue.
eos
quote_content = <<-EOS.strip_heredoc
For years there has been a theory that millions of monkeys typing at
random on millions of typewriters would reproduce the entire works of
Shakespeare. The Internet has proven this theory to be untrue.
EOS

quote_slide =
RevealCK::Slide.new(
Expand All @@ -33,19 +34,19 @@
height: '299'
)

sample_code = <<eos
function linkify( selector ) {
if( supports3DTransforms ) {
var nodes = document.querySelectorAll( selector );
for( var i = 0, len = nodes.length; i &lt; len; i++ ) {
var node = nodes[i];
if( !node.className ) {
node.className += ' roll';
}
}
}
}
eos
sample_code = <<-EOS.strip_heredoc
function linkify( selector ) {
if( supports3DTransforms ) {
var nodes = document.querySelectorAll( selector );
for( var i = 0, len = nodes.length; i &lt; len; i++ ) {
var node = nodes[i];
if( !node.className ) {
node.className += ' roll';
}
}
}
}
EOS

code_slide =
RevealCK::Slide.new(
Expand Down
66 changes: 66 additions & 0 deletions features/generate-with-config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,69 @@ Feature: The capabilities of config.yml
| slides/index.html |
And the file "slides/index.html" should have html matching the css:
| img[src*="reveal-js/reveal-parallax-1.jpg"] | the referenced image |

Scenario: Generating slides and specifying head_prefix
Given a file named "config.yml" with:
"""
head_prefix: 'og: http://ogp.me/ns#'
"""
Given a file named "slides.md" with:
"""
# Hello World
"""
When I run `reveal-ck generate`
Then the exit status should be 0
And the following files should exist:
| slides/index.html |
And the file "slides/index.html" should contain:
"""
<head prefix="og: http://ogp.me/ns#">
"""

Scenario: Generating slides with a template and og configs
Given a file named "config.yml" with:
"""
meta_properties:
og:title: "reveal-ck"
"""
Given a file named "slides.haml" with:
"""
%section
%p
Config
"""
When I run `reveal-ck generate`
Then the exit status should be 0
And the output should contain exactly "Generating slides for 'slides.haml'..\n"
And the following files should exist:
| slides/index.html |
And the file "slides/index.html" should contain:
"""
<meta property="og:title" content="reveal-ck" />
"""
And the file "slides/index.html" should contain:
"""
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article#">
"""

Scenario: Generating slides with a template and twitter configs
Given a file named "config.yml" with:
"""
meta_names:
twitter:title: "reveal-ck"
"""
Given a file named "slides.haml" with:
"""
%section
%p
Config
"""
When I run `reveal-ck generate`
Then the exit status should be 0
And the output should contain exactly "Generating slides for 'slides.haml'..\n"
And the following files should exist:
| slides/index.html |
And the file "slides/index.html" should contain:
"""
<meta name="twitter:title" content="reveal-ck" />
"""
2 changes: 1 addition & 1 deletion files/reveal-ck/Guardfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
notification :off

guard 'livereload' do
watch(/^slides\/index.html$/)
watch(%r{^slides/index.html$})
end
8 changes: 8 additions & 0 deletions files/reveal-ck/templates/index.html/head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
<meta name="author" content="<%= config.author %>">
<meta name="generator" content="reveal-ck <%= RevealCK::VERSION %>">

<% config.meta_properties.each do |property, content| %>
<meta property="<%= property %>" content="<%= content %>" />
<% end %>

<% config.meta_names.each do |name, content| %>
<meta name="<%= name %>" content="<%= content %>" />
<% end %>

<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />

Expand Down
2 changes: 1 addition & 1 deletion files/reveal-ck/templates/index.html/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html>
<html lang="en">
<head>
<head prefix="<%= head_prefix %>">
<%= head %>
</head>

Expand Down
1 change: 1 addition & 0 deletions lib/reveal-ck/builders/create_index_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def setup
index_html_file = "#{output_dir}/index.html"
task(index_html_file => slides_html) do
content = IndexHtml.new(slides_html: slides_html,
head_prefix: config.head_prefix,
template: template,
config: config).render
File.open(index_html_file, 'w') do |index_html|
Expand Down
6 changes: 4 additions & 2 deletions lib/reveal-ck/builders/index_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ module Builders
class IndexHtml
include Retrieve

attr_reader :template, :slides_html, :config
attr_reader :template, :slides_html, :head_prefix, :config

def initialize(args)
@template = retrieve(:template, args)
@slides_html = retrieve(:slides_html, args)
@head_prefix = retrieve(:head_prefix, args)
@config = retrieve(:config, args)
end

def render
scope = RevealCK::Render::Scope.new(dir: Dir.pwd, config: config)
tilt_template = Tilt.new(template)
locals = {
slides_html: slides_html
slides_html: slides_html,
head_prefix: head_prefix
}
tilt_template.render(scope, locals)
end
Expand Down
22 changes: 14 additions & 8 deletions lib/reveal-ck/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ def defaults
filter_defaults].reduce({}) { |acc, elem| acc.merge(elem) }
end

OPEN_GRAPH_PREFIX =
'og: http://ogp.me/ns# ' \
'fb: http://ogp.me/ns/fb# ' \
'article: http://ogp.me/ns/article#'.freeze

def core_defaults
{
'title' => 'Slides',
'description' => '',
'author' => '',
'theme' => 'black',
'transition' => 'default',
'data' => {

}
'title' => 'Slides',
'description' => '',
'author' => '',
'theme' => 'black',
'transition' => 'default',
'data' => {},
'meta_properties' => {},
'meta_names' => {},
'head_prefix' => OPEN_GRAPH_PREFIX
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/reveal-ck/presentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module RevealCK
class Presentation
include Retrieve
extend Forwardable
[:author, :title, :transition, :theme].each do |name|
%i[author title transition theme].each do |name|
def_delegators :@config, name, "#{name}=".to_sym
end

Expand Down
2 changes: 1 addition & 1 deletion rakelib/ci.rake
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
desc 'Run Continuous Integration'
task ci: [:spec, :rubocop, :cucumber]
task ci: %i[spec rubocop cucumber]
13 changes: 8 additions & 5 deletions reveal-ck.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
require File.join([File.dirname(__FILE__),'lib','reveal-ck','version.rb'])

$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require File.join([File.dirname(__FILE__), 'lib', 'reveal-ck', 'version.rb'])

Gem::Specification.new do |s|
s.date = '2017-01-14'
Expand All @@ -13,7 +14,7 @@ Gem::Specification.new do |s|
s.homepage = 'https://github.com/jedcn/reveal-ck'
s.summary = 'Create reveal.js presentations with Markdown.'
s.description =
'A command line interface for generating reveal.js presentations from markdown.'
'A cli for generating reveal.js presentations from markdown.'
#
# Runtime Dependencies
s.add_dependency 'docile', '1.1.5'
Expand All @@ -35,6 +36,7 @@ Gem::Specification.new do |s|

#
# Development Dependencies
s.add_development_dependency 'activesupport'
s.add_development_dependency 'aruba'
s.add_development_dependency 'codeclimate-test-reporter'
s.add_development_dependency 'cucumber'
Expand All @@ -45,13 +47,14 @@ Gem::Specification.new do |s|
s.add_development_dependency 'simplecov'

files = {
core: ['LICENSE', 'Rakefile', 'Gemfile'],
core: %w[LICENSE Rakefile Gemfile],
supporting: Dir.glob('files/**/*'),
lib: `git ls-files lib`.split("\n"),
rakelib: `git ls-files rakelib`.split("\n")
}

s.files = files[:core] + files[:lib] + files[:rakelib] + files[:supporting]
s.files = files[:core] + files[:lib] + files[:rakelib] +
files[:supporting]
s.test_files = `git ls-files -- {spec,features}/**/*`.split("\n")
s.executables = ['reveal-ck']
s.require_paths = ['lib']
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/reveal-ck/builders/create_slides_html_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module Builders
end

config = Config.new
config.requires = %w(json time)
config.requires = %w[json time]
application = Rake::Application.new
slides_html =
CreateSlidesHtml.new(slides_file: slides_file_initial,
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/reveal-ck/builders/creation_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setup

it 'defines a task on the application' do
args_expected_to_be_passed_to_rake = {
'creation_task_testing_class' => %w(foo bar)
'creation_task_testing_class' => %w[foo bar]
}
application = double
expect(application)
Expand Down
Loading

0 comments on commit 1a3b8a6

Please sign in to comment.