Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a dev mode feature flag and some starter classes #915

Merged
merged 46 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
bfa4ec9
Add a dev mode feature flag and some starter classes
binford2k Nov 30, 2019
d846690
Barebones presentation render
binford2k Dec 3, 2019
ed8c140
Added slide context/option parsing
binford2k Dec 4, 2019
5dfa11f
start compiler implementation
binford2k Dec 5, 2019
9ad0f9c
Templatize slide generation
binford2k Dec 15, 2019
004f019
Handles section titles now
binford2k Dec 16, 2019
3f63bfe
Add slide template support (deprecate?)
binford2k Dec 16, 2019
2f451a6
Forms, variables, some markup
binford2k Dec 20, 2019
11308cf
Add some showoff extensions, glossary/notes/variables/etc
binford2k Dec 20, 2019
3ded36a
Per-slide compilation done except for i18n
binford2k Dec 24, 2019
c3102cc
Glossary and TOC complete now
binford2k Dec 29, 2019
7dee28a
added the first spec tests
binford2k Dec 30, 2019
6952f8f
Adding a few more tests
binford2k Dec 31, 2019
f1befdc
add a TOC spec
binford2k Dec 31, 2019
83caf0c
add notes and state specs
binford2k Dec 31, 2019
ba4cbc0
add section & slide specs
binford2k Dec 31, 2019
6f65fbe
started the specs for forms.
binford2k Jan 2, 2020
426bd95
added some more radio button testing
binford2k Jan 2, 2020
76d8d5f
finished form radio spec
binford2k Jan 3, 2020
551d055
add checkbox spec
binford2k Jan 3, 2020
ac9f2b9
fix form parsing bug
binford2k Jan 3, 2020
9e872fb
add specs for selects/text/textarea
binford2k Jan 3, 2020
0bc2937
make a list of directories work again
binford2k Jan 7, 2020
7797303
add i18n
binford2k Jan 7, 2020
6e0460e
@languages has not done anything since 2015
binford2k Jan 17, 2020
6787e5f
fix styling bug
binford2k Jan 24, 2020
41c74f7
`showoff static` now generates a complete presentation
binford2k Jan 24, 2020
6f77c55
print/static/supplemental all work now
binford2k Jan 26, 2020
b58fca2
Add specs for new functionality
binford2k Jan 26, 2020
bbe4e78
add optional verbose specs
binford2k Jan 26, 2020
9ca0b79
add working PDFkit support
binford2k Jan 26, 2020
17b870f
fix config specs
binford2k Jan 26, 2020
c741fc2
make locale work on Ruby <2.5
binford2k Jan 26, 2020
e19cfbb
add Ruby 2.0 to the test matrix
binford2k Jan 26, 2020
7b78c62
ensure all image paths start from presentation root
binford2k Jan 27, 2020
ae5cd96
Properly parse complex config files
binford2k Jan 27, 2020
2e09d9f
fix some garbled output
binford2k Jan 27, 2020
e390fb2
need pry during testing
binford2k Jan 27, 2020
e95142f
fix another usage of the :base parameter
binford2k Jan 27, 2020
9838fea
load templates from the gem properly
binford2k Jan 27, 2020
b74f333
Cleaning up more of the files prefix garbage
binford2k Jan 27, 2020
9effb26
static snapshots should be non-interactive
binford2k Jan 27, 2020
378614e
s/File/FileUtils/
binford2k Jan 31, 2020
901d30c
Make `showoff pdf` work
binford2k Jan 31, 2020
7a13cc0
Add a real logger class
binford2k Jan 31, 2020
6fb72bf
Extends support back to Ruby 2.0
binford2k Jan 31, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
22 changes: 21 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
language: ruby

sudo: false
bundler_args: --jobs 4 --retry 2 --without packaging documentation
before_install:
- git config --global user.name "TravisCI"
- git config --global user.email "[email protected]"
- sudo apt-get install wkhtmltopdf
script:
- "bundle exec rake $CHECK"
notifications:
email: false

matrix:
include:
- rvm: 2.0
env: "CHECK=spec"
gemfile: Gemfile.ruby-2.0.x

- rvm: 2.3
env: "CHECK=spec"

- rvm: 2.5
env: "CHECK=spec"

- rvm: 2.6
env: "CHECK=spec"
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ end

group :test do
gem 'rake'
gem 'rspec'
gem 'pry'
end

gem 'rack-contrib'
25 changes: 25 additions & 0 deletions Gemfile.ruby-2.0.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
source 'https://rubygems.org'

gemspec

gem 'public_suffix', '2.0.5'
gem 'i18n', '1.2.0'
gem 'nokogiri', '1.6.8.1'

group :development do
gem "turn"
gem "rack-test"
gem "pdf-inspector"
end

group :optional do
gem "pdfkit"
end

group :test do
gem 'rake'
gem 'rspec'
gem 'pry'
end

gem 'rack-contrib'
36 changes: 24 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,33 @@ task 'doc:website' => [:doc] do
end
end

desc "Run tests"
task :test do
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
# These tests are currently unmaintained.
# @todo: port and delete
#
# desc "Run tests"
# task :test do
# require 'rake/testtask'
#
# Rake::TestTask.new do |t|
# t.libs << 'lib'
# t.pattern = 'test/**/*_test.rb'
# t.verbose = false
# end
#
# suffix = "-n #{ENV['TEST']}" if ENV['TEST']
# sh "turn test/*_test.rb #{suffix}"
# end

desc "Run RSpec unit tests"
task :spec do
ENV["LOG_SPEC_ORDER"] = "true"
if ENV['verbose'] == 'true'
sh %{rspec #{ENV['TEST'] || ENV['TESTS'] || 'spec'} -fd}
else
sh %{rspec #{ENV['TEST'] || ENV['TESTS'] || 'spec'}}
end

suffix = "-n #{ENV['TEST']}" if ENV['TEST']
sh "turn test/*_test.rb #{suffix}"
end


desc 'Validate translation files'
task 'lang:check' do
require 'yaml'
Expand Down
31 changes: 27 additions & 4 deletions bin/showoff
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env ruby

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'showoff'
#require 'showoff'
require 'showoff/version'
require 'rubygems'
require 'fidget'
Expand All @@ -28,7 +28,8 @@ module Wrapper
The simplest use case is to run `showoff serve` from the directory containing
the showoff.json file.
desc

switch :dev, :desc => "Use the next-gen development version of Showoff"
switch :debug, :desc => "Show application backtraces on crash"

desc 'Create new showoff presentation'
long_desc 'This command helps start a new showoff presentation by setting up the proper directory structure for you. It takes the directory name you would like showoff to create for you.'
Expand Down Expand Up @@ -331,15 +332,37 @@ module Wrapper
arg_name 'name'
long_desc 'Creates a PDF version of the presentation as {name}.pdf'
command [:pdf] do |c|
c.desc 'JSON file used to describe presentation'
c.default_value "showoff.json"
c.flag [:f, :file, :pres_file]

c.desc 'Language code to generate.'
c.flag [:l, :lang, :language, :locale]

c.action do |global_options,options,args|
Showoff.do_static(['pdf'].concat args)
Showoff.do_static(['pdf'].concat(args), options)
end
end

pre do |global,command,options,args|
# Pre logic here
# Return true to proceed; false to abourt and not call the
# Return true to proceed; false to abort and not call the
# chosen command

if global[:debug]
ENV['GLI_DEBUG'] = 'true'
end

if global[:dev]
require 'showoff_ng'

if options[:file]
Showoff::Config.load(options[:file])
end
else
require 'showoff'
end

true
end

Expand Down
9 changes: 8 additions & 1 deletion lib/showoff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,8 @@ def self.do_static(args, opts = {})
["js", "css"].each { |dir|
FileUtils.copy_entry("#{my_path}/#{dir}", "#{out}/#{dir}", false, false, true)
}

# @todo: uh. I don't know how this ever worked. my_path is showoff and name is presentation.
# And copy the directory
Dir.glob("#{my_path}/#{name}/*").each { |subpath|
base = File.basename(subpath)
Expand All @@ -1533,7 +1535,12 @@ def self.do_static(args, opts = {})

# ..., copy all user-defined styles and javascript files
showoff.css_files.each { |path|
dest = File.join(file_dir, path)
dest = File.join(out, path)
FileUtils.mkdir_p(File.dirname(dest))
FileUtils.copy(path, dest)
}
showoff.js_files.each { |path|
dest = File.join(out, path)
FileUtils.mkdir_p(File.dirname(dest))
FileUtils.copy(path, dest)
}
Expand Down
106 changes: 106 additions & 0 deletions lib/showoff/compiler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
require 'tilt'
require 'tilt/erb'
require 'nokogiri'

class Showoff::Compiler
require 'showoff/compiler/form'
require 'showoff/compiler/variables'
require 'showoff/compiler/fixups'
require 'showoff/compiler/i18n'
require 'showoff/compiler/notes'
require 'showoff/compiler/glossary'
require 'showoff/compiler/downloads'
require 'showoff/compiler/table_of_contents'

def initialize(options)
@options = options
@profile = profile
end

# Configures Tilt with the selected engine and options.
#
# Returns render options profile hash
#
# Source:
# https://github.com/puppetlabs/showoff/blob/3f43754c84f97be4284bb34f9bc7c42175d45226/lib/showoff_utils.rb#L671-L720
# TODO: per slide profiles of render options
def profile
renderer = Showoff::Config.get('markdown')
profile = Showoff::Config.get(renderer)

begin
# Load markdown configuration
case renderer
when 'rdiscount'
Tilt.prefer Tilt::RDiscountTemplate, "markdown"

when 'maruku'
Tilt.prefer Tilt::MarukuTemplate, "markdown"
# Now check if we can go for latex mode
require 'maruku'
require 'maruku/ext/math'

if profile[:use_tex]
MaRuKu::Globals[:html_math_output_mathml] = false
MaRuKu::Globals[:html_math_output_png] = true
MaRuKu::Globals[:html_math_engine] = 'none'
MaRuKu::Globals[:html_png_engine] = 'blahtex'
MaRuKu::Globals[:html_png_dir] = profile[:png_dir]
MaRuKu::Globals[:html_png_url] = profile[:html_png_url]
end

when 'bluecloth'
Tilt.prefer Tilt::BlueClothTemplate, "markdown"

when 'kramdown'
Tilt.prefer Tilt::KramdownTemplate, "markdown"

when 'commonmarker', 'commonmark'
Tilt.prefer Tilt::CommonMarkerTemplate, "markdown"

when 'redcarpet', :default
Tilt.prefer Tilt::RedcarpetTemplate, "markdown"

else
raise 'Unsupported markdown renderer'

end
rescue LoadError
puts "ERROR: The #{renderer} markdown rendering engine does not appear to be installed correctly."
exit! 1
end

profile
end

# Compiles markdown and all Showoff extensions into the final HTML output and notes.
#
# @param content [String] markdown content.
# @return [[String, Array<String>]] A tuple of (html content, array of notes contents)
#
# @todo I think the update_image_paths() malarky is redundant. Verify that.
def render(content)
Variables::interpolate!(content)
I18n.selectLanguage!(content)

html = Tilt[:markdown].new(nil, nil, @profile) { content }.render
doc = Nokogiri::HTML::DocumentFragment.parse(html)

Form.render!(doc, @options)
Fixups.updateClasses!(doc)
Fixups.updateLinks!(doc)
Fixups.updateSyntaxHighlighting!(doc)
Fixups.updateCommandlineBlocks!(doc)
Fixups.updateImagePaths!(doc, @options)
Glossary.render!(doc)
Downloads.scanForFiles!(doc, @options)

# This call must be last in the chain because it separates notes from the
# content and returns them separately. If it's not last, then the notes
# won't have all the compilation steps applied to them.
#
# must pass in extra context because this will render markdown itself
Notes.render!(doc, @profile, @options)
end

end
91 changes: 91 additions & 0 deletions lib/showoff/compiler/downloads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# adds file download link processing
class Showoff::Compiler::Downloads

# Scan for file download links and move them to the state storage.
#
# @param doc [Nokogiri::HTML::DocumentFragment]
# The slide document
#
# @return [Nokogiri::HTML::DocumentFragment]
# The slide DOM with download links removed.
#
# @todo Should .download change meaning to 'make available on this slide'?
#
# @see
# https://github.com/puppetlabs/showoff/blob/3f43754c84f97be4284bb34f9bc7c42175d45226/lib/showoff.rb#L1056-L1073
def self.scanForFiles!(doc, options)
current = Showoff::State.get(:slide_count)
doc.search('p.download').each do |container|
links = container.text.gsub(/^\.download ?/, '')
links.split("\n").each do |line|
file, modifier = line.split
modifier ||= 'next' # @todo Is this still the proper default?

case modifier
when 'a', 'all', 'always', 'now'
self.pushFile(0, current, options[:name], file)
when 'p', 'prev', 'previous'
self.pushFile(current-1, current, options[:name], file)
when 'c', 'curr', 'current'
self.pushFile(current, current, options[:name], file)
when 'n', 'next'
self.pushFile(current+1, current, options[:name], file)
end
end

container.remove
end

doc
end


# Convention that index 0 represents files that are always available and every
# other index represents files whose visibility will be triggered on that slide.
#
# [
# {
# :enabled => false,
# :slides => [
# {:slidenum => num, :source => name, :file => file},
# {:slidenum => num, :source => name, :file => file},
# ],
# },
# {
# :enabled => false,
# :slides => [
# {:slidenum => num, :source => name, :file => file},
# {:slidenum => num, :source => name, :file => file},
# ],
# },
# ]


def self.pushFile(index, current, source, file)
record = Showoff::State.getAtIndex(:downloads, index) || {}
record[:enabled] ||= false
record[:slides] ||= []
record[:slides] << {:slidenum => current, :source => source, :file => file}

Showoff::State.setAtIndex(:downloads, index, record)
end

def self.enableFiles(index)
record = Showoff::State.getAtIndex(:downloads, index)
return unless record

record[:enabled] = true
Showoff::State.setAtIndex(:downloads, index, record)
end

def self.getFiles(index)
record = Showoff::State.getAtIndex(:downloads, index)

if (record and record[:enabled])
record[:slides]
else
[]
end
end

end
Loading