sinatra-jshlp 0.1.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/.directory +6 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +177 -0
- data/Rakefile +7 -0
- data/lib/sinatra/jshlp.rb +84 -0
- data/sinatra-jshlp.gemspec +30 -0
- metadata +125 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2329f2b76c33f5b6df8db63b122c01a96565206c
|
|
4
|
+
data.tar.gz: 439c19360974117cef3458d26cf91514819a0ed0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d2a0206d38baed4c4c6ff08be3a016a87e731ff935ace01652111c778ae78f9c3bdd3bd48a8d79a7538cb19a16fba07e77980d345084372cbe6e0456ffd2a8ab
|
|
7
|
+
data.tar.gz: 52273967a6e52bdddf5a16608ca87141ab8549285e970b57c3eac264daf308e138770a0cad1830ac06ba1b2f39a6a8742b62e6d3506c20ed5c675efe590f48ee
|
data/.directory
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Contributor Code of Conduct
|
|
2
|
+
|
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
|
4
|
+
|
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
|
6
|
+
|
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
|
8
|
+
|
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
|
10
|
+
|
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
|
12
|
+
|
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 xtsidx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# sinatra-jshlp
|
|
2
|
+
|
|
3
|
+
Helpers for js and css assets in [Sinatra](https://github.com/sinatra/sinatra) applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'sinatra-jshlp'
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
$ gem install sinatra-jshlp
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
In Classic Applications
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
# app.rb
|
|
28
|
+
require 'sinatra'
|
|
29
|
+
require 'sinatra/jshlp'
|
|
30
|
+
|
|
31
|
+
#...
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
In Modular Applications
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
# app.rb
|
|
38
|
+
require 'sinatra/base'
|
|
39
|
+
require 'sinatra/jshlp'
|
|
40
|
+
|
|
41
|
+
class MyApp < Sinatra::Base
|
|
42
|
+
register Sinatra::JSHlp
|
|
43
|
+
|
|
44
|
+
# ...
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### JS and CSS from view to layout
|
|
50
|
+
|
|
51
|
+
Simple layout
|
|
52
|
+
```erb
|
|
53
|
+
<html>
|
|
54
|
+
<head>
|
|
55
|
+
<link rel="stylesheet" href="/css/style.css" />
|
|
56
|
+
<%= stylesheets %>
|
|
57
|
+
</head>
|
|
58
|
+
<body>
|
|
59
|
+
|
|
60
|
+
<%= yield %>
|
|
61
|
+
|
|
62
|
+
<script src="/js/script.js"></script>
|
|
63
|
+
<%= javascripts %>
|
|
64
|
+
</body>
|
|
65
|
+
</html>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Connect js and css in view
|
|
69
|
+
```erb
|
|
70
|
+
<%
|
|
71
|
+
jscode "alert('Hello from Main Page!');"
|
|
72
|
+
jslink '/lib/dateplugin.js'
|
|
73
|
+
jslink '/js/mainpage.js'
|
|
74
|
+
csslink '/css/mainpage.css'
|
|
75
|
+
jscode "alert('Thanx you!');"
|
|
76
|
+
%>
|
|
77
|
+
<h1>Main Page</h1>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Result HTML
|
|
81
|
+
```html
|
|
82
|
+
<html>
|
|
83
|
+
<head>
|
|
84
|
+
<link rel="stylesheet" href="/css/style.css" />
|
|
85
|
+
<link rel="stylesheet" href="/css/mainpage.css" />
|
|
86
|
+
</head>
|
|
87
|
+
<body>
|
|
88
|
+
<h1>Main Page</h1>
|
|
89
|
+
<script src="/js/script.js"></script>
|
|
90
|
+
<script src="/js/mainpage.js"></script>
|
|
91
|
+
<script src="/js/dateplugin.js"></script>
|
|
92
|
+
<script>
|
|
93
|
+
alert("Hello from Main Page!");
|
|
94
|
+
alert('Thanx you!');
|
|
95
|
+
</script>
|
|
96
|
+
</body>
|
|
97
|
+
</html>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Duplicate links
|
|
101
|
+
|
|
102
|
+
If you connect several times the JS or CSS file, in html once it connects.
|
|
103
|
+
```erb
|
|
104
|
+
# view.erb
|
|
105
|
+
<%
|
|
106
|
+
jslink '/lib/jslib.js'
|
|
107
|
+
jslink '/lib/jslib.js'
|
|
108
|
+
jslink '/lib/jslib.js'
|
|
109
|
+
%>
|
|
110
|
+
```
|
|
111
|
+
HTML Result
|
|
112
|
+
```html
|
|
113
|
+
...
|
|
114
|
+
<body>
|
|
115
|
+
...
|
|
116
|
+
<script src="/js/script.js"></script>
|
|
117
|
+
<script src="/lib/jslib.js"></script>
|
|
118
|
+
</body>
|
|
119
|
+
...
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Dividing javascripts
|
|
123
|
+
It is possible to split the output code.
|
|
124
|
+
```erb
|
|
125
|
+
<%= javascripts %>
|
|
126
|
+
|
|
127
|
+
analog of
|
|
128
|
+
|
|
129
|
+
<%= jslinks %>
|
|
130
|
+
<%= jscodes %>
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### JS library
|
|
135
|
+
|
|
136
|
+
Register your library
|
|
137
|
+
```ruby
|
|
138
|
+
configure do
|
|
139
|
+
jslibreg(
|
|
140
|
+
name: "datetimepicker",
|
|
141
|
+
jslinks: [ "/lib/datetimepicker/datetimepicker.js" ],
|
|
142
|
+
csslinks: [ "/lib/datetimepicker/datetimepicker.css" ]
|
|
143
|
+
)
|
|
144
|
+
end
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Use your library in view
|
|
148
|
+
```erb
|
|
149
|
+
<%
|
|
150
|
+
jslib "datetimepicker"
|
|
151
|
+
jscode "$('#dtp').datetimepicker();"
|
|
152
|
+
%>
|
|
153
|
+
<input id="dtp" type="text">
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Analog code
|
|
157
|
+
```erb
|
|
158
|
+
<%
|
|
159
|
+
jslink "/lib/datetimepicker/datetimepicker.js"
|
|
160
|
+
csslink "/lib/datetimepicker/datetimepicker.css"
|
|
161
|
+
jscode "$('#dtp').datetimepicker();"
|
|
162
|
+
%>
|
|
163
|
+
<input id="dtp" type="text">
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
169
|
+
|
|
170
|
+
## Contributing
|
|
171
|
+
|
|
172
|
+
1. Fork it ( https://github.com/xtsidx/sinatra-jshlp/fork )
|
|
173
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
174
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
175
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
176
|
+
5. Create a new Pull Request
|
|
177
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require 'sinatra/base'
|
|
2
|
+
|
|
3
|
+
module Sinatra
|
|
4
|
+
|
|
5
|
+
module JSHlp
|
|
6
|
+
|
|
7
|
+
module Helpers
|
|
8
|
+
|
|
9
|
+
def jslink(link)
|
|
10
|
+
@jslinks ||= []
|
|
11
|
+
@jslinks << link
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def csslink(link)
|
|
15
|
+
@csslinks ||= []
|
|
16
|
+
@csslinks << link
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def jscode(code)
|
|
20
|
+
@jscodes ||= ""
|
|
21
|
+
@jscodes << (code + "\n")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def jslinks
|
|
25
|
+
return "" unless @jslinks
|
|
26
|
+
links = @jslinks.compact
|
|
27
|
+
code = ""
|
|
28
|
+
links.each do |link|
|
|
29
|
+
code << "<script src='#{link}'></script>\n"
|
|
30
|
+
end
|
|
31
|
+
code
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def jscodes
|
|
35
|
+
return "" unless @jscodes
|
|
36
|
+
"<script>#{@jscodes}</script>"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def javascripts
|
|
40
|
+
"#{jslinks}\n#{jscodes}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def stylesheets
|
|
44
|
+
return "" unless @csslinks
|
|
45
|
+
links = @csslinks.compact
|
|
46
|
+
code = ""
|
|
47
|
+
links.each do |link|
|
|
48
|
+
code << "<link rel='stylesheet' href='#{link}' />"
|
|
49
|
+
end
|
|
50
|
+
code
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def jslib(name)
|
|
54
|
+
libsreg = self.class.jshlp[:libsreg]
|
|
55
|
+
raise "Not know this jslib: #{name}" unless libsreg.include? name
|
|
56
|
+
libsreg[name][:jslinks].each{ |l| jslink l }
|
|
57
|
+
libsreg[name][:csslinks].each{ |l| csslink l }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.registered(app)
|
|
63
|
+
app.helpers JSHlp::Helpers
|
|
64
|
+
|
|
65
|
+
app.set :jshlp, {
|
|
66
|
+
libsreg: {}, # зарегистрированные библиотеки
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def jslibreg(args)
|
|
71
|
+
libsreg = jshlp[:libsreg]
|
|
72
|
+
name = args[:name]
|
|
73
|
+
raise "JSlib name must be set!" unless name
|
|
74
|
+
libsreg[name] = {
|
|
75
|
+
jslinks: args[:jslinks] ||= [],
|
|
76
|
+
csslinks: args[:csslinks] ||= []
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
register JSHlp
|
|
83
|
+
|
|
84
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "sinatra-jshlp"
|
|
7
|
+
spec.version = "0.1.0"
|
|
8
|
+
spec.authors = ["xtsidx"]
|
|
9
|
+
spec.email = ["xtsidx@gmail.com"]
|
|
10
|
+
|
|
11
|
+
if spec.respond_to?(:metadata)
|
|
12
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
spec.summary = %q{Assets helper for JS and CSS files in Sinatra applications}
|
|
16
|
+
spec.description = %q{Simple and easy way for connect JS and CSS file in your Sinatra applications}
|
|
17
|
+
spec.homepage = "https://github.com/xtsidx/sinatra-jshlp"
|
|
18
|
+
spec.license = "MIT"
|
|
19
|
+
|
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
21
|
+
spec.bindir = "exe"
|
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
|
+
spec.require_paths = ["lib"]
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
28
|
+
spec.add_development_dependency "rack-test"
|
|
29
|
+
spec.add_dependency "sinatra"
|
|
30
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sinatra-jshlp
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- xtsidx
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.2'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.2'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.8'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.8'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rack-test
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: sinatra
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: Simple and easy way for connect JS and CSS file in your Sinatra applications
|
|
84
|
+
email:
|
|
85
|
+
- xtsidx@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".directory"
|
|
91
|
+
- ".gitignore"
|
|
92
|
+
- ".rspec"
|
|
93
|
+
- ".travis.yml"
|
|
94
|
+
- CODE_OF_CONDUCT.md
|
|
95
|
+
- Gemfile
|
|
96
|
+
- LICENSE.txt
|
|
97
|
+
- README.md
|
|
98
|
+
- Rakefile
|
|
99
|
+
- lib/sinatra/jshlp.rb
|
|
100
|
+
- sinatra-jshlp.gemspec
|
|
101
|
+
homepage: https://github.com/xtsidx/sinatra-jshlp
|
|
102
|
+
licenses:
|
|
103
|
+
- MIT
|
|
104
|
+
metadata: {}
|
|
105
|
+
post_install_message:
|
|
106
|
+
rdoc_options: []
|
|
107
|
+
require_paths:
|
|
108
|
+
- lib
|
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - ">="
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '0'
|
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
|
+
requirements:
|
|
116
|
+
- - ">="
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: '0'
|
|
119
|
+
requirements: []
|
|
120
|
+
rubyforge_project:
|
|
121
|
+
rubygems_version: 2.4.6
|
|
122
|
+
signing_key:
|
|
123
|
+
specification_version: 4
|
|
124
|
+
summary: Assets helper for JS and CSS files in Sinatra applications
|
|
125
|
+
test_files: []
|