rack-source 0.0.1

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 (4) hide show
  1. data/README.md +34 -0
  2. data/lib/rack/source.rb +36 -0
  3. data/lib/rack-source.rb +1 -0
  4. metadata +94 -0
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Rack Source
2
+
3
+ Serves a file with syntax highlighting. Rack::Source has the simplicity of Rack::File, combined with the usefulness of Rack::CodeHighlighter, except using GitHub's Pygments gem under the hood.
4
+
5
+ # Setup
6
+
7
+ ```
8
+ gem install rack-source
9
+ ```
10
+
11
+ ```ruby
12
+ # config.ru
13
+ require 'rack/source'
14
+
15
+ run Rack::Source.new('path/to/file')
16
+ ```
17
+
18
+ ```
19
+ rackup
20
+ ```
21
+
22
+ It usually does a good job of detecting the source language, but you can force it, i.e.
23
+
24
+ ```ruby
25
+ run Rack::Source.new(__FILE__, :lexer => :ruby)
26
+ ```
27
+
28
+ All parameters are passed through to [Pygments](https://github.com/tmm1/pygments.rb), so look there for additional options and supported lexers.
29
+
30
+ # Contribution
31
+
32
+ Feel free. No pull request is too small.
33
+
34
+ [@cpatuzzo](https://twitter.com/#!/cpatuzzo)
@@ -0,0 +1,36 @@
1
+ require 'rack'
2
+ require 'pygments'
3
+
4
+ module Rack
5
+ class Source
6
+
7
+ attr_reader :path, :params
8
+
9
+ def initialize(path, params = {})
10
+ @path = path
11
+ @params = params
12
+ end
13
+
14
+ def call(env)
15
+ [200, { 'Content-Type' => 'text/html' }, [html]]
16
+ end
17
+
18
+ private
19
+ def html
20
+ "<html><head><style>#{style}</style></head><body>#{body}</body></html>"
21
+ end
22
+
23
+ def style
24
+ Pygments.css
25
+ end
26
+
27
+ def body
28
+ Pygments.highlight(file_content, params)
29
+ end
30
+
31
+ def file_content
32
+ ::File.read(path)
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rack', 'source')
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-source
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Christopher Patuzzo
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-06-01 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rack
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: pygments.rb
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: Serves a file with syntax highlighting
49
+ email: chris.patuzzo@gmail.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - README.md
58
+ - lib/rack/source.rb
59
+ - lib/rack-source.rb
60
+ homepage: https://github.com/cpatuzzo/rack-source
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.22
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Rack Source
93
+ test_files: []
94
+