Commit 7a517a8f by Piotr Mitros

First prototype

parent 89a2ddf7
AudioXBlock TemplateXBlock
=========== ==============
This is a simple XBlock which will play audio files as an HTML5 audio This is a simple template for an XBlock. It will play audio files as
element. If unavailable, it will fall back to an embed element. an HTML5 audio element. If unavailable, it will fall back to an embed
element.
Usage: Usage:
<audio src="http://server.tld/static/song.mp3" /> <template src="http://server.tld/static/song.mp3" />
from .audio import AudioXBlock
\ No newline at end of file
# Welcome!
#
# Step 1: Come up with a short name for your XBlock. For example, if
# your XBlock plays audio files, 'audio' is a good name.
short-name : audio
# Step 2: Create a repository on github for your XBlock. In the above
# case, I strongly recommend the short name, followed by 'XBlock,' in
# camelcase. Do not initialize this repo. We'll do it for you
github : git@github.com:pmitros/AudioXBlock.git
# Step 3: Give a short description of this XBlock
description : Plays an audio file as an embed element
# Step 4: Give a multiline description. Keep the 2 line indent, please.
overview : |
This XBlock plays an audio file as an HTML5 audio element. If
the audio element is not present, it will fall back to an
embed element.
# Once you're done, hit save, and watch the magic happen!
\ No newline at end of file
"""Setup for audio XBlock.""" """Setup for template XBlock."""
import os import os
from setuptools import setup from setuptools import setup
...@@ -15,19 +15,19 @@ def package_data(pkg, root): ...@@ -15,19 +15,19 @@ def package_data(pkg, root):
setup( setup(
name='audio-xblock', name='template-xblock',
version='0.1', version='0.1',
description='audio XBlock', # TODO: write a better description. description='template XBlock', # TODO: write a better description.
packages=[ packages=[
'audio', 'template',
], ],
install_requires=[ install_requires=[
'XBlock', 'XBlock',
], ],
entry_points={ entry_points={
'xblock.v1': [ 'xblock.v1': [
'audio = audio:AudioXBlock', 'template = template:TemplateXBlock',
] ]
}, },
package_data=package_data("audio", "static"), package_data=package_data("template", "static"),
) )
\ No newline at end of file
from .template import TemplateXBlock
\ No newline at end of file
/* CSS for AudioXBlock */ /* CSS for TemplateXBlock */
.audio_block .count { .template_block .count {
font-weight: bold; font-weight: bold;
} }
.audio_block p { .template_block p {
cursor: pointer; cursor: pointer;
} }
\ No newline at end of file
<div class="audio_block"> <div class="template_block">
<audio controls preload> <audio controls preload>
<source src="{src}"> <source src="{src}">
<embed height="50" width="100" src="{src}"> <embed height="50" width="100" src="{src}">
......
...@@ -7,7 +7,7 @@ from xblock.fields import Scope, Integer, String ...@@ -7,7 +7,7 @@ from xblock.fields import Scope, Integer, String
from xblock.fragment import Fragment from xblock.fragment import Fragment
class AudioXBlock(XBlock): class TemplateXBlock(XBlock):
""" """
This XBlock will play an MP3 file as an HTML5 audio element. This XBlock will play an MP3 file as an HTML5 audio element.
""" """
...@@ -27,16 +27,16 @@ class AudioXBlock(XBlock): ...@@ -27,16 +27,16 @@ class AudioXBlock(XBlock):
# TO-DO: change this view to display your data your own way. # TO-DO: change this view to display your data your own way.
def student_view(self, context=None): def student_view(self, context=None):
""" """
The primary view of the AudioXBlock, shown to students The primary view of the TemplateXBlock, shown to students
when viewing courses. when viewing courses.
""" """
html = self.resource_string("static/html/audio.html") html = self.resource_string("static/html/template.html")
print self.src print self.src
print html.format print html.format
frag = Fragment(html.format(src = self.src)) frag = Fragment(html.format(src = self.src))
frag.add_css(self.resource_string("static/css/audio.css")) frag.add_css(self.resource_string("static/css/template.css"))
frag.add_javascript(self.resource_string("static/js/src/audio.js")) frag.add_javascript(self.resource_string("static/js/src/template.js"))
frag.initialize_js('AudioXBlock') frag.initialize_js('TemplateXBlock')
print self.xml_text_content() print self.xml_text_content()
return frag return frag
...@@ -46,11 +46,11 @@ class AudioXBlock(XBlock): ...@@ -46,11 +46,11 @@ class AudioXBlock(XBlock):
def workbench_scenarios(): def workbench_scenarios():
"""A canned scenario for display in the workbench.""" """A canned scenario for display in the workbench."""
return [ return [
("AudioXBlock", ("TemplateXBlock",
"""<vertical_demo> """<vertical_demo>
<audio src="http://localhost/Ikea.mp3"> </audio> <template src="http://localhost/Ikea.mp3"> </template>
<audio src="http://localhost/skull.mp3"> </audio> <template src="http://localhost/skull.mp3"> </template>
<audio src="http://localhost/monkey.mp3"> </audio> <template src="http://localhost/monkey.mp3"> </template>
</vertical_demo> </vertical_demo>
"""), """),
] ]
import yaml
commands = '''
git mv ./template/template.py ./template/{shortname}.py
git mv ./template/static/html/template.html ./template/static/html/{shortname}.html
git mv ./template/static/css/template.css ./template/static/css/{shortname}.css
git mv ./template/static/js/src/template.js ./template/static/js/src/{shortname}.js
git mv template {shortname}
find . -type f | grep -v git | xargs sed -i 's/template/{shortname}/g'
find . -type f | grep -v git | xargs sed -i 's/Template/{Shortname}/g'
git remote rm origin
git remote add origin {github}
git commit -a -m "Initializing repo"
git push --set-upstream origin master
'''
os.system("editor config.yaml")
settings = yaml.load(open("config.yaml", 'r'))
commands = commands.format(shortname = settings["short-name"],
Shortname = settings["short-name"].capitalize(),
github = settings["github"])
readme = open("README.md", "w")
readme.writelines(["{Shortname}XBlock".format(Shortname = settings["short-name"].capitalize()),
"==============",
"",
settings["description"],
""
settings["overview"]])
for command in commands:
if len(command > 0):
print command
os.system(command)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment