00001
00002 """
00003 ROS - Buildsystem
00004
00005 <<Buildsystem(<catkin|rosbuild>)>>
00006 This will create a flag which indicates the associated line(s) are
00007 specific to catkin or rosbuild.
00008
00009 OR
00010
00011 <<Buildsystem()>>
00012 This macro will place buttons to toggle between the available build
00013 systems. Follow it with sections like:
00014
00015 {{{#!wiki buildsystem catkin
00016 This is catkin stuff.
00017 }}}
00018 {{{#!wiki buildsystem rosbuild
00019 This is rosbuild stuff.
00020 }}}
00021
00022 @copyright: 2012 Willow Garage,
00023 William Woodall <wwoodall@willowgarage.com>
00024 @license: BSD
00025 """
00026
00027 from __future__ import print_function
00028
00029 Dependencies = []
00030
00031 systems = ['catkin', 'rosbuild']
00032
00033 DEFAULT_SYSTEM = 'rosbuild'
00034
00035 buildsystem_js = """\
00036 <script type="text/javascript">
00037 <!--
00038 // @@ Buildsystem macro
00039 function Buildsystem(sections) {
00040 var dotversion = ".buildsystem."
00041
00042 // Tag shows unless already tagged
00043 $.each(sections.show,
00044 function() {
00045 $("div" + dotversion + this).not(".versionshow,.versionhide")\
00046 .addClass("versionshow")
00047 }
00048 )
00049
00050 // Tag hides unless already tagged
00051 $.each(sections.hide,
00052 function() {
00053 $("div" + dotversion + this).not(".versionshow,.versionhide")\
00054 .addClass("versionhide")
00055 }
00056 )
00057
00058 // Show or hide according to tag
00059 $(".versionshow").removeClass("versionshow").filter("div").show(0)
00060 $(".versionhide").removeClass("versionhide").filter("div").hide(0)
00061 }
00062
00063 function getURLParameter(name) {
00064 return decodeURIComponent(
00065 (
00066 new RegExp(
00067 '[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)'
00068 ).exec(location.search) || [,""]
00069 )[1].replace(/\+/g, '%20')
00070 ) || null;
00071 }
00072
00073 $(document).ready(function() {
00074 var activesystem = \"""" + DEFAULT_SYSTEM + """";
00075 var url_distro = getURLParameter('distro');
00076 if (url_distro)
00077 {
00078 activesystem = url_distro;
00079 }
00080 $("div.version").not("."+activesystem).hide();
00081 $("#"+activesystem).click();
00082 $("input.version:hidden").each(function() {
00083 var bg = $(this).attr("value").split(":");
00084 $("div.version." + bg[0]).css("background-color", bg[1])\
00085 .removeClass(bg[0])
00086 });
00087 })
00088 // -->
00089 </script>
00090 """
00091
00092
00093 def distro_html(system, systems):
00094 active = [system.encode("iso-8859-1")]
00095 inactive = [x.encode("iso-8859-1") for x in systems if not x == system]
00096 sectionarg = '''{show:%s, hide:%s}''' % (active, inactive)
00097 html = '''\
00098 <button id="%s" onClick="Buildsystem(%s);this.style.color='#e6e6e6';\
00099 this.style.background='#3e4f6e';\
00100 ''' % (system, sectionarg)
00101 for inactive_distro in inactive:
00102 html += '''\
00103 document.getElementById('%s').style.background='#e6e6e6';\
00104 document.getElementById('%s').style.color='#3e4f6e';\
00105 ''' % (inactive_distro, inactive_distro)
00106 html += '''return false"> %s </button>''' % (system)
00107 return html
00108
00109
00110 def execute(macro, args):
00111 if args:
00112 buildsystem = str(args)
00113 msg = '<span style="background-color:#FFFF00; ' + \
00114 'font-weight:bold; padding: 3px;">%s</span>'
00115 if buildsystem.lower() in ['catkin', 'rosbuild']:
00116 return msg % ('%s specific' % buildsystem.lower())
00117 else:
00118 return '<span class="error">Invalid use of macro: ' + \
00119 '<<Buildsystem(%s)>>' % buildsystem
00120
00121 html = ''
00122 html += buildsystem_js
00123 macro.request.cfg.buildsystem_macro = True
00124 html += "\n".join([distro_html(system, systems) for system in systems])
00125 return macro.formatter.rawHTML(html)