コード例 #1
0
def depart_mc_node(self, node):
    res = ""
    currFeedback = ""
    # Add all of the possible answers
    okeys = list(node.mc_options.keys())
    okeys.sort()
    for k in okeys:
        if 'answer_' in k:
            x, label = k.split('_')
            node.mc_options['alabel'] = label
            node.mc_options['atext'] = node.mc_options[k]
            currFeedback = "feedback_" + label
            node.mc_options['feedtext'] = node.mc_options.get(
                currFeedback, "")  #node.mc_options[currFeedback]
            if label in node.mc_options['correct']:
                node.mc_options["is_correct"] = "data-correct"
            else:
                node.mc_options["is_correct"] = ""
            res += node.template_option % node.mc_options

    res += node.template_end % node.mc_options
    self.body.append(res)

    addHTMLToDB(node.mc_options['divid'], node.mc_options['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #2
0
    def run(self):
        """
        process the video directive and generate html for output.
        :param self:
        :return:
        """
        super(Video, self).run()
        addQuestionToDB(self)

        mimeMap = {'mov':'mp4','webm':'webm', 'm4v':'m4v'}

        sources = [SOURCE % (directives.uri(line),mimeMap[line[line.rindex(".")+1:]]) for line in self.content]
        if 'controls' in self.options:
            self.options['controls'] = 'controls'
        if 'loop' in self.options:
            self.options['loop'] = 'loop'
        else:
            self.options['loop'] = ''

        if 'preload' in self.options:
            self.options['preload'] = 'preload="auto"'
        else:
            self.options['preload'] = 'preload="none"'

        self.options['sources'] = "\n    ".join(sources)
        res = CODE % self.options
        if 'popup' in self.options:
            res += POPUP % self.options
        else:
            res += INLINE % self.options

        addHTMLToDB(self.options['divid'], self.options['basecourse'], res)
        return [nodes.raw(self.block_text, res, format='html')]
コード例 #3
0
    def run(self):
        """
        process the video directive and generate html for output.
        :param self:
        :return:
        """
        super(Video, self).run()
        addQuestionToDB(self)

        mimeMap = {'mov':'mp4','webm':'webm', 'm4v':'m4v'}

        sources = [SOURCE % (directives.uri(line),mimeMap[line[line.rindex(".")+1:]]) for line in self.content]
        if 'controls' in self.options:
            self.options['controls'] = 'controls'
        if 'loop' in self.options:
            self.options['loop'] = 'loop'
        else:
            self.options['loop'] = ''

        if 'preload' in self.options:
            self.options['preload'] = 'preload="auto"'
        else:
            self.options['preload'] = 'preload="none"'

        self.options['sources'] = "\n    ".join(sources)
        res = CODE % self.options
        if 'popup' in self.options:
            res += POPUP % self.options
        else:
            res += INLINE % self.options

        addHTMLToDB(self.options['divid'], self.options['basecourse'], res)
        return [nodes.raw(self.block_text, res, format='html')]
コード例 #4
0
ファイル: fitb.py プロジェクト: usag1r/RunestoneComponents
def depart_fitb_node(self, node):
    # If there were fewer blanks than feedback items, add blanks at the end of the question.
    blankCount = 0
    for _ in node.traverse(BlankNode):
        blankCount += 1
    while blankCount < len(node.feedbackArray):
        visit_blank_node(self, None)
        blankCount += 1

    # Warn if there are fewer feedback items than blanks.
    if len(node.feedbackArray) < blankCount:
        # Taken from the example in the `logging API <http://www.sphinx-doc.org/en/stable/extdev/logging.html#logging-api>`_.
        logger = logging.getLogger(__name__)
        logger.warning(
            'Not enough feedback for the number of blanks supplied.',
            location=node)

    # Generate the HTML.
    json_feedback = json.dumps(node.feedbackArray)
    # Some nodes (for example, those in a timed node) have their ``document == None``. Find a valid ``document``.
    node_with_document = node
    while not node_with_document.document:
        node_with_document = node_with_document.parent
    # Supply client-side grading info if we're not grading on the server.
    node.fitb_options[
        'json'] = 'false' if node_with_document.document.settings.env.config.runestone_server_side_grading else json_feedback
    res = node.template_end % node.fitb_options
    self.body.append(res)

    # add HTML to the Database and clean up
    addHTMLToDB(node.fitb_options['divid'], node.fitb_options['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]),
                json_feedback)

    self.body.remove(node.delimiter)
コード例 #5
0
ファイル: fitb.py プロジェクト: tahmeed14/RunestoneComponents
def depart_fitb_node(self, node):
    # If there were fewer blanks than feedback items, add blanks at the end of the question.
    blankCount = 0
    for _ in node.traverse(BlankNode):
        blankCount += 1
    while blankCount < len(node.feedbackArray):
        visit_blank_node(self, None)
        blankCount += 1

    # Warn if there are fewer feedback items than blanks.
    if len(node.feedbackArray) < blankCount:
        # Taken from the example in the `logging API <http://www.sphinx-doc.org/en/stable/extdev/logging.html#logging-api>`_.
        logger = logging.getLogger(__name__)
        logger.warning('Not enough feedback for the number of blanks supplied.', location=node)

    # Generate the HTML.
    node.fitb_options['json'] = json.dumps(node.feedbackArray)
    res = node.template_end % node.fitb_options
    self.body.append(res)

    # add HTML to the Database and clean up
    addHTMLToDB(node.fitb_options['divid'],
                node.fitb_options['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #6
0
def depart_mc_node(self,node):
    res = ""
    currFeedback = ""
    # Add all of the possible answers
    okeys = list(node.mc_options.keys())
    okeys.sort()
    for k in okeys:
        if 'answer_' in k:
            x,label = k.split('_')
            node.mc_options['alabel'] = label
            node.mc_options['atext'] = "(" +k[-1].upper() + ") " + node.mc_options[k]
            currFeedback = "feedback_" + label
            node.mc_options['feedtext'] = node.mc_options.get(currFeedback,"") #node.mc_options[currFeedback]
            if label in node.mc_options['correct']:
                node.mc_options["is_correct"] = "data-correct"
            else:
                node.mc_options["is_correct"] = ""
            res += node.template_option % node.mc_options


    res += node.template_end % node.mc_options
    self.body.append(res)

    addHTMLToDB(node.mc_options['divid'],
                node.mc_options['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #7
0
def depart_fitb_node(self, node):
    # If there were fewer blanks than feedback items, add blanks at the end of the question.
    blankCount = 0
    for _ in node.traverse(BlankNode):
        blankCount += 1
    while blankCount < len(node.feedbackArray):
        visit_blank_node(self, None)
        blankCount += 1

    # Warn if there are fewer feedback items than blanks.
    if len(node.feedbackArray) < blankCount:
        print('Warning at {} line {}: there'
              ' not enough feedback for the number of blanks supplied.'.format(
                  node.source, node.line))

    # Generate the HTML.
    node.fitb_options['json'] = json.dumps(node.feedbackArray)
    res = node.template_end % node.fitb_options
    self.body.append(res)

    # add HTML to the Database and clean up
    addHTMLToDB(node.fitb_options['divid'], node.fitb_options['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #8
0
def depart_mc_node(self, node):
    res = ""
    currFeedback = ""
    # Add all of the possible answers
    okeys = list(node.runestone_options.keys())
    okeys.sort()
    for k in okeys:
        if "answer_" in k:
            x, label = k.split("_")
            node.runestone_options["alabel"] = label
            node.runestone_options["atext"] = node.runestone_options[k]
            currFeedback = "feedback_" + label
            node.runestone_options["feedtext"] = node.runestone_options.get(
                currFeedback, "")  # node.runestone_options[currFeedback]
            if label in node.runestone_options["correct"]:
                node.runestone_options["is_correct"] = "data-correct"
            else:
                node.runestone_options["is_correct"] = ""
            res += node.template_option % node.runestone_options

    res += node.template_end % node.runestone_options
    self.body.append(res)

    addHTMLToDB(
        node.runestone_options["divid"],
        node.runestone_options["basecourse"],
        "".join(self.body[self.body.index(node.delimiter) + 1:]),
    )

    self.body.remove(node.delimiter)
コード例 #9
0
def depart_fitb_node(self, node):
    # If there were fewer blanks than feedback items, add blanks at the end of the question.
    blankCount = 0
    for _ in node.traverse(BlankNode):
        blankCount += 1
    while blankCount < len(node.feedbackArray):
        visit_blank_node(self, None)
        blankCount += 1

    # Warn if there are fewer feedback items than blanks.
    if len(node.feedbackArray) < blankCount:
        # Taken from the example in the `logging API <http://www.sphinx-doc.org/en/stable/extdev/logging.html#logging-api>`_.
        logger = logging.getLogger(__name__)
        logger.warning('Not enough feedback for the number of blanks supplied.', location=node)

    # Generate the HTML.
    node.fitb_options['json'] = json.dumps(node.feedbackArray)
    res = node.template_end % node.fitb_options
    self.body.append(res)

    # add HTML to the Database and clean up
    addHTMLToDB(node.fitb_options['divid'],
                node.fitb_options['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #10
0
    def run(self):

        addQuestionToDB(self)

        self.JS_VARNAME = ""
        self.JS_VARVAL = ""

        def raw_dict(input_code, output_trace):
            ret = dict(code=input_code, trace=output_trace)
            return ret

        def js_var_finalizer(input_code, output_trace):
            global JS_VARNAME
            ret = dict(code=input_code, trace=output_trace)
            json_output = json.dumps(ret, indent=None)
            return "var %s = %s;" % (self.JS_VARNAME, json_output)

        self.options['divid'] = self.arguments[0]
        if self.content:
            source = "\n".join(self.content)
        else:
            source = '\n'

        CUMULATIVE_MODE = False
        self.JS_VARNAME = self.options['divid'] + '_trace'
        if 'showoutput' not in self.options:
            self.options['embedded'] = 'true'  # to set embeddedmode to true
        else:
            self.options['embedded'] = 'false'

        if 'python' not in self.options:
            if six.PY2:
                self.options['python'] = 'py2'
            else:
                self.options['python'] = 'py3'

        if 'question' in self.options:
            curTrace = exec_script_str_local(source, None, CUMULATIVE_MODE, None, raw_dict)
            self.inject_questions(curTrace)
            json_output = json.dumps(curTrace, indent=None)
            self.options['tracedata'] = "var %s = %s;" % (self.JS_VARNAME, json_output)
        else:
            self.options['tracedata'] = exec_script_str_local(source, None,
                                                              CUMULATIVE_MODE,
                                                              None, js_var_finalizer)

        res = VIS
        if 'caption' not in self.options:
            self.options['caption'] = ''
        if 'question' in self.options:
            res += QUESTION
        if 'tracedata' in self.options:
            res += DATA
        else:
            res += '</div>'
        addHTMLToDB(self.options['divid'], self.options['basecourse'], res % self.options)
        raw_node = nodes.raw(self.block_text, res % self.options, format='html')
        raw_node.source, raw_node.line = self.state_machine.get_source_and_line(self.lineno)
        return [raw_node]
コード例 #11
0
    def run(self):
        """
        All prerequisite information that should be displayed above the directive,
        such as variable declaration, are separated from the step strings by "-----".

        The step animations follow the "-----" and are written one per line. Use
        "{{" and "}}" braces to surround the part of the line that should be replaced,
        followed by the replacement text also in "{{" and "}}". If you would like to add
        a comment that will appear in a div beside the animation, denote that at the end
        of the step where you would like it to appear with "##".

    Example:

    .. showeval:: showEval_0
       :trace_mode: false

       eggs = ['dogs', 'cats', 'moose']
       ~~~~

       ''.join({{eggs}}{{['dogs', 'cats', 'moose']}}).upper().join(eggs)
       {{''.join(['dogs', 'cats', 'moose'])}}{{'dogscatsmoose'}}.upper().join(eggs)  ##I want to put a comment here!
       {{'dogscatsmoose'.upper()}}{{'DOGSCATSMOOSE'}}.join(eggs)
       'DOGSCATSMOOSE'.join({{eggs}}{{['dogs', 'cats', 'moose']}})
       {{'DOGSCATSMOOSE'.join(['dogs', 'cats', 'moose'])}}{{'dogsDOGSCATSMOOSEcatsDOGSCATSMOOSEmoose'}}

        """

        # Raise an error if the directive does not have contents.
        super(ShowEval, self).run()
        addQuestionToDB(self)

        self.options["trace_mode"] = self.options["trace_mode"].lower()
        self.options["preReqLines"] = ""
        self.options["steps"] = []

        env = self.state.document.settings.env
        self.options["divclass"] = env.config.showeval_div_class

        is_dynamic = env.config.html_context.get("dynamic_pages", False)
        is_dynamic = True if is_dynamic == "True" else False
        step = False
        count = 0
        for line in self.content:
            if step == True:
                if line != "":
                    if is_dynamic:
                        esc_line = str(line).replace("{", r"\{")
                    else:
                        esc_line = str(line)
                    self.options["steps"].append(esc_line)
            elif "~~~~" in line:
                step = True
            else:
                self.options["preReqLines"] += line + "<br />\n"

        res = CODE % self.options

        addHTMLToDB(self.options["divid"], self.options["basecourse"], res)
        return [nodes.raw(self.block_text, res, format="html")]
コード例 #12
0
def visit_journal_node(self, node):
    div_id = node.journalnode_components['divid']
    components = dict(node.journalnode_components)
    components.update({'divid': div_id})
    res = TEXT % components
    addHTMLToDB(div_id, components['basecourse'], res)

    self.body.append(res)
コード例 #13
0
def visit_parsons_node(self, node):
    div_id = node.parsonsnode_components['divid']
    components = dict(node.parsonsnode_components)
    components.update({'divid': div_id})
    res = TEMPLATE % components
    addHTMLToDB(div_id, components['basecourse'], res)

    self.body.append(res)
コード例 #14
0
def visit_parsons_node(self, node):
    div_id = node.parsonsnode_components["divid"]
    components = dict(node.parsonsnode_components)
    components.update({"divid": div_id})
    res = TEMPLATE % components
    addHTMLToDB(div_id, components["basecourse"], res)

    self.body.append(res)
コード例 #15
0
def visit_journal_node(self, node):
    div_id = node.journalnode_components['divid']
    components = dict(node.journalnode_components)
    components.update({'divid': div_id})
    res = TEXT % components
    addHTMLToDB(div_id, components['basecourse'], res)

    self.body.append(res)
コード例 #16
0
def depart_ca_node(self, node):
    res = ""
    res = TEMPLATE_END % node.ca_options
    self.body.append(res)

    addHTMLToDB(node.ca_options['divid'], node.ca_options['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #17
0
def depart_parsons_node(self, node):
    res = TEMPLATE_END % node.runestone_options
    self.body.append(res)
    addHTMLToDB(
        node.runestone_options["divid"],
        node.runestone_options["basecourse"],
        "".join(self.body[self.body.index(node.delimiter) + 1:]),
    )
    self.body.remove(node.delimiter)
コード例 #18
0
def depart_ca_node(self,node):
    res = ""
    res = TEMPLATE_END % node.ca_options
    self.body.append(res)

    addHTMLToDB(node.ca_options['divid'],
                node.ca_options['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #19
0
def depart_external_node(self, node):
    # Set options and format templates accordingly
    res = TEMPLATE_END % node.external_options

    self.body.append(res)

    addHTMLToDB(node.external_options["divid"],
                node.external_options["basecourse"], "".join(""))

    self.body.remove(node.delimiter)
コード例 #20
0
def depart_external_node(self, node):
    # Set options and format templates accordingly
    res = TEMPLATE_END % node.external_options

    self.body.append(res)

    addHTMLToDB(node.external_options['divid'],
                node.external_options['basecourse'],
                "".join(""))

    self.body.remove(node.delimiter)
コード例 #21
0
    def run(self):
        """
        All prerequisite information that should be displayed above the directive,
        such as variable declaration, are separated from the step strings by "-----".

        The step animations follow the "-----" and are written one per line. Use
        "{{" and "}}" braces to surround the part of the line that should be replaced,
        followed by the replacement text also in "{{" and "}}". If you would like to add
        a comment that will appear in a div beside the animation, denote that at the end
        of the step where you would like it to appear with "##".

    Example:

    .. showeval:: showEval_0
       :trace_mode: false

       eggs = ['dogs', 'cats', 'moose']
       ~~~~

       ''.join({{eggs}}{{['dogs', 'cats', 'moose']}}).upper().join(eggs)
       {{''.join(['dogs', 'cats', 'moose'])}}{{'dogscatsmoose'}}.upper().join(eggs)  ##I want to put a comment here!
       {{'dogscatsmoose'.upper()}}{{'DOGSCATSMOOSE'}}.join(eggs)
       'DOGSCATSMOOSE'.join({{eggs}}{{['dogs', 'cats', 'moose']}})
       {{'DOGSCATSMOOSE'.join(['dogs', 'cats', 'moose'])}}{{'dogsDOGSCATSMOOSEcatsDOGSCATSMOOSEmoose'}}

        """

        # Raise an error if the directive does not have contents.
        super(ShowEval, self).run()
        addQuestionToDB(self)

        self.options['trace_mode'] = self.options['trace_mode'].lower()
        self.options['preReqLines'] = ''
        self.options['steps'] = []

        env = self.state.document.settings.env
        self.options['divclass'] = env.config.showeval_div_class

        step = False
        count = 0
        for line in self.content:
            if step == True:
                if line != '':
                    self.options['steps'].append(str(line))
            elif '~~~~' in line:
                step = True
            else:
                self.options['preReqLines'] += line + '<br />\n'


        res = (CODE + SCRIPT) % self.options

        addHTMLToDB(self.options['divid'], self.options['basecourse'], res)
        return [nodes.raw(self.block_text, res, format='html')]
コード例 #22
0
def depart_mc_html(self, node):
    res = depart_mc_common(self, node)
    self.body.append(res)

    addHTMLToDB(
        node["runestone_options"]["divid"],
        node["runestone_options"]["basecourse"],
        "".join(self.body[self.body.index(node["delimiter"]) + 1:]),
    )

    self.body.remove(node["delimiter"])
コード例 #23
0
def depart_ca_html(self, node):
    res = ""
    res = TEMPLATE_END % node["runestone_options"]
    self.body.append(res)

    addHTMLToDB(
        node["runestone_options"]["divid"],
        node["runestone_options"]["basecourse"],
        "".join(self.body[self.body.index(node["delimiter"]) + 1:]),
    )

    self.body.remove(node["delimiter"])
コード例 #24
0
ファイル: quizly.py プロジェクト: ram8647/RunestoneComponents
def depart_quizly_node(self, node):
    """ This is called at the start of processing an activecode node.  If activecode had recursive nodes
        etc and did not want to do all of the processing in visit_ac_node any finishing touches could be
        added here.
    """
    print('DEBUG: depart_quizly_node') if DEBUG else None
    addHTMLToDB(
        node.runestone_options["divid"],
        node.runestone_options["basecourse"],
        "".join(self.body[self.body.index(node.delimiter) + 1:]),
    )
    self.body.remove(node.delimiter)
コード例 #25
0
def depart_ac_node(self, node):
    ''' This is called at the start of processing an activecode node.  If activecode had recursive nodes
        etc and did not want to do all of the processing in visit_ac_node any finishing touches could be
        added here.
    '''
    res = TEMPLATE_END % node.ac_components
    self.body.append(res)

    addHTMLToDB(node.ac_components['divid'], node.ac_components['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #26
0
    def run(self):
        """
        All prerequisite information that should be displayed above the directive,
        such as variable declaration, are separated from the step strings by "-----".

        The step animations follow the "-----" and are written one per line. Use
        "{{" and "}}" braces to surround the part of the line that should be replaced,
        followed by the replacement text also in "{{" and "}}". If you would like to add
        a comment that will appear in a div beside the animation, denote that at the end
        of the step where you would like it to appear with "##".

    Example:

    .. showeval:: showEval_0
       :trace_mode: false

       eggs = ['dogs', 'cats', 'moose']
       ~~~~

       ''.join({{eggs}}{{['dogs', 'cats', 'moose']}}).upper().join(eggs)
       {{''.join(['dogs', 'cats', 'moose'])}}{{'dogscatsmoose'}}.upper().join(eggs)  ##I want to put a comment here!
       {{'dogscatsmoose'.upper()}}{{'DOGSCATSMOOSE'}}.join(eggs)
       'DOGSCATSMOOSE'.join({{eggs}}{{['dogs', 'cats', 'moose']}})
       {{'DOGSCATSMOOSE'.join(['dogs', 'cats', 'moose'])}}{{'dogsDOGSCATSMOOSEcatsDOGSCATSMOOSEmoose'}}

        """

        # Raise an error if the directive does not have contents.
        super(ShowEval, self).run()
        addQuestionToDB(self)

        self.options['trace_mode'] = self.options['trace_mode'].lower()
        self.options['preReqLines'] = ''
        self.options['steps'] = []

        env = self.state.document.settings.env
        self.options['divclass'] = env.config.showeval_div_class

        step = False
        count = 0
        for line in self.content:
            if step == True:
                if line != '':
                    self.options['steps'].append(str(line))
            elif '~~~~' in line:
                step = True
            else:
                self.options['preReqLines'] += line + '<br />\n'

        res = (CODE + SCRIPT) % self.options

        addHTMLToDB(self.options['divid'], self.options['basecourse'], res)
        return [nodes.raw(self.block_text, res, format='html')]
コード例 #27
0
def depart_journal_node(self, node):

    components = dict(node.journalnode_components)

    res = TEXT_END % components
    self.body.append(res)

    addHTMLToDB(
        node.journalnode_components["divid"],
        components["basecourse"],
        "".join(self.body[self.body.index(node.delimiter) + 1:]),
    )

    self.body.remove(node.delimiter)
コード例 #28
0
def depart_journal_html(self, node):

    components = dict(node["runestone_options"])

    res = TEXT_END % components
    self.body.append(res)

    addHTMLToDB(
        node["runestone_options"]["divid"],
        components["basecourse"],
        "".join(self.body[self.body.index(node["delimiter"]) + 1:]),
    )

    self.body.remove(node["delimiter"])
コード例 #29
0
def visit_codelens_html(self, node):
    html = VIS
    if "caption" not in node["runestone_options"]:
        node["runestone_options"]["caption"] = node["runestone_options"][
            "question_label"]
    if "tracedata" in node["runestone_options"]:
        html += DATA
    else:
        html += "</div>"
    html = html % node["runestone_options"]

    self.body.append(html)
    addHTMLToDB(node["runestone_options"]["divid"],
                node["runestone_options"]["basecourse"], html)
コード例 #30
0
ファイル: quizly.py プロジェクト: bjones1/RunestoneComponents
def depart_quizly_html(self, node):
    """ This is called at the start of processing an activecode node.  If activecode had recursive nodes
        etc and did not want to do all of the processing in visit_ac_html any finishing touches could be
        added here.
    """
    print('DEBUG: depart_quizly_html') if DEBUG else None
    bc = node["runestone_options"]["basecourse"]
    addHTMLToDB(
        node["runestone_options"]["divid"],
        bc,
        "".join(self.body[self.body.index(node["delimiter"]) + 1:]).replace(
            "../_static", f"/runestone/books/published/{bc}/_static"),
    )
    self.body.remove(node["delimiter"])
コード例 #31
0
def depart_ac_node(self, node):
    ''' This is called at the start of processing an activecode node.  If activecode had recursive nodes
        etc and did not want to do all of the processing in visit_ac_node any finishing touches could be
        added here.
    '''
    res = TEMPLATE_END % node.ac_components
    self.body.append(res)


    addHTMLToDB(node.ac_components['divid'],
                node.ac_components['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #32
0
def depart_ac_node(self, node):
    """This is called at the start of processing an activecode node.  If activecode had recursive nodes
    etc and did not want to do all of the processing in visit_ac_node any finishing touches could be
    added here.
    """
    res = TEMPLATE_END % node.runestone_options
    self.body.append(res)

    addHTMLToDB(
        node.runestone_options["divid"],
        node.runestone_options["basecourse"],
        "".join(self.body[self.body.index(node.delimiter) + 1:]),
    )

    self.body.remove(node.delimiter)
コード例 #33
0
    def run(self):
        """
        All prerequisite information that should be displayed above the directive,
        such as variable declaration, are separated from the step strings by "-----".

        The step animations follow the "-----" and are written one per line. Use
        "{{" and "}}" braces to surround the part of the line that should be replaced,
        followed by the replacement text also in "{{" and "}}".

    Example:

    .. showeval:: showEval_0
       :trace_mode: false

       eggs = ['dogs', 'cats', 'moose']
       ~~~~

       ''.join({{eggs}}{{['dogs', 'cats', 'moose']}}).upper().join(eggs)
       {{''.join(['dogs', 'cats', 'moose'])}}{{'dogscatsmoose'}}.upper().join(eggs)
       {{'dogscatsmoose'.upper()}}{{'DOGSCATSMOOSE'}}.join(eggs)
       'DOGSCATSMOOSE'.join({{eggs}}{{['dogs', 'cats', 'moose']}})
       {{'DOGSCATSMOOSE'.join(['dogs', 'cats', 'moose'])}}{{'dogsDOGSCATSMOOSEcatsDOGSCATSMOOSEmoose'}}

        """

        addQuestionToDB(self)

        self.options['divid'] = self.arguments[0]
        self.options['trace_mode'] = self.options['trace_mode'].lower()
        self.options['preReqLines'] = ''
        self.options['steps'] = []

        step = False
        count = 0
        for line in self.content:
            if step == True:
                if line != '':
                    self.options['steps'].append(str(line))
            elif '~~~~' in line:
                step = True
            else:
                self.options['preReqLines'] += line + '<br />\n'

        res = (CODE + SCRIPT) % self.options

        addHTMLToDB(self.options['divid'], self.options['basecourse'], res)
        return [nodes.raw(self.block_text, res, format='html')]
コード例 #34
0
 def run(self):
     super(IframeVideo, self).run()
     self.options['video_id'] = directives.uri(self.arguments[0])
     if not self.options.get('width'):
         self.options['width'] = self.default_width
     if not self.options.get('height'):
         self.options['height'] = self.default_height
     if not self.options.get('align'):
         self.options['align'] = 'left'
     if not self.options.get('http'):
         self.options['http'] = 'https'
     if not self.options.get('divid'):
         self.options['divid'] = self.arguments[0]
     
     res = self.html % self.options
     addHTMLToDB(self.options['divid'], self.options['basecourse'], res)
     raw_node = nodes.raw(self.block_text, res, format='html')
     raw_node.source, raw_node.line = self.state_machine.get_source_and_line(self.lineno)
     return [raw_node]
コード例 #35
0
    def run(self):
        super(IframeVideo, self).run()
        self.options['video_id'] = directives.uri(self.arguments[0])
        if not self.options.get('width'):
            self.options['width'] = self.default_width
        if not self.options.get('height'):
            self.options['height'] = self.default_height
        if not self.options.get('align'):
            self.options['align'] = 'left'
        if not self.options.get('http'):
            self.options['http'] = 'https'
        if not self.options.get('divid'):
            self.options['divid'] = self.arguments[0]

        res = self.html % self.options
        addHTMLToDB(self.options['divid'], self.options['basecourse'], res)
        raw_node = nodes.raw(self.block_text, res, format='html')
        raw_node.source, raw_node.line = self.state_machine.get_source_and_line(self.lineno)
        return [raw_node]
コード例 #36
0
def visit_poll_node(self, node):
    res = TEMPLATE_START
    res = res % node.poll_content

    if node.poll_content["scale"] == "":
        okeys = list(node.poll_content.keys())
        okeys.sort()
        for k in okeys:
            if 'option_' in k:
                node.poll_content["optiontext"] = node.poll_content[k]
                res += TEMPLATE_OPTION % node.poll_content
    else:
        for i in range(node.poll_content["scale"]):
            node.poll_content["optiontext"] = i + 1
            res += TEMPLATE_OPTION % node.poll_content
    res += TEMPLATE_END

    addHTMLToDB(node.poll_content['divid'], node.poll_content['basecourse'],
                res)
    self.body.append(res)
コード例 #37
0
ファイル: video.py プロジェクト: larisala/tcc-ead-2020
    def run(self):
        super(IframeVideo, self).run()
        self.options["video_id"] = directives.uri(self.arguments[0])
        if not self.options.get("width"):
            self.options["width"] = self.default_width
        if not self.options.get("height"):
            self.options["height"] = self.default_height
        if not self.options.get("align"):
            self.options["align"] = "left"
        if not self.options.get("http"):
            self.options["http"] = "https"
        if not self.options.get("divid"):
            self.options["divid"] = self.arguments[0]

        res = self.html % self.options
        addHTMLToDB(self.options["divid"], self.options["basecourse"], res)
        raw_node = nodes.raw(self.block_text, res, format="html")
        raw_node.source, raw_node.line = self.state_machine.get_source_and_line(
            self.lineno)
        return [raw_node]
コード例 #38
0
def depart_dnd_node(self, node):
    res = ""
    # Add all of the possible answers
    okeys = list(node.dnd_options.keys())
    okeys.sort()
    for k in okeys:
        if 'match' in k:
            x, label = k.split('_')
            node.dnd_options['dnd_label'] = label
            dragE, dropE = node.dnd_options[k].split("|||")
            node.dnd_options["dragText"] = dragE
            node.dnd_options['dropText'] = dropE
            res += node.template_option % node.dnd_options
    res += node.template_end % node.dnd_options
    self.body.append(res)

    addHTMLToDB(node.dnd_options['divid'], node.dnd_options['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #39
0
def depart_dnd_node(self,node):
    res = ""
    # Add all of the possible answers
    okeys = list(node.dnd_options.keys())
    okeys.sort()
    for k in okeys:
        if 'match' in k:
            x,label = k.split('_')
            node.dnd_options['dnd_label'] = label
            dragE, dropE = node.dnd_options[k].split("|||")
            node.dnd_options["dragText"] = dragE
            node.dnd_options['dropText'] = dropE
            res += node.template_option % node.dnd_options
    res += node.template_end % node.dnd_options
    self.body.append(res)

    addHTMLToDB(node.dnd_options['divid'],
                node.dnd_options['basecourse'],
                "".join(self.body[self.body.index(node.delimiter) + 1:]))

    self.body.remove(node.delimiter)
コード例 #40
0
def visit_poll_node(self, node):
    res = TEMPLATE_START
    res = res % node.poll_content

    if node.poll_content["scale"] == "":
        okeys = list(node.poll_content.keys())
        okeys.sort()
        i = 1
        for k in okeys:
            if "option_" in k:
                node.poll_content["optiontext"] = f"{i}. " + node.poll_content[k]
                i += 1
                res += TEMPLATE_OPTION % node.poll_content
    else:
        for i in range(node.poll_content["scale"]):
            node.poll_content["optiontext"] = i + 1
            res += TEMPLATE_OPTION % node.poll_content
    res += TEMPLATE_END

    addHTMLToDB(node.poll_content["divid"], node.poll_content["basecourse"], res)
    self.body.append(res)
コード例 #41
0
    def run(self):
        """
        process the video directive and generate html for output.
        :param self:
        :return:
        """
        super(Video, self).run()
        addQuestionToDB(self)

        mimeMap = {"mov": "mp4", "webm": "webm", "m4v": "m4v"}

        sources = [
            SOURCE %
            (directives.uri(line), mimeMap[line[line.rindex(".") + 1:]])
            for line in self.content
        ]
        if "controls" in self.options:
            self.options["controls"] = "controls"
        if "loop" in self.options:
            self.options["loop"] = "loop"
        else:
            self.options["loop"] = ""

        if "preload" in self.options:
            self.options["preload"] = 'preload="auto"'
        else:
            self.options["preload"] = 'preload="none"'

        self.options["sources"] = "\n    ".join(sources)
        res = CODE % self.options
        if "popup" in self.options:
            res += POPUP % self.options
        else:
            res += INLINE % self.options

        addHTMLToDB(self.options["divid"], self.options["basecourse"], res)
        return [nodes.raw(self.block_text, res, format="html")]
コード例 #42
0
    def run(self):
        super(Codelens, self).run()

        addQuestionToDB(self)

        self.JS_VARNAME = ""
        self.JS_VARVAL = ""

        def raw_dict(input_code, output_trace):
            ret = dict(code=input_code, trace=output_trace)
            return ret

        def js_var_finalizer(input_code, output_trace):
            global JS_VARNAME
            ret = dict(code=input_code, trace=output_trace)
            json_output = json.dumps(ret, indent=None)
            return "var %s = %s;" % (self.JS_VARNAME, json_output)

        if self.content:
            source = "\n".join(self.content)
        else:
            source = '\n'

        CUMULATIVE_MODE = False
        self.JS_VARNAME = self.options['divid'] + '_trace'
        env = self.state.document.settings.env
        self.options['divclass'] = env.config.codelens_div_class

        if 'showoutput' not in self.options:
            self.options['embedded'] = 'true'  # to set embeddedmode to true
        else:
            self.options['embedded'] = 'false'

        if 'python' not in self.options:
            if six.PY2:
                self.options['python'] = 'py2'
            else:
                self.options['python'] = 'py3'

        if 'question' in self.options:
            curTrace = exec_script_str_local(source, None, CUMULATIVE_MODE, None, raw_dict)
            self.inject_questions(curTrace)
            json_output = json.dumps(curTrace, indent=None)
            self.options['tracedata'] = "var %s = %s;" % (self.JS_VARNAME, json_output)
        else:
            self.options['tracedata'] = exec_script_str_local(source, None,
                                                              CUMULATIVE_MODE,
                                                              None, js_var_finalizer)

        res = VIS
        if 'caption' not in self.options:
            self.options['caption'] = ''
        if 'question' in self.options:
            res += QUESTION
        if 'tracedata' in self.options:
            res += DATA
        else:
            res += '</div>'
        addHTMLToDB(self.options['divid'], self.options['basecourse'], res % self.options)
        raw_node = nodes.raw(self.block_text, res % self.options, format='html')
        raw_node.source, raw_node.line = self.state_machine.get_source_and_line(self.lineno)
        return [raw_node]