Skip to content

Commit

Permalink
split runfile to multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Apr 18, 2024
1 parent 0fbe1e9 commit 04902a3
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ Gemfile.lock

/cache
/coverage
/debug.runfile
/dev
/doc
/gems
/spec/status.txt
/tasks/debug.runfile
/tmp

.sass-cache
Expand Down
112 changes: 3 additions & 109 deletions Runfile
Original file line number Diff line number Diff line change
@@ -1,118 +1,12 @@
require 'madness'
require 'sasstool'
require 'slim'
require 'madness/version'
require 'pretty_trace/enable-trim'
require 'debug' rescue nil

title "Madness Runfile"
summary "Runfile tasks for building the Madness gem"
version Madness::VERSION

import_gem 'runfile-tasks/gem'
import_gem 'runfile-tasks/docker', image: 'dannyben/madness', version: Madness::VERSION
import 'debug'
import 'tasks/*'

help 'Run specs'
action :spec do
system 'rspec && STANDALONE=1 rspec'
end

help 'Test the madness JSON schema'
action :schema do
file = 'lib/madness/templates/madness.yml'
command = "check-jsonschema --schemafile schemas/madness.json #{file}"
say "\n$ check-jsonschema bb`#{file}`"
success = system command
exit 1 unless success
end



help 'Generate public CSS'
usage 'css [--watch]'
option '--watch, -w', 'Watch for changes and regenerate'
action :css do |args|
if args['--watch']
exec "filewatcher --immediate 'app/styles/*.scss' 'bundle exec run css'"
else
target = "app/public/css"
Sasstool::Renderer.new("app/styles/main.scss").save target
puts "Saved #{target}"
end
end

help "Generate rouge CSS"
action :'css-rouge' do
puts 'Saving app/styles/_rouge.scss'
exec 'bundle exec rougify style github > app/styles/_rouge.scss'
end

help "Generate pandoc CSS"
action :'css-pandoc' do
File.write 'tmp/pandoc-style.css', '$highlighting-css$'
sample = <<~CODE
```ruby
puts "hello"
```
CODE
File.write 'tmp/pandoc-dummy.md', sample

puts 'Saving app/styles/_pandoc_code.scss'
system 'pandoc tmp/pandoc-dummy.md --metadata title=dummy --highlight-style=pygments --template=tmp/pandoc-style.css > app/styles/_pandoc_code.scss'
end

usage "(server|s) [--sample]"
help "Run server with spec docroot or the sample docroot"
option "--sample, -s", "Use the 'sample' folder instead of the fixture"
action :server, :s do |args|
folder = args['--sample'] ? 'sample' : 'spec/fixtures/docroot'
exec "bundle exec bin/madness server #{folder}"
end

help 'Extract fontello zip'
action :fontello do
system 'mkdir -p tmp/fontello'
zip = 'assets/fontello.zip'
system "unzip -j -o #{zip} -d tmp/fontello"
%w[eot svg ttf woff woff2].each do |ext|
system "cp tmp/fontello/fontello.#{ext} app/public/font/"
end

system 'cp tmp/fontello/fontello.css app/styles/_fontello.scss'
end

help "Count lines of code"
action :cloc do
system "cloc . --exclude-dir coverage,spec,examples"
end

help "Generate the screenshots animated gif"
action :screenshots do
puts "Saving assets/screenshots.gif"
exec "convert -delay 300 -loop 0 assets/screenshots/*.png assets/screenshots.gif"
end

help "Generate the site to /docs"
action :site do
# Use the README as a base, and do some TOC acrobatics to prevent the HTML
# generator from converting some TOC comments.
readme = File.read('README.md')
.gsub('<!-- TOC -->', '{{TOC_COMMENT}}')
.gsub('<!-- MADNESS_TOC -->', '<!-- TOC -->')
.sub(/\[!\[Gem Version\].*/, '')
.sub(/\[!\[Build Status\].*/, '')
.sub(/\[!\[Maintainability\].*/, '')

# Create the Madness page using Madness
content = Madness::MarkdownDocument.new(readme)
.to_html
.gsub '{{TOC_COMMENT}}', '&lt;!-- TOC --&gt;'

# Place the rendered HTML inside a slim template
Slim::Engine.set_options pretty: true
html = Slim::Template.new("assets/site/index.slim").render(nil, content: content)

# Export for GitHub pages
File.write 'site/index.html', html
puts 'Saved site/index.html'
end
shortcut 's', 'server'
5 changes: 5 additions & 0 deletions tasks/cloc.runfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
summary "Count lines of code"

action do
system "cloc . --exclude-dir coverage,spec,examples"
end
36 changes: 36 additions & 0 deletions tasks/css.runfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
summary 'CSS operations'

help 'Generate public CSS'
usage 'generate [--watch]'
option '--watch, -w', 'Watch for changes and regenerate'
action :generate do |args|
require 'sasstool'

if args['--watch']
exec "filewatcher --immediate 'app/styles/*.scss' 'bundle exec run css'"
else
target = "app/public/css"
Sasstool::Renderer.new("app/styles/main.scss").save target
puts "Saved #{target}"
end
end

help "Generate rouge CSS"
action :rouge do
puts 'Saving app/styles/_rouge.scss'
exec 'bundle exec rougify style github > app/styles/_rouge.scss'
end

help "Generate pandoc CSS"
action :pandoc do
File.write 'tmp/pandoc-style.css', '$highlighting-css$'
sample = <<~CODE
```ruby
puts "hello"
```
CODE
File.write 'tmp/pandoc-dummy.md', sample

puts 'Saving app/styles/_pandoc_code.scss'
system 'pandoc tmp/pandoc-dummy.md --metadata title=dummy --highlight-style=pygments --template=tmp/pandoc-style.css > app/styles/_pandoc_code.scss'
end
12 changes: 12 additions & 0 deletions tasks/fontello.runfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
summary 'Extract fontello zip'

action do
system 'mkdir -p tmp/fontello'
zip = 'assets/fontello.zip'
system "unzip -j -o #{zip} -d tmp/fontello"
%w[eot svg ttf woff woff2].each do |ext|
system "cp tmp/fontello/fontello.#{ext} app/public/font/"
end

system 'cp tmp/fontello/fontello.css app/styles/_fontello.scss'
end
9 changes: 9 additions & 0 deletions tasks/schema.runfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
summary 'Test the madness JSON schema'

action do
file = 'lib/madness/templates/madness.yml'
command = "check-jsonschema --schemafile schemas/madness.json #{file}"
say "\n$ check-jsonschema bb`#{file}`"
success = system command
exit 1 unless success
end
6 changes: 6 additions & 0 deletions tasks/screenshots.runfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
summary "Generate the screenshots animated gif"

action do
puts "Saving assets/screenshots.gif"
exec "convert -delay 300 -loop 0 assets/screenshots/*.png assets/screenshots.gif"
end
8 changes: 8 additions & 0 deletions tasks/server.runfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
summary "Run server with spec docroot or the sample docroot"

usage "[--sample]"
option "--sample, -s", "Use the 'sample' folder instead of the fixture"
action do |args|
folder = args['--sample'] ? 'sample' : 'spec/fixtures/docroot'
exec "bundle exec bin/madness server #{folder}"
end
28 changes: 28 additions & 0 deletions tasks/site.runfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
summary "Generate the site to /docs"

action do
require 'madness'
require 'slim'

# Use the README as a base, and do some TOC acrobatics to prevent the HTML
# generator from converting some TOC comments.
readme = File.read('README.md')
.gsub('<!-- TOC -->', '{{TOC_COMMENT}}')
.gsub('<!-- MADNESS_TOC -->', '<!-- TOC -->')
.sub(/\[!\[Gem Version\].*/, '')
.sub(/\[!\[Build Status\].*/, '')
.sub(/\[!\[Maintainability\].*/, '')

# Create the Madness page using Madness
content = Madness::MarkdownDocument.new(readme)
.to_html
.gsub '{{TOC_COMMENT}}', '&lt;!-- TOC --&gt;'

# Place the rendered HTML inside a slim template
Slim::Engine.set_options pretty: true
html = Slim::Template.new("assets/site/index.slim").render(nil, content: content)

# Export for GitHub pages
File.write 'site/index.html', html
puts 'Saved site/index.html'
end
5 changes: 5 additions & 0 deletions tasks/spec.runfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
summary 'Run specs using two separate configurations'

action do
system 'rspec && STANDALONE=1 rspec'
end

0 comments on commit 04902a3

Please sign in to comment.