mulberry_preview 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ef0e373452c98e52c87aefe022a9713dd88f573
4
- data.tar.gz: c097671b58078c8ee1d6ec020b0d12b8cb4ea40d
3
+ metadata.gz: 8f81c1197f78c15c5163f70a7f784b1da6c263d2
4
+ data.tar.gz: 50af7446e84566cd10f3e6fd8573e9f96e40e9f7
5
5
  SHA512:
6
- metadata.gz: d88e666e03734e5d134dad382d7eb1ff5e3fa16bd5a564f42bf64528ffcf1942c7fb9588af55935e9482bbe6c8f957d667d15e83f97381ad77d7612c4c2b89c8
7
- data.tar.gz: 7c744a94b9204e8f3e1f15591eb5c6da1b5a8c51afd9c53651055b916af8fb351f802299b8062ff9eb3a5e20b8e07bd4cb89742158870142b871283c468c588f
6
+ metadata.gz: 3ab2d89c3de59c7e13bedc42d4821c2c72f09168a5049031f9ef92a0c0c8e4d23e22d289420333fbdb5f274c984e6789dfc8f7be8db4372c999d8965ef105ba6
7
+ data.tar.gz: 045881ed80ecfac365b5e764a9778caf24eec96531784ad70e980f733039dd040c0c11e9215ad1c79859df81bc46fb2d33611ce4e910bc5b55875d2555b80e1a
@@ -0,0 +1,148 @@
1
+ @import "twitter/bootstrap";
2
+
3
+ .CodeRay {
4
+ background-color: #efefef;
5
+ font-family: Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
6
+ color: #000;
7
+ margin-bottom: 14px;
8
+
9
+ pre {
10
+ display: block;
11
+ padding: 5px;
12
+ margin: 0;
13
+ font-size: 13px;
14
+ line-height: 20px;
15
+ word-break: break-all;
16
+ word-wrap: break-word;
17
+ white-space: pre;
18
+ background-color: #fcfcfc;
19
+ border: 1px solid #fcfcfc;
20
+ -webkit-border-radius: 5px;
21
+ -moz-border-radius: 5px;
22
+ border-radius: 5px;
23
+ }
24
+
25
+ .line-numbers, .no {
26
+ background-color: #ECECEC;
27
+ color: #AAA;
28
+ text-align: right;
29
+ }
30
+
31
+ .line-numbers {
32
+ a { color: #AAA; }
33
+ tt { font-weight: bold }
34
+ .highlighted { color: red }
35
+ .line { display: block; float: left; width: 100%; }
36
+ }
37
+
38
+ span.line-numbers { padding: 0px 4px }
39
+ .code {
40
+ width: 100%;
41
+ pre { overflow: auto }
42
+ }
43
+
44
+ .debug { color:white ! important; background:blue ! important; }
45
+ .annotation { color:#007 }
46
+ .attribute-name { color:#f08 }
47
+ .attribute-value { color:#700 }
48
+ .binary { color:#509; font-weight:bold }
49
+ .comment { color:#998; font-style: italic;}
50
+ .char { color:#04D }
51
+ .char .content { color:#04D }
52
+ .char .delimiter { color:#039 }
53
+ .class { color:#458; font-weight:bold }
54
+ .complex { color:#A08; font-weight:bold }
55
+ .constant { color:teal; }
56
+ .color { color:#0A0 }
57
+ .class-variable { color:#369 }
58
+ .decorator { color:#B0B; }
59
+ .definition { color:#099; font-weight:bold }
60
+ .directive { color:#088; font-weight:bold }
61
+ .delimiter { color:black }
62
+ .doc { color:#970 }
63
+ .doctype { color:#34b }
64
+ .doc-string { color:#D42; font-weight:bold }
65
+ .escape { color:#666; font-weight:bold }
66
+ .entity { color:#800; font-weight:bold }
67
+ .error { color:#F00; background-color:#FAA }
68
+ .exception { color:#C00; font-weight:bold }
69
+ .filename { color:#099; }
70
+ .function { color:#900; font-weight:bold }
71
+ .global-variable { color:teal; font-weight:bold }
72
+ .hex { color:#058; font-weight:bold }
73
+ .integer { color:#099; }
74
+ .include { color:#B44; font-weight:bold }
75
+ .inline { color: black }
76
+ .inline .inline { background: #ccc }
77
+ .inline .inline .inline { background: #bbb }
78
+ .inline .inline-delimiter { color: #D14; }
79
+ .inline-delimiter { color: #D14; }
80
+ .important { color:#f00; }
81
+ .interpreted { color:#B2B; font-weight:bold }
82
+ .instance-variable { color:teal }
83
+ .label { color:#970; font-weight:bold }
84
+ .local-variable { color:#963 }
85
+ .octal { color:#40E; font-weight:bold }
86
+ .operator { }
87
+ .predefined-constant { font-weight:bold }
88
+ .predefined { color:#369; font-weight:bold }
89
+ .preprocessor { color:#579; }
90
+ .pseudo-class { color:#00C; font-weight:bold }
91
+ .predefined-type { color:#074; font-weight:bold }
92
+ .reserved, .keyword { color:#000; font-weight:bold }
93
+
94
+ .key { color: #808; }
95
+ .key .delimiter { color: #606; }
96
+ .key .char { color: #80f; }
97
+ .value { color: #088; }
98
+
99
+ .regexp { background-color:#fff0ff }
100
+ .regexp .content { color:#808 }
101
+ .regexp .delimiter { color:#404 }
102
+ .regexp .modifier { color:#C2C }
103
+ .regexp .function { color:#404; font-weight: bold }
104
+
105
+ .string { color: #D20; }
106
+ .string .string { }
107
+ .string .string .string { background-color:#ffd0d0 }
108
+ .string .content { color: #D14; }
109
+ .string .char { color: #D14; }
110
+ .string .delimiter { color: #D14; }
111
+
112
+ .shell { color:#D14 }
113
+ .shell .content { }
114
+ .shell .delimiter { color:#D14 }
115
+
116
+ .symbol { color:#990073 }
117
+ .symbol .content { color:#A60 }
118
+ .symbol .delimiter { color:#630 }
119
+
120
+ .tag { color:#070 }
121
+ .tag-special { color:#D70; font-weight:bold }
122
+ .type { color:#339; font-weight:bold }
123
+ .variable { color:#036 }
124
+
125
+ .insert { background: #afa; }
126
+ .delete { background: #faa; }
127
+ .change { color: #aaf; background: #007; }
128
+ .head { color: #f8f; background: #505 }
129
+
130
+ .insert .insert { color: #080; font-weight:bold }
131
+ .delete .delete { color: #800; font-weight:bold }
132
+ .change .change { color: #66f; }
133
+ .head .head { color: #f4f; }
134
+ }
135
+
136
+
137
+ div.CodeRay { }
138
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px }
139
+
140
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
141
+ table.CodeRay td {
142
+ padding: 1em 0.5em;
143
+ vertical-align: top;
144
+ }
145
+
146
+ ol.CodeRay { font-size: 10pt }
147
+ ol.CodeRay li { white-space: pre }
148
+
@@ -1,27 +1,32 @@
1
1
  class PreviewController < ActionController::Base
2
2
 
3
3
  Languages = [:ruby, :python, :java, :js, :scss, :sass, :haml, :json,
4
- :go, :sql, :yaml, :c, :coffee, :properties]
4
+ :go, :sql, :yaml, :c, :coffee, :properties, :clojure]
5
5
 
6
6
  def index
7
7
  clazz, id = params[:type].classify.constantize, params[:id]
8
8
  r = clazz.find(id)
9
- type, ext = r.content_type[/^[^\/]+/].to_sym, r.content_type[/(?<=\/)(x-)?(.+)/, 2].to_sym
10
- if Languages.include?(ext)
11
- @code = CodeRay.scan(r.content, ext).div(:line_numbers => :table, :css => :class)
12
- render 'code', layout: 'coderay'
13
- elsif [:pdf, :html].include?(ext)
14
- render_native(r.content, r.content_type)
15
- else
16
- case type
17
- when :text
18
- render_native(r.content, 'text/plain')
19
- when :image
20
- render_native(r.content, r.content_type)
9
+ if r
10
+ mime = r.content_type
11
+ type, ext = mime[/^[^\/]+/].to_sym, mime[/(?<=\/)(x-)?(.+)/, 2].to_sym
12
+ if Languages.include?(ext)
13
+ @code = CodeRay.scan(r.content, ext).div(:line_numbers => :table, :css => :class)
14
+ render 'code', layout: 'coderay'
15
+ elsif [:pdf, :html].include?(ext)
16
+ render_native(r.content, mime)
21
17
  else
22
- @resource = r
23
- render 'download', layout: 'coderay'
18
+ case type
19
+ when :text
20
+ render_native(r.content, 'text/plain')
21
+ when :image, :video, :audio
22
+ render_native(r.content, mime)
23
+ else
24
+ @resource = r
25
+ render 'download', layout: 'coderay'
26
+ end
24
27
  end
28
+ else
29
+ render text: "#{r} or #{r.content_type} is not acceptable.", content_type: 'text/plain'
25
30
  end
26
31
  end
27
32
 
@@ -42,7 +47,11 @@ class PreviewController < ActionController::Base
42
47
  def download
43
48
  clazz, id = params[:type].classify.constantize, params[:id]
44
49
  r = clazz.find(id)
45
- render_native(r.content, r.content_type)
50
+ if r
51
+ render_native(r.content, r.content_type || 'application/octet-stream')
52
+ else
53
+ head :no_content
54
+ end
46
55
  end
47
56
 
48
57
  private
@@ -1,8 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Webfs</title>
5
- <%= stylesheet_link_tag "twitter/bootstrap", media: "all" %>
4
+ <title>Preview</title>
6
5
  <%= stylesheet_link_tag "coderay", media: "all" %>
7
6
  <%= csrf_meta_tags %>
8
7
  </head>
@@ -1,6 +1,9 @@
1
- <div class="jumbotron container">
2
- <%= link_to download_path(@resource.class.name.underscore, @resource.id) do %>
3
- <i class="glyphicon glyphicon-download"></i><%= @resource.name %>
4
- <% end %>
5
- [<%= @resource.content_type %>]
6
- </div>
1
+ <div class="container">
2
+ <br />
3
+ <div class="jumbotron">
4
+ <%= link_to download_path(@resource.class.name.underscore, @resource.id) do %>
5
+ <i class="glyphicon glyphicon-download"></i><%= @resource.name %>
6
+ <% end %>
7
+ [<%= @resource.content_type %>]
8
+ </div>
9
+ </div>
data/config/routes.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- get "preview/:type/:id" => "preview#index", as: :preview
4
- get "download/:type/:id" => "preview#download", as: :download
5
- post "open" => "preview#open"
3
+ get 'preview/:type/:id' => 'preview#index', as: :preview
4
+ get 'download/:type/:id' => 'preview#download', as: :download
5
+ post 'open' => 'preview#open'
6
6
 
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module MulberryPreview
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mulberry_preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Zhan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-24 00:00:00.000000000 Z
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,20 +30,34 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 4.1.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bootstrap-sass-rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: sqlite3
35
49
  requirement: !ruby/object:Gem::Requirement
36
50
  requirements:
37
51
  - - "~>"
38
52
  - !ruby/object:Gem::Version
39
- version: '0'
53
+ version: '1'
40
54
  type: :development
41
55
  prerelease: false
42
56
  version_requirements: !ruby/object:Gem::Requirement
43
57
  requirements:
44
58
  - - "~>"
45
59
  - !ruby/object:Gem::Version
46
- version: '0'
60
+ version: '1'
47
61
  description: Can preview files and format the view.
48
62
  email:
49
63
  - zhiqiangzhan@gmail.com
@@ -54,7 +68,7 @@ files:
54
68
  - MIT-LICENSE
55
69
  - README.rdoc
56
70
  - Rakefile
57
- - app/assets/stylesheets/coderay.css
71
+ - app/assets/stylesheets/coderay.css.scss
58
72
  - app/controllers/preview_controller.rb
59
73
  - app/views/layouts/coderay.html.erb
60
74
  - app/views/preview/code.html.erb
@@ -1,143 +0,0 @@
1
- .CodeRay {
2
- background-color: #efefef;
3
- font-family: Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
4
- color: #000;
5
- margin-bottom: 14px;
6
- }
7
-
8
- .CodeRay pre {
9
- display: block;
10
- padding: 5px;
11
- margin: 0;
12
- font-size: 13px;
13
- line-height: 20px;
14
- word-break: break-all;
15
- word-wrap: break-word;
16
- white-space: pre;
17
- background-color: #fcfcfc;
18
- border: 1px solid #fcfcfc;
19
- -webkit-border-radius: 5px;
20
- -moz-border-radius: 5px;
21
- border-radius: 5px;
22
- }
23
-
24
- div.CodeRay { }
25
- span.CodeRay { white-space: pre; border: 0px; padding: 2px }
26
-
27
- table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
28
- table.CodeRay td {
29
- padding: 1em 0.5em;
30
- vertical-align: top;
31
- }
32
-
33
- .CodeRay .line-numbers, .CodeRay .no {
34
- background-color: #ECECEC;
35
- color: #AAA;
36
- text-align: right;
37
- }
38
-
39
- .CodeRay .line-numbers a {
40
- color: #AAA;
41
- }
42
-
43
- .CodeRay .line-numbers tt { font-weight: bold }
44
- .CodeRay .line-numbers .highlighted { color: red }
45
- .CodeRay .line { display: block; float: left; width: 100%; }
46
- .CodeRay span.line-numbers { padding: 0px 4px }
47
- .CodeRay .code { width: 100% }
48
-
49
- ol.CodeRay { font-size: 10pt }
50
- ol.CodeRay li { white-space: pre }
51
-
52
- .CodeRay .code pre { overflow: auto }
53
- .CodeRay .debug { color:white ! important; background:blue ! important; }
54
-
55
- .CodeRay .annotation { color:#007 }
56
- .CodeRay .attribute-name { color:#f08 }
57
- .CodeRay .attribute-value { color:#700 }
58
- .CodeRay .binary { color:#509; font-weight:bold }
59
- .CodeRay .comment { color:#998; font-style: italic;}
60
- .CodeRay .char { color:#04D }
61
- .CodeRay .char .content { color:#04D }
62
- .CodeRay .char .delimiter { color:#039 }
63
- .CodeRay .class { color:#458; font-weight:bold }
64
- .CodeRay .complex { color:#A08; font-weight:bold }
65
- .CodeRay .constant { color:teal; }
66
- .CodeRay .color { color:#0A0 }
67
- .CodeRay .class-variable { color:#369 }
68
- .CodeRay .decorator { color:#B0B; }
69
- .CodeRay .definition { color:#099; font-weight:bold }
70
- .CodeRay .directive { color:#088; font-weight:bold }
71
- .CodeRay .delimiter { color:black }
72
- .CodeRay .doc { color:#970 }
73
- .CodeRay .doctype { color:#34b }
74
- .CodeRay .doc-string { color:#D42; font-weight:bold }
75
- .CodeRay .escape { color:#666; font-weight:bold }
76
- .CodeRay .entity { color:#800; font-weight:bold }
77
- .CodeRay .error { color:#F00; background-color:#FAA }
78
- .CodeRay .exception { color:#C00; font-weight:bold }
79
- .CodeRay .filename { color:#099; }
80
- .CodeRay .function { color:#900; font-weight:bold }
81
- .CodeRay .global-variable { color:teal; font-weight:bold }
82
- .CodeRay .hex { color:#058; font-weight:bold }
83
- .CodeRay .integer { color:#099; }
84
- .CodeRay .include { color:#B44; font-weight:bold }
85
- .CodeRay .inline { color: black }
86
- .CodeRay .inline .inline { background: #ccc }
87
- .CodeRay .inline .inline .inline { background: #bbb }
88
- .CodeRay .inline .inline-delimiter { color: #D14; }
89
- .CodeRay .inline-delimiter { color: #D14; }
90
- .CodeRay .important { color:#f00; }
91
- .CodeRay .interpreted { color:#B2B; font-weight:bold }
92
- .CodeRay .instance-variable { color:teal }
93
- .CodeRay .label { color:#970; font-weight:bold }
94
- .CodeRay .local-variable { color:#963 }
95
- .CodeRay .octal { color:#40E; font-weight:bold }
96
- .CodeRay .operator { }
97
- .CodeRay .predefined-constant { font-weight:bold }
98
- .CodeRay .predefined { color:#369; font-weight:bold }
99
- .CodeRay .preprocessor { color:#579; }
100
- .CodeRay .pseudo-class { color:#00C; font-weight:bold }
101
- .CodeRay .predefined-type { color:#074; font-weight:bold }
102
- .CodeRay .reserved, .keyword { color:#000; font-weight:bold }
103
-
104
- .CodeRay .key { color: #808; }
105
- .CodeRay .key .delimiter { color: #606; }
106
- .CodeRay .key .char { color: #80f; }
107
- .CodeRay .value { color: #088; }
108
-
109
- .CodeRay .regexp { background-color:#fff0ff }
110
- .CodeRay .regexp .content { color:#808 }
111
- .CodeRay .regexp .delimiter { color:#404 }
112
- .CodeRay .regexp .modifier { color:#C2C }
113
- .CodeRay .regexp .function { color:#404; font-weight: bold }
114
-
115
- .CodeRay .string { color: #D20; }
116
- .CodeRay .string .string { }
117
- .CodeRay .string .string .string { background-color:#ffd0d0 }
118
- .CodeRay .string .content { color: #D14; }
119
- .CodeRay .string .char { color: #D14; }
120
- .CodeRay .string .delimiter { color: #D14; }
121
-
122
- .CodeRay .shell { color:#D14 }
123
- .CodeRay .shell .content { }
124
- .CodeRay .shell .delimiter { color:#D14 }
125
-
126
- .CodeRay .symbol { color:#990073 }
127
- .CodeRay .symbol .content { color:#A60 }
128
- .CodeRay .symbol .delimiter { color:#630 }
129
-
130
- .CodeRay .tag { color:#070 }
131
- .CodeRay .tag-special { color:#D70; font-weight:bold }
132
- .CodeRay .type { color:#339; font-weight:bold }
133
- .CodeRay .variable { color:#036 }
134
-
135
- .CodeRay .insert { background: #afa; }
136
- .CodeRay .delete { background: #faa; }
137
- .CodeRay .change { color: #aaf; background: #007; }
138
- .CodeRay .head { color: #f8f; background: #505 }
139
-
140
- .CodeRay .insert .insert { color: #080; font-weight:bold }
141
- .CodeRay .delete .delete { color: #800; font-weight:bold }
142
- .CodeRay .change .change { color: #66f; }
143
- .CodeRay .head .head { color: #f4f; }