PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/samples/syntax.textile

http://github.com/geraldb/slideshow
Unknown | 216 lines | 155 code | 61 blank | 0 comment | 0 complexity | cf04cc37b28fe34697e752f23b0b9b02 MD5 | raw file
Possible License(s): CC0-1.0
  1. title: Slide Show (S9) Code Syntax Highlighting
  2. code-theme: all-hallows-eve
  3. h1. Slide Show (S9) Code Syntax Highlighting
  4. The slideshow (S9) gem now includes the Ultraviolet (Uv) gem that lets you use/turn on
  5. experimental syntax highlighting in your slides for your code. Add @#!ruby@ after
  6. the code block. Example:
  7. {{{{{{
  8. #!ruby
  9. puts "Syntaxes:"
  10. puts Uv.syntaxes.join( ", " )
  11. puts "Themes:"
  12. puts Uv.themes.join( ", " )
  13. }}}}}}
  14. Or use any of the other 40+ languages supported by Ultraviolet. Use headers to select any of the 20+ Ultraviolet syntax highlighting themes[1] and/or turn off line numbering. Example:
  15. {{{
  16. code-theme: blackboard
  17. code-line-numbers: false
  18. }}}
  19. fn1. active4d, all-hallows-eve, amy, blackboard, cobalt, dawn, eiffel, espresso-libre, idle, iplastic, lazy,
  20. mac-classic, pastels-on-dark, slush-poppies, spacecadet, sunburst, twilight, zenburnesque
  21. h1. Rubyize This: 5th Edition
  22. {{{
  23. #!ruby
  24. @wordsToHighlight=["important","monkey","dancing"]
  25. def highlightText(input)
  26. for i in 0..@wordsToHighlight.length-1 do
  27. input = input.gsub(@wordsToHighlight[i],"*" + @wordsToHighlight[i] + "*")
  28. end
  29. return input
  30. end
  31. }}}
  32. Source: "Rubyize this: 5th edition":http://www.rubyfleebie.com/rubyize-this-5th-edition by RubyFleebie (François Lamontagne)
  33. Refactoring:
  34. {{{
  35. #!ruby
  36. def highlight_text(input, words_to_highlight=%w(important monkey dancing))
  37. input.gsub(/#{words_to_highlight.join('|')}/i, '*\0*')
  38. end
  39. puts highlight_text("Hey monkey, it's important you start dancing right now!")
  40. # >> Hey *monkey*, it's *important* you start *dancing* right now!
  41. }}}
  42. Another Refactoring:
  43. {{{
  44. #!ruby
  45. class String
  46. def highlight(words=[])
  47. words.empty? ? self : self.gsub(Regexp.union(*words), '*\0*')
  48. end
  49. end
  50. puts "I think it's important to have a dancing monkey in your bedroom.".highlight %w(important monkey dancing)
  51. # => I think it's *important* to have a *dancing* *monkey* in your bedroom.
  52. }}}
  53. h1. Rubyize This: Vancouver RubyCamp 2008 Edition
  54. {{{
  55. #!ruby
  56. # create num random numbers between min and max
  57. # and print them to a file called file_name, one per line
  58. def create_random_numbers(file_name, min, max, num)
  59. file = File.open(file_name, 'w')
  60. n = 0
  61. while n < num
  62. r = rand(max - min) + min
  63. file.puts(r)
  64. n += 1
  65. end
  66. file.close
  67. end
  68. create_random_numbers('random.txt', 0, 10, 1000)
  69. }}}
  70. Source: "Rubyize this: Live in Vancouver. Refactoring #1":http://spattendesign.com/2008/1/27/rubyize-this-live-in-vancouver
  71. Refactoring:
  72. {{{
  73. #!ruby
  74. def create_random_numbers(file_name, min, max, num)
  75. File.open(file_name, 'w') do |file|
  76. num.times {file.puts(rand(max - min) + min)}
  77. end
  78. end
  79. create_random_numbers('random.txt', 0, 10, 1000)
  80. }}}
  81. Another Refactoring:
  82. {{{
  83. #!ruby
  84. class Range
  85. def random_member
  86. offset = rand(max - min)
  87. min + offset
  88. end
  89. end
  90. def create_random_numbers(file_name, range, num)
  91. File.open(file_name, 'w') do |file|
  92. num.times { file.puts(range.random_member) }
  93. end
  94. end
  95. create_random_numbers('random.txt', (0..10), 1000)
  96. }}}
  97. h1. Hello World - From Ada to CSS
  98. Ada
  99. {{{
  100. #!ada
  101. -- Hello World in Ada
  102. with Text_IO;
  103. procedure Hello_World is
  104. begin
  105. Text_IO.Put_Line("Hello World!");
  106. end Hello_World;
  107. }}}
  108. C
  109. {{{
  110. #!c
  111. /* Hello World in C, Ansi-style */
  112. #include <stdio.h>
  113. #include <stdlib.h>
  114. int main(void)
  115. {
  116. puts("Hello World!");
  117. return EXIT_SUCCESS;
  118. }
  119. }}}
  120. CSS
  121. {{{
  122. #!css
  123. /* Hello World in CSS */
  124. body:before {
  125. content: "Hello World";
  126. }
  127. }}}
  128. h1. Hello World - From Erlang to PHP
  129. Erlang
  130. {{{
  131. #!erlang
  132. %% Hello World in Erlang
  133. -module(hello).
  134. -export([hello/0]).
  135. hello() ->
  136. io:format("Hello World!~n", []).
  137. }}}
  138. Java
  139. {{{
  140. #!java
  141. // Hello World in Java
  142. class HelloWorld {
  143. static public void main( String args[] ) {
  144. System.out.println( "Hello World!" );
  145. }
  146. }
  147. }}}
  148. PHP
  149. {{{
  150. #!php
  151. <?php
  152. // Hello World in PHP
  153. echo 'Hello World!';
  154. ?>
  155. }}}