gist-embed-rails 2.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +28 -0
- data/gist-embed-rails.gemspec +23 -0
- data/lib/gist/embed/rails.rb +10 -0
- data/lib/gist/embed/rails/version.rb +7 -0
- data/vendor/assets/javascripts/gist-embed.js +174 -0
- metadata +82 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9bebff69e7b40aed3143265116cbc2070d0f60c0
|
|
4
|
+
data.tar.gz: 07df665c8f00c04f1e2eed7888637fdd80dc51ab
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b4d70aa891ade4477349cfacff8503be18e2b1c7b3a8c9597a9547c7218104a15fc7f2c76b8c7752de65b32aba5e0312107e4fb6c6c32079e5506066267f9e11
|
|
7
|
+
data.tar.gz: a3c4267b7f42306d5fb8308475384862d98f067da06c7194a1f9d9b40011fa1d066e44fd06039c002e6343c413d8300d06080a060a445ba3973ed3af5b5d43fe
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Ponomarev Nikolay
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# gist-embed.js for Rails
|
|
2
|
+
|
|
3
|
+
[gist-embed.js](https://github.com/blairvanderhoof/gist-embed) for Rails
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'gist-embed-rails'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install gist-embed-rails
|
|
20
|
+
|
|
21
|
+
Add to `application.js`
|
|
22
|
+
```javascript
|
|
23
|
+
//= require jquery
|
|
24
|
+
//= require gist-embed
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Add in html template:
|
|
28
|
+
```html
|
|
29
|
+
<code data-gist-id="<gist-id>"></code>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
Variants of usage: [http://blairvanderhoof.com](http://blairvanderhoof.com/gist-embed/)
|
|
35
|
+
|
|
36
|
+
## Turbolinks
|
|
37
|
+
Compatable with [jquery.turbolinks](https://github.com/kossnocorp/jquery.turbolinks)
|
|
38
|
+
|
|
39
|
+
## Contributing
|
|
40
|
+
|
|
41
|
+
To refresh gem, run:
|
|
42
|
+
```shell
|
|
43
|
+
$ rake upload
|
|
44
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'net/http'
|
|
4
|
+
|
|
5
|
+
begin
|
|
6
|
+
require 'bundler/setup'
|
|
7
|
+
rescue LoadError
|
|
8
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
require 'bundler'
|
|
12
|
+
require 'rake'
|
|
13
|
+
|
|
14
|
+
desc 'Upload lib files from remote repo'
|
|
15
|
+
task :upload do
|
|
16
|
+
js_filename = "gist-embed.js"
|
|
17
|
+
js_url = "https://raw.githubusercontent.com/blairvanderhoof/gist-embed/master/#{js_filename}"
|
|
18
|
+
js_path = "vendor/assets/javascripts/#{js_filename}"
|
|
19
|
+
|
|
20
|
+
response = Net::HTTP.get( URI(js_url) )
|
|
21
|
+
if File.write(js_path, response)
|
|
22
|
+
puts %Q{
|
|
23
|
+
-->> #{js_url}
|
|
24
|
+
was succesfully uploaded to:
|
|
25
|
+
-->> #{js_path}
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'gist/embed/rails/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "gist-embed-rails"
|
|
8
|
+
spec.version = Gist::Embed::Rails::VERSION
|
|
9
|
+
spec.authors = ["Ponomarev Nikolay", "Blair Vanderhoof"]
|
|
10
|
+
spec.email = ["itsnikolay@gmail.com"]
|
|
11
|
+
spec.summary = %q{Gist embeded for RubyOnRails}
|
|
12
|
+
spec.description = %q{Gist embeded for RubyOnRails}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
23
|
+
end
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// author: Blair Vanderhoof
|
|
2
|
+
// https://github.com/blairvanderhoof/gist-embed
|
|
3
|
+
// version 2.0
|
|
4
|
+
(function($) {
|
|
5
|
+
|
|
6
|
+
function getLineNumbers(lineRangeString) {
|
|
7
|
+
var lineNumbers = [], range, lineNumberSections;
|
|
8
|
+
|
|
9
|
+
if (typeof lineRangeString === 'number') {
|
|
10
|
+
lineNumbers.push(lineRangeString);
|
|
11
|
+
} else {
|
|
12
|
+
lineNumberSections = lineRangeString.split(',');
|
|
13
|
+
|
|
14
|
+
for (var i = 0; i < lineNumberSections.length; i++) {
|
|
15
|
+
range = lineNumberSections[i].split('-');
|
|
16
|
+
if (range.length === 2) {
|
|
17
|
+
for (var j = parseInt(range[0], 10); j <= range[1]; j++) {
|
|
18
|
+
lineNumbers.push(j);
|
|
19
|
+
}
|
|
20
|
+
} else if (range.length === 1) {
|
|
21
|
+
lineNumbers.push(parseInt(range[0], 10));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return lineNumbers;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
$.fn.gist = function() {
|
|
29
|
+
return this.each(function() {
|
|
30
|
+
var $elem = $(this),
|
|
31
|
+
id,
|
|
32
|
+
url,
|
|
33
|
+
file,
|
|
34
|
+
lines,
|
|
35
|
+
highlightLines,
|
|
36
|
+
hideFooterOption,
|
|
37
|
+
hideLineNumbersOption,
|
|
38
|
+
data = {};
|
|
39
|
+
|
|
40
|
+
// make block level so loading text shows properly
|
|
41
|
+
$elem.css('display', 'block');
|
|
42
|
+
|
|
43
|
+
id = $elem.data('gist-id') || '';
|
|
44
|
+
file = $elem.data('gist-file');
|
|
45
|
+
hideFooterOption = $elem.data('gist-hide-footer') === true;
|
|
46
|
+
hideLineNumbersOption = $elem.data('gist-hide-line-numbers') === true;
|
|
47
|
+
lines = $elem.data('gist-line');
|
|
48
|
+
highlightLines = $elem.data('gist-highlight-line');
|
|
49
|
+
|
|
50
|
+
if (file) {
|
|
51
|
+
data.file = file;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// if the id doesn't exist, then ignore the code block
|
|
55
|
+
if (!id) return false;
|
|
56
|
+
|
|
57
|
+
url = 'https://gist.github.com/' + id + '.json';
|
|
58
|
+
|
|
59
|
+
// loading
|
|
60
|
+
$elem.html('Loading gist ' + url + (data.file ? ', file: ' + data.file : '') + '...');
|
|
61
|
+
|
|
62
|
+
// request the json version of this gist
|
|
63
|
+
$.ajax({
|
|
64
|
+
url: url,
|
|
65
|
+
data: data,
|
|
66
|
+
dataType: 'jsonp',
|
|
67
|
+
timeout: 10000,
|
|
68
|
+
success: function(response) {
|
|
69
|
+
var linkTag,
|
|
70
|
+
head,
|
|
71
|
+
lineNumbers,
|
|
72
|
+
highlightLineNumbers,
|
|
73
|
+
$responseDiv;
|
|
74
|
+
|
|
75
|
+
// the html payload is in the div property
|
|
76
|
+
if (response && response.div) {
|
|
77
|
+
// github returns /assets/embed-id.css now, but let's be sure about that
|
|
78
|
+
if (response.stylesheet && response.stylesheet.indexOf('http') !== 0) {
|
|
79
|
+
// add leading slash if missing
|
|
80
|
+
if (response.stylesheet.indexOf('/') !== 0) {
|
|
81
|
+
response.stylesheet = '/' + response.stylesheet;
|
|
82
|
+
}
|
|
83
|
+
response.stylesheet = 'https://gist.github.com' + response.stylesheet;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// add the stylesheet if it does not exist
|
|
87
|
+
if (response.stylesheet && $('link[href="' + response.stylesheet + '"]').length === 0) {
|
|
88
|
+
linkTag = document.createElement('link');
|
|
89
|
+
head = document.getElementsByTagName('head')[0];
|
|
90
|
+
|
|
91
|
+
linkTag.type = 'text/css';
|
|
92
|
+
linkTag.rel = 'stylesheet';
|
|
93
|
+
linkTag.href = response.stylesheet;
|
|
94
|
+
head.insertBefore(linkTag, head.firstChild);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// refernce to div
|
|
98
|
+
$responseDiv = $(response.div);
|
|
99
|
+
|
|
100
|
+
// remove id for uniqueness constraints
|
|
101
|
+
$responseDiv.removeAttr('id');
|
|
102
|
+
|
|
103
|
+
$elem.html('').append($responseDiv);
|
|
104
|
+
|
|
105
|
+
// option to highlight lines
|
|
106
|
+
if (highlightLines) {
|
|
107
|
+
highlightLineNumbers = getLineNumbers(highlightLines);
|
|
108
|
+
|
|
109
|
+
// we need to set the line-data td to 100% so the highlight expands the whole line
|
|
110
|
+
$responseDiv.find('td.line-data').css({
|
|
111
|
+
'width': '100%'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// find all .line divs (acutal code lines) that match the highlightLines and add the highlight class
|
|
115
|
+
$responseDiv.find('.line').each(function(index) {
|
|
116
|
+
if ($.inArray(index + 1, highlightLineNumbers) !== -1) {
|
|
117
|
+
$(this).css({
|
|
118
|
+
'background-color': 'rgb(255, 255, 204)'
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// if user provided a line param, get the line numbers baesed on the criteria
|
|
125
|
+
if (lines) {
|
|
126
|
+
lineNumbers = getLineNumbers(lines);
|
|
127
|
+
|
|
128
|
+
// find all .line divs (acutal code lines) and remove them if they don't exist in the line param
|
|
129
|
+
$responseDiv.find('.line').each(function(index) {
|
|
130
|
+
if (($.inArray(index + 1, lineNumbers)) === -1) {
|
|
131
|
+
$(this).remove();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// find all .line-number divs (numbers on the gutter) and remove them if they don't exist in the line param
|
|
136
|
+
$responseDiv.find('.line-number').each(function(index) {
|
|
137
|
+
if (($.inArray(index + 1, lineNumbers)) === -1) {
|
|
138
|
+
$(this).remove();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// option to remove footer
|
|
144
|
+
if (hideFooterOption) {
|
|
145
|
+
$responseDiv.find('.gist-meta').remove();
|
|
146
|
+
|
|
147
|
+
// present a uniformed border when footer is hidden
|
|
148
|
+
$responseDiv.find('.gist-data').css("border-bottom", "0px");
|
|
149
|
+
$responseDiv.find('.gist-file').css("border-bottom", "1px solid #ddd");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// option to remove
|
|
153
|
+
if (hideLineNumbersOption) {
|
|
154
|
+
$responseDiv.find('.line-numbers').remove();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
} else {
|
|
158
|
+
$elem.html('Failed loading gist ' + url);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
error: function(jqXHR, textStatus) {
|
|
162
|
+
$elem.html('Failed loading gist ' + url + ': ' + textStatus);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
$(function() {
|
|
170
|
+
// find all elements containing "data-gist-id" attribute.
|
|
171
|
+
$('[data-gist-id]').gist();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
})(jQuery);
|
metadata
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: gist-embed-rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ponomarev Nikolay
|
|
8
|
+
- Blair Vanderhoof
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: bundler
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - "~>"
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: '1.7'
|
|
21
|
+
type: :development
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - "~>"
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: '1.7'
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: rake
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - "~>"
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '10.0'
|
|
35
|
+
type: :development
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - "~>"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '10.0'
|
|
42
|
+
description: Gist embeded for RubyOnRails
|
|
43
|
+
email:
|
|
44
|
+
- itsnikolay@gmail.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".gitignore"
|
|
50
|
+
- Gemfile
|
|
51
|
+
- LICENSE.txt
|
|
52
|
+
- README.md
|
|
53
|
+
- Rakefile
|
|
54
|
+
- gist-embed-rails.gemspec
|
|
55
|
+
- lib/gist/embed/rails.rb
|
|
56
|
+
- lib/gist/embed/rails/version.rb
|
|
57
|
+
- vendor/assets/javascripts/gist-embed.js
|
|
58
|
+
homepage: ''
|
|
59
|
+
licenses:
|
|
60
|
+
- MIT
|
|
61
|
+
metadata: {}
|
|
62
|
+
post_install_message:
|
|
63
|
+
rdoc_options: []
|
|
64
|
+
require_paths:
|
|
65
|
+
- lib
|
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
requirements: []
|
|
77
|
+
rubyforge_project:
|
|
78
|
+
rubygems_version: 2.2.2
|
|
79
|
+
signing_key:
|
|
80
|
+
specification_version: 4
|
|
81
|
+
summary: Gist embeded for RubyOnRails
|
|
82
|
+
test_files: []
|