remi-syntax-on 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/TODO +3 -0
  2. data/lib/syntax-on/browser.rb +83 -0
  3. metadata +3 -1
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ * -b, --bash option for highlighting to tell it to run in a Bash::Session in the background
2
+ * add theme choosing via dropdown to browser
3
+ * add syntax-on theme(s) for listing themes and telling you howto create new ones, etc
@@ -0,0 +1,83 @@
1
+ class SyntaxOn::Browser
2
+
3
+ attr_accessor :request, :response, :current_theme
4
+
5
+ def initialize directory = '.'
6
+ @directory = directory || '.'
7
+ end
8
+
9
+ def call env
10
+ @pwd = Dir.pwd
11
+ Dir.chdir @directory
12
+
13
+ @response = Rack::Response.new
14
+ @request = Rack::Request.new env
15
+
16
+ @current_theme = request['theme'] if request['theme'] and SyntaxOn.theme_names.include? request['theme']
17
+
18
+ if request.path_info[/^\/styles\/(.*)\.css$/]
19
+ response['Content-Type'] = 'text/css'
20
+ response.body = SyntaxOn::theme request.path_info.match(/^\/styles\/(.*)\.css$/)[1]
21
+ else
22
+ response.body = response_for env
23
+ end
24
+
25
+ Dir.chdir @pwd
26
+
27
+ response.finish
28
+ end
29
+
30
+ def response_for env
31
+ path = env['PATH_INFO'].sub '/',''
32
+
33
+ if File.file? path
34
+ code_layout SyntaxOn.new( nil, :file => path ).to_html
35
+ else
36
+ code_layout
37
+ end
38
+ end
39
+
40
+ def file_list
41
+ '<ul>' + Dir['**/*'].map { |file_or_dir| %{<li><a href="/#{file_or_dir}">#{file_or_dir}</a></li>} }.join + '</ul>'
42
+ end
43
+
44
+ def theme_selector
45
+ <<HTML
46
+ <select id="theme-selector" onchange="javascript:window.location = window.location.toString().replace(/\\?.*/,'') + '?theme=' + document.getElementById('theme-selector').value">
47
+ <option>... select a theme ...</option>
48
+ #{ SyntaxOn::theme_names.map { |theme| "<option>#{theme}</option>" } }
49
+ </select>
50
+ HTML
51
+ end
52
+
53
+ def code_layout code = ''
54
+ <<HTML
55
+ <html>
56
+ <head>
57
+ <script src="http://jquery.com/src/jquery-latest.js" type="text/javascript"></script>
58
+ <style type="text/css">
59
+ <!--
60
+ select { position: absolute; top: 5px; right: 5px; }
61
+ -->
62
+ </style>
63
+ <link rel="stylesheet" href="/styles/#{ current_theme }.css" type="text/css" />
64
+ <head>
65
+ <body>
66
+ <h1>#{ @request.path_info }</h1>
67
+ #{ theme_selector }
68
+ <hr />
69
+ <pre>
70
+ #{ code }
71
+ </pre>
72
+ <hr />
73
+ #{ file_list }
74
+ </body>
75
+ </html>
76
+ HTML
77
+ end
78
+
79
+ def css # need to fix this ... can't seem to find the theme directory when running in thin ...
80
+ SyntaxOn::theme :murphy
81
+ end
82
+
83
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remi-syntax-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - remi Taylor
@@ -33,6 +33,7 @@ files:
33
33
  - bin/syntax-on
34
34
  - lib/syntax-on.rb
35
35
  - lib/syntax-on/bin.rb
36
+ - lib/syntax-on/browser.rb
36
37
  - themes/rubyblue.css
37
38
  - themes/peachpuff.css
38
39
  - themes/blue.css
@@ -54,6 +55,7 @@ files:
54
55
  - themes/torte.css
55
56
  - themes/shine.css
56
57
  - README
58
+ - TODO
57
59
  has_rdoc: true
58
60
  homepage: http://github.com/remi/syntax-on
59
61
  post_install_message: