def run(self): super(_LpBuildButtonDirective, self).run() _assert_has_no_content(self) addQuestionToDB(self) # Process options ##=============== self.options["include"] = [ x.strip() for x in self.options.get("include", "") ] # If a language isn't provided, derive it from the file's name. env = self.state.document.settings.env self.options.setdefault("language", get_lexer(filename=env.docname).mimetypes[0]) self.options.setdefault("timelimit", 25000) self.options.setdefault("builder", "JOBE") self.options["source_path"] = env.docname lp_node = LpNode(self.options, rawsource=self.block_text) lp_node.source, lp_node.line = self.state_machine.get_source_and_line( self.lineno) # Insert the question number. self.content.append(self.options["qnumber"], "lp") # Parse it, since the number may be a role. self.state.nested_parse(self.content, self.content_offset, lp_node) return [lp_node]
def run(self): super(_LpBuildButtonDirective, self).run() _assert_has_no_content(self) addQuestionToDB(self) # Gather arguments. id_ = self.options["divid"] # Process options ##=============== self.options["include"] = [ x.strip() for x in self.options.get("include", "") ] # If a language isn't provided, derive it from the file's name. env = self.state.document.settings.env self.options.setdefault("language", get_lexer(filename=env.docname).mimetypes[0]) self.options.setdefault("timelimit", 25000) self.options.setdefault("builder", "JOBE") # Generate HTML for the lp build directive. Pass the language, so client-side JS can use the correct syntax highligher. html = """<div class="runestone"> <input type="button" value="Save and run" class="btn btn-success" data-component="lp_build" data-lang="{}" id="{}" /> <br /> <textarea readonly id="lp-result"></textarea> <br /> <div></div> </div>""".format(self.options["language"], id_) addHTMLToDB( id_, self.options["basecourse"], html, json.dumps( dict( # Provide these to the server, indicating how to build. language=self.options["language"], builder=self.options["builder"], timelimit=self.options["timelimit"], include=self.options["include"], source_path=env.docname, sphinx_base_path=env.app.confdir, )), ) raw_node = nodes.raw(self.block_text, html, format="html") raw_node.source, raw_node.line = self.state_machine.get_source_and_line( self.lineno) return [raw_node]
def run(self): super(_LpBuildButtonDirective, self).run() _assert_has_no_content(self) addQuestionToDB(self) # Gather arguments. id_ = self.options['divid'] # Process options ##=============== self.options['include'] = [x.strip() for x in self.options.get('include', '')] # If a language isn't provided, derive it from the file's name. env = self.state.document.settings.env self.options.setdefault('language', get_lexer(filename=env.docname).name) self.options.setdefault('timelimit', 25000) self.options.setdefault('builder', 'JOBE') # Generate HTML for the lp build directive. Pass the language, so client-side JS can use the correct syntax highligher. html = ( """<div class="runestone"> <input type="button" value="Save and run" class="btn btn-success" data-component="lp_build" data-lang="{}" id="{}" /> <br /> <textarea readonly id="lp-result"></textarea> <br /> <div></div> </div>""".format(self.options['language'], id_) ) addHTMLToDB(id_, self.options['basecourse'], html, json.dumps(dict( # Provide these to the server, indicating how to build. language=self.options['language'], builder=self.options['builder'], timelimit=self.options['timelimit'], include=self.options['include'], source_path=env.docname, sphinx_base_path=env.app.confdir, ))) raw_node = nodes.raw(self.block_text, html, format='html') raw_node.source, raw_node.line = self.state_machine.get_source_and_line(self.lineno) return [raw_node]