Add a 'module' for generating a MediaWiki template invocation

pull/1/head
Daniel Asher Resnick 3 years ago
parent 2b089cb516
commit 6a216d9b3e
  1. 19
      src/app.rb
  2. 60
      src/data/WikiSheet.erb
  3. 22
      src/lib/wiki.rb
  4. 16
      src/public/js/burning.js
  5. 5
      src/views/partials/main.erb

@ -5,6 +5,7 @@ require 'json'
require_relative 'lib/cache'
require_relative 'lib/pdf'
require_relative 'lib/data'
require_relative 'lib/wiki'
use Rack::Logger
set :bind, ENV['HOST']
@ -107,6 +108,16 @@ post '/model' do
"/get_file?file=#{key}&download_name=#{data['name']} Character Sheet.model"
end
post '/wiki' do
request.body.rewind
raw = request.body.readpartial(16 * 1024)
data = JSON.parse(raw)
key = "char-#{Time.now.strftime('%Y%m%d%H%M%S%L')}-#{rand(1...10000)}"
CACHE.store key, data
"/get_file?file=#{key}&download_name=#{data['name']} Character Sheet.wiki"
end
get '/get_file' do
data = nil
if params['download_name'].match(/\.pdf$/)
@ -116,6 +127,14 @@ get '/get_file' do
cs = CharSheet.new(data)
data = cs.render(logger, DATA)
end
elsif params['download_name'].match(/\.wiki$/)
content_type 'text/plain'
data = CACHE.delete(params['file'])
if data
wiki_sheet = WikiSheet.new(data)
p wiki_sheet
data = wiki_sheet.render
end
else
content_type 'application/octet-stream'
data = JSON.dump CACHE.delete(params['file'])

@ -0,0 +1,60 @@
{{BWCharacterSheet
|name=<%= name %>
|stock=<%= stock.capitalize %>
|age=<%= age %>
|homeland=
|features=
<% lifepaths.each.with_index do |lifepath, i| %>
|lifepath<%= i+1 %>=<%= lifepath %>
<% end %>
|fate=
|persona=
|deeds=
|belief1=
|belief2=
|belief3=
<%# |belief_special= %>
|instinct1=
|instinct2=
|instinct3=
|character_traits={{BWCharacterSheet/TraitList
<% for trait in traits.filter { |trait| trait[1] == "character" }%>
|<%= trait[0] %>
<% end %>
}}
|die_traits={{BWCharacterSheet/TraitList
<% for trait in traits.filter { |trait| trait[1] == "die" }%>
|<%= trait[0] %>
<% end %>
}}
|call-on_traits={{BWCharacterSheet/TraitList
<% for trait in traits.filter { |trait| trait[1] == "call_on" }%>
|<%= trait[0] %>
<% end %>
}}
|will=<%= stats["will"][0] %><%= stats["will"][1] %>,0,0,0,0,0
|perception=<%= stats["perception"][0] %><%= stats["perception"][1] %>,0,0,0,0,0
|power=<%= stats["power"][0] %><%= stats["power"][1] %>,0,0,0,0,0
|forte=<%= stats["forte"][0] %><%= stats["forte"][1] %>,0,0,0,0,0
|agility=<%= stats["agility"][0] %><%= stats["agility"][1] %>,0,0,0,0,0
|speed=<%= stats["speed"][0] %><%= stats["speed"][1] %>,0,0,0,0,0
|health=<%= attributes["health"][0] %><%= attributes["health"][1] %>,0,0,0,0,0,0
|steel=<%= attributes["steel"][0] %><%= attributes["steel"][1] %>,0,0,0,0,0,0
|circles=<%= attributes["circles"][0] %><%= attributes["circles"][1] %>,0,0,0,0,0,0
|resources=<%= attributes["resources"][0] %><%= attributes["resources"][1] %>,0,0,0,0,0,0
<%# |special_att1=Faith,B3,6,5,4,3,2,1 %>
<%# |special_att2=Grief,B3,6,5,4,3,2,1 %>
<% skills.each.with_index do |skill,i| %>
|skill<%= i+1 %>=<%= skill[0] %>,<%= skill[1] %><%= skill[2] %>,0,0,0,0,0,0
<% end %>
}}

@ -0,0 +1,22 @@
require 'erb'
class WikiSheet
include ERB::Util
attr_accessor :character
def initialize(character)
@character = character
end
def render()
load_template
ERB.new(@template, 0, '>').result_with_hash(@character)
end
private
def load_template
@template = File.read("data/WikiSheet.erb")
end
end

@ -1447,6 +1447,22 @@ function BurningCtrl($scope, $http, $modal, $timeout, settings, appropriateWeapo
});
}
$scope.downloadWikiSheet = function(){
var json = angular.toJson($scope.convertCurrentCharacterToStructForCharSheet(), true);
$http.post("/wiki", json).
success(function(data,status,headers,config){
console.log("huzzah, making wiki sheet succeeded. File URL: " + data);
var frame = document.getElementById("downloadframe");
if ( frame ){
frame.src = data;
}
}).
error(function(data,status,headers,config){
console.log("boo, making wiki sheet failed: " + data);
$scope.addAlert('tools', "Generating Wiki character sheet failed: " + data);
});
}
$scope.saveCurrentCharacterToServer = function(){
var nameWarn = "The character must have a name before it can be saved.";
if( $scope.name.length == 0 ){

@ -59,6 +59,11 @@
Download Character Model
</a>
</div>
<div class='col-md-3' ng-show="serverSettings.storageType != 'server'">
<a href='' ng-click='downloadWikiSheet()'>
Download Wiki Character Sheet
</a>
</div>
</div>
</div>
</div>

Loading…
Cancel
Save