styxie 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.
- checksums.yaml +7 -0
- data/.gitignore +53 -0
- data/.rubocop.yml +299 -0
- data/.travis.yml +10 -0
- data/Dockerfile +7 -0
- data/Gemfile +15 -0
- data/LICENSE +22 -0
- data/README.md +79 -0
- data/Rakefile +8 -0
- data/app/assets/javascripts/styxie.js.coffee +22 -0
- data/app/views/styxie/_initializer.html.erb +12 -0
- data/docker-compose.yml +5 -0
- data/init.rb +2 -0
- data/lib/styxie/engine.rb +5 -0
- data/lib/styxie/helpers.rb +16 -0
- data/lib/styxie/initializer.rb +26 -0
- data/lib/styxie.rb +9 -0
- data/spec/controllers/tests_controller_spec.rb +12 -0
- data/spec/internal/app/controllers/tests_controller.rb +15 -0
- data/spec/internal/app/views/tests/index.html.erb +1 -0
- data/spec/internal/config/routes.rb +4 -0
- data/spec/internal/db/schema.rb +0 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/lib/styxie_helpers_spec.rb +63 -0
- data/spec/lib/styxie_initializer_spec.rb +28 -0
- data/spec/spec_helper.rb +13 -0
- data/styxie.gemspec +15 -0
- metadata +70 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5d2156cfb84c6af5e34dc8519e9c45cddbfe9c1f
|
|
4
|
+
data.tar.gz: f4b9bcb8b735cc5285fa1fbe75828db219e5c121
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: abdd26d978c1334c0138bf9fefd442f0ec21c39f5af03c5ad8eccd2aa66064538237fb09265af1f2e8e09167552dcb00ed3f42faf3e44ab066dd72d96452c4a1
|
|
7
|
+
data.tar.gz: 6588c7c4ea55f3aacad4cdace62cfb55a4e3e4bf590e4ecf13a72991c086f05f88481442ee9ec20e6a5970e834fec0a3d6487e984aac5329ce5f4857e08b3689
|
data/.gitignore
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
.idea/
|
|
2
|
+
.rspec
|
|
3
|
+
|
|
4
|
+
*.gem
|
|
5
|
+
*.rbc
|
|
6
|
+
/.config
|
|
7
|
+
/coverage/
|
|
8
|
+
/InstalledFiles
|
|
9
|
+
/pkg/
|
|
10
|
+
/spec/reports/
|
|
11
|
+
/spec/examples.txt
|
|
12
|
+
/test/tmp/
|
|
13
|
+
/test/version_tmp/
|
|
14
|
+
/tmp/
|
|
15
|
+
|
|
16
|
+
# Used by dotenv library to load environment variables.
|
|
17
|
+
# .env
|
|
18
|
+
|
|
19
|
+
## Specific to RubyMotion:
|
|
20
|
+
.dat*
|
|
21
|
+
.repl_history
|
|
22
|
+
build/
|
|
23
|
+
*.bridgesupport
|
|
24
|
+
build-iPhoneOS/
|
|
25
|
+
build-iPhoneSimulator/
|
|
26
|
+
|
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
|
28
|
+
#
|
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
32
|
+
#
|
|
33
|
+
# vendor/Pods/
|
|
34
|
+
|
|
35
|
+
## Documentation cache and generated files:
|
|
36
|
+
/.yardoc/
|
|
37
|
+
/_yardoc/
|
|
38
|
+
/doc/
|
|
39
|
+
/rdoc/
|
|
40
|
+
|
|
41
|
+
## Environment normalization:
|
|
42
|
+
/.bundle/
|
|
43
|
+
/vendor/bundle
|
|
44
|
+
/lib/bundler/man/
|
|
45
|
+
|
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
48
|
+
Gemfile.lock
|
|
49
|
+
.ruby-version
|
|
50
|
+
.ruby-gemset
|
|
51
|
+
|
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
53
|
+
.rvmrc
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.3
|
|
3
|
+
|
|
4
|
+
Style/EmptyLinesAroundClassBody:
|
|
5
|
+
Enabled: true
|
|
6
|
+
EnforcedStyle: empty_lines
|
|
7
|
+
|
|
8
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
|
9
|
+
Enabled: true
|
|
10
|
+
|
|
11
|
+
Style/SymbolLiteral:
|
|
12
|
+
Enabled: true
|
|
13
|
+
|
|
14
|
+
Style/SpaceAroundOperators:
|
|
15
|
+
Enabled: true
|
|
16
|
+
|
|
17
|
+
Style/ParallelAssignment:
|
|
18
|
+
Enabled: true
|
|
19
|
+
|
|
20
|
+
Style/NumericLiterals:
|
|
21
|
+
MinDigits: 14
|
|
22
|
+
|
|
23
|
+
Style/Not:
|
|
24
|
+
Enabled: true
|
|
25
|
+
|
|
26
|
+
Style/ClosingParenthesisIndentation:
|
|
27
|
+
Enabled: false
|
|
28
|
+
|
|
29
|
+
Style/SpaceAfterComma:
|
|
30
|
+
Enabled: true
|
|
31
|
+
|
|
32
|
+
Style/SpaceInsideBrackets:
|
|
33
|
+
Enabled: false
|
|
34
|
+
|
|
35
|
+
Style/SpaceInsideParens:
|
|
36
|
+
Enabled: true
|
|
37
|
+
|
|
38
|
+
Style/SpaceBeforeFirstArg:
|
|
39
|
+
Enabled: true
|
|
40
|
+
|
|
41
|
+
Style/MultilineOperationIndentation:
|
|
42
|
+
Enabled: false
|
|
43
|
+
|
|
44
|
+
Style/MethodDefParentheses:
|
|
45
|
+
Enabled: true
|
|
46
|
+
|
|
47
|
+
Style/MethodCallParentheses:
|
|
48
|
+
Enabled: true
|
|
49
|
+
|
|
50
|
+
Style/LineEndConcatenation:
|
|
51
|
+
Enabled: true
|
|
52
|
+
|
|
53
|
+
Style/LeadingCommentSpace:
|
|
54
|
+
Enabled: true
|
|
55
|
+
|
|
56
|
+
Style/AlignArray:
|
|
57
|
+
Enabled: false
|
|
58
|
+
|
|
59
|
+
Style/AlignHash:
|
|
60
|
+
Enabled: false
|
|
61
|
+
|
|
62
|
+
Style/CaseIndentation:
|
|
63
|
+
Enabled: true
|
|
64
|
+
|
|
65
|
+
Style/GuardClause:
|
|
66
|
+
Enabled: false
|
|
67
|
+
|
|
68
|
+
Style/HashSyntax:
|
|
69
|
+
EnforcedStyle: ruby19
|
|
70
|
+
|
|
71
|
+
Style/RedundantSelf:
|
|
72
|
+
Enabled: true
|
|
73
|
+
|
|
74
|
+
Lint/DeprecatedClassMethods:
|
|
75
|
+
Enabled: true
|
|
76
|
+
|
|
77
|
+
Style/NilComparison:
|
|
78
|
+
Enabled: true
|
|
79
|
+
|
|
80
|
+
Style/EmptyLineBetweenDefs:
|
|
81
|
+
Enabled: true
|
|
82
|
+
|
|
83
|
+
Style/EmptyLines:
|
|
84
|
+
Enabled: true
|
|
85
|
+
|
|
86
|
+
Style/EmptyLinesAroundAccessModifier:
|
|
87
|
+
Enabled: true
|
|
88
|
+
|
|
89
|
+
Style/EmptyLiteral:
|
|
90
|
+
Enabled: true
|
|
91
|
+
|
|
92
|
+
Style/For:
|
|
93
|
+
Enabled: true
|
|
94
|
+
|
|
95
|
+
Lint/AssignmentInCondition:
|
|
96
|
+
Enabled: true
|
|
97
|
+
|
|
98
|
+
Lint/BlockAlignment:
|
|
99
|
+
Enabled: true
|
|
100
|
+
|
|
101
|
+
Lint/LiteralInCondition:
|
|
102
|
+
Enabled: true
|
|
103
|
+
|
|
104
|
+
Lint/Loop:
|
|
105
|
+
Enabled: true
|
|
106
|
+
|
|
107
|
+
Lint/ParenthesesAsGroupedExpression:
|
|
108
|
+
Enabled: true
|
|
109
|
+
|
|
110
|
+
Lint/RescueException:
|
|
111
|
+
Enabled: true
|
|
112
|
+
|
|
113
|
+
Lint/ShadowingOuterLocalVariable:
|
|
114
|
+
Enabled: false
|
|
115
|
+
|
|
116
|
+
Lint/UnusedBlockArgument:
|
|
117
|
+
Enabled: true
|
|
118
|
+
|
|
119
|
+
Lint/UnusedMethodArgument:
|
|
120
|
+
Enabled: true
|
|
121
|
+
|
|
122
|
+
Lint/UselessAssignment:
|
|
123
|
+
Enabled: true
|
|
124
|
+
|
|
125
|
+
Lint/Void:
|
|
126
|
+
Enabled: true
|
|
127
|
+
|
|
128
|
+
Style/StringLiterals:
|
|
129
|
+
Enabled: true
|
|
130
|
+
|
|
131
|
+
Lint/AmbiguousRegexpLiteral:
|
|
132
|
+
Enabled: true
|
|
133
|
+
|
|
134
|
+
Lint/Debugger:
|
|
135
|
+
Enabled: true
|
|
136
|
+
|
|
137
|
+
Lint/EndAlignment:
|
|
138
|
+
Enabled: true
|
|
139
|
+
|
|
140
|
+
Lint/HandleExceptions:
|
|
141
|
+
Enabled: true
|
|
142
|
+
|
|
143
|
+
Lint/StringConversionInInterpolation:
|
|
144
|
+
Enabled: true
|
|
145
|
+
|
|
146
|
+
Style/SpaceInsideHashLiteralBraces:
|
|
147
|
+
Enabled: true
|
|
148
|
+
|
|
149
|
+
Style/SpaceInsideBlockBraces:
|
|
150
|
+
Enabled: true
|
|
151
|
+
SpaceBeforeBlockParameters: false
|
|
152
|
+
|
|
153
|
+
Style/SpaceBeforeBlockBraces:
|
|
154
|
+
Enabled: true
|
|
155
|
+
|
|
156
|
+
Style/BracesAroundHashParameters:
|
|
157
|
+
Enabled: false
|
|
158
|
+
|
|
159
|
+
Style/TrailingBlankLines:
|
|
160
|
+
Enabled: true
|
|
161
|
+
|
|
162
|
+
Style/TrailingWhitespace:
|
|
163
|
+
Enabled: true
|
|
164
|
+
|
|
165
|
+
Lint/UnderscorePrefixedVariableName:
|
|
166
|
+
Enabled: true
|
|
167
|
+
|
|
168
|
+
Lint/UselessAccessModifier:
|
|
169
|
+
Enabled: true
|
|
170
|
+
|
|
171
|
+
Metrics/BlockNesting:
|
|
172
|
+
Max: 3
|
|
173
|
+
|
|
174
|
+
Metrics/ClassLength:
|
|
175
|
+
Max: 160
|
|
176
|
+
|
|
177
|
+
Metrics/CyclomaticComplexity:
|
|
178
|
+
Max: 10
|
|
179
|
+
|
|
180
|
+
Style/CommentAnnotation:
|
|
181
|
+
Enabled: true
|
|
182
|
+
|
|
183
|
+
Style/CommentIndentation:
|
|
184
|
+
Enabled: true
|
|
185
|
+
|
|
186
|
+
Style/DeprecatedHashMethods:
|
|
187
|
+
Enabled: true
|
|
188
|
+
|
|
189
|
+
Style/Documentation:
|
|
190
|
+
Enabled: false
|
|
191
|
+
|
|
192
|
+
Style/DotPosition:
|
|
193
|
+
Enabled: true
|
|
194
|
+
|
|
195
|
+
Lint/AmbiguousOperator:
|
|
196
|
+
Enabled: true
|
|
197
|
+
|
|
198
|
+
Metrics/AbcSize:
|
|
199
|
+
Max: 80
|
|
200
|
+
|
|
201
|
+
Metrics/LineLength:
|
|
202
|
+
Max: 160
|
|
203
|
+
|
|
204
|
+
Metrics/MethodLength:
|
|
205
|
+
Max: 50
|
|
206
|
+
|
|
207
|
+
Metrics/ParameterLists:
|
|
208
|
+
Enabled: true
|
|
209
|
+
CountKeywordArgs: false
|
|
210
|
+
|
|
211
|
+
Metrics/PerceivedComplexity:
|
|
212
|
+
Max: 12
|
|
213
|
+
|
|
214
|
+
Metrics/ModuleLength:
|
|
215
|
+
Max: 150
|
|
216
|
+
|
|
217
|
+
Style/Alias:
|
|
218
|
+
Enabled: true
|
|
219
|
+
|
|
220
|
+
Style/AlignParameters:
|
|
221
|
+
Enabled: false
|
|
222
|
+
|
|
223
|
+
Style/AndOr:
|
|
224
|
+
Enabled: false
|
|
225
|
+
|
|
226
|
+
Style/AsciiComments:
|
|
227
|
+
Enabled: true
|
|
228
|
+
|
|
229
|
+
Style/ClassAndModuleChildren:
|
|
230
|
+
Enabled: false
|
|
231
|
+
|
|
232
|
+
Style/DoubleNegation:
|
|
233
|
+
Enabled: false
|
|
234
|
+
|
|
235
|
+
Style/EmptyLinesAroundMethodBody:
|
|
236
|
+
Enabled: false
|
|
237
|
+
|
|
238
|
+
Style/EmptyLinesAroundModuleBody:
|
|
239
|
+
Enabled: false
|
|
240
|
+
|
|
241
|
+
Style/IfUnlessModifier:
|
|
242
|
+
Enabled: true
|
|
243
|
+
|
|
244
|
+
Style/FormatString:
|
|
245
|
+
Enabled: false
|
|
246
|
+
|
|
247
|
+
Style/IndentArray:
|
|
248
|
+
Enabled: true
|
|
249
|
+
|
|
250
|
+
Style/IndentHash:
|
|
251
|
+
Enabled: false
|
|
252
|
+
|
|
253
|
+
Style/IndentationConsistency:
|
|
254
|
+
Enabled: true
|
|
255
|
+
|
|
256
|
+
Style/IndentationWidth:
|
|
257
|
+
Enabled: true
|
|
258
|
+
|
|
259
|
+
Style/Lambda:
|
|
260
|
+
Enabled: false
|
|
261
|
+
|
|
262
|
+
Style/PercentLiteralDelimiters:
|
|
263
|
+
Enabled: true
|
|
264
|
+
|
|
265
|
+
Style/PredicateName:
|
|
266
|
+
Enabled: false
|
|
267
|
+
|
|
268
|
+
Style/RaiseArgs:
|
|
269
|
+
Enabled: false
|
|
270
|
+
|
|
271
|
+
Style/RedundantReturn:
|
|
272
|
+
Enabled: true
|
|
273
|
+
|
|
274
|
+
Style/RegexpLiteral:
|
|
275
|
+
Enabled: true
|
|
276
|
+
|
|
277
|
+
Style/RescueModifier:
|
|
278
|
+
Enabled: false
|
|
279
|
+
|
|
280
|
+
Style/Semicolon:
|
|
281
|
+
Enabled: true
|
|
282
|
+
|
|
283
|
+
Style/SpaceAfterMethodName:
|
|
284
|
+
Enabled: true
|
|
285
|
+
|
|
286
|
+
Style/SymbolProc:
|
|
287
|
+
Enabled: true
|
|
288
|
+
|
|
289
|
+
Style/TrailingCommaInLiteral:
|
|
290
|
+
Enabled: true
|
|
291
|
+
|
|
292
|
+
Style/TrailingCommaInArguments:
|
|
293
|
+
Enabled: true
|
|
294
|
+
|
|
295
|
+
Style/TrivialAccessors:
|
|
296
|
+
Enabled: true
|
|
297
|
+
|
|
298
|
+
Style/StructInheritance:
|
|
299
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Dockerfile
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
source 'http://rubygems.org'
|
|
3
|
+
|
|
4
|
+
gemspec
|
|
5
|
+
|
|
6
|
+
group :development, :test do
|
|
7
|
+
gem 'combustion', '~> 0.3.1'
|
|
8
|
+
gem 'capybara'
|
|
9
|
+
gem 'rspec-rails'
|
|
10
|
+
gem 'rubocop'
|
|
11
|
+
gem 'rake'
|
|
12
|
+
gem 'pry'
|
|
13
|
+
gem 'codecov', require: false
|
|
14
|
+
gem 'mutant-rspec'
|
|
15
|
+
end
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2012 Round Lake, inc.,
|
|
4
|
+
Peter Zotov <whitequark@whitequark.org>.
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Styxie
|
|
2
|
+
|
|
3
|
+
Bridge between Server side and Client (JS) side which is divided into several modules:
|
|
4
|
+
|
|
5
|
+
* **Helpers**: set of helpers to support all other modules.
|
|
6
|
+
* **Initializer**: organizes JS into bootstrap classes and allows you to pass data from controller/view.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
In your Gemfile, add this line:
|
|
11
|
+
|
|
12
|
+
gem 'styxie'
|
|
13
|
+
|
|
14
|
+
In your assets application.js include appropriate libs:
|
|
15
|
+
|
|
16
|
+
//= require styx <- Helpers and Initializers
|
|
17
|
+
|
|
18
|
+
## Basic Usage
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
# app/controllers/foos_controller.rb
|
|
22
|
+
class FoosController < ApplicationController
|
|
23
|
+
include Styxie::Initializer
|
|
24
|
+
end
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Include modules to ApplicationController if you want to use it everywhere.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Initializer
|
|
31
|
+
|
|
32
|
+
In common each controller in Rails comes with *app/assets/javascripts/controller_name.js.coffee*.
|
|
33
|
+
**Styxie.Initializer** allows you to define bootstrap logic for each Rails action separately and
|
|
34
|
+
pass some data from server right into it.
|
|
35
|
+
|
|
36
|
+
To enable initializers bootstrap, add *styx_initialize* call into your layout:
|
|
37
|
+
|
|
38
|
+
```erb
|
|
39
|
+
<head>
|
|
40
|
+
<title>Rails Application</title>
|
|
41
|
+
<%= stylesheet_link_tag "application" %>
|
|
42
|
+
<%= javascript_include_tag "application" %>
|
|
43
|
+
<%= styx_initialize %>
|
|
44
|
+
<%= csrf_meta_tags %>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Imagine you have controller *Foos* and therefore *app/assets/javascripts/foos.js.coffee* file.
|
|
48
|
+
|
|
49
|
+
```coffee-script
|
|
50
|
+
@Styxie.Initializers.Foos =
|
|
51
|
+
initialize: ->
|
|
52
|
+
console.log 'This will be called in foos#ANY action after <head> was parsed'
|
|
53
|
+
|
|
54
|
+
index: (data) ->
|
|
55
|
+
console.log 'This will be called in foos#index action after <head> was parsed'
|
|
56
|
+
|
|
57
|
+
show: (data) ->
|
|
58
|
+
$ ->
|
|
59
|
+
console.log 'This will be called in foos#show action after the page was loaded'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Note that any method besides common *initialize* has the *data* parameter. To pass some data to your
|
|
63
|
+
initializers you can use *styxie_initialize_with* helper in your controller or views. Like that:
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
# app/controllers/foos_controller.rb
|
|
67
|
+
class FoosController < ApplicationController
|
|
68
|
+
def index
|
|
69
|
+
styx_initialize_with some: 'data', and: { even: 'more data' }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# app/views/foos/index.html.erb
|
|
74
|
+
<%- styx_initialize_with enabled: true %>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
As the result *Styxie.Initializers.Foos->index* will be called with data equal to
|
|
78
|
+
|
|
79
|
+
{some: data, and: {even: 'mode data'}, enabled: true}
|
data/Rakefile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
@Styxie = {
|
|
2
|
+
Initializers: {}
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
@Styxie.URL =
|
|
6
|
+
go: (url, force=false) ->
|
|
7
|
+
# 'Force' required if you want to reload same page with another anchor
|
|
8
|
+
url = this.build(url, "reloadthispagepls=#{Math.random()}") if force
|
|
9
|
+
window.location.href = url
|
|
10
|
+
|
|
11
|
+
build: (url, params) ->
|
|
12
|
+
hash = url.match(/\#.*$/)
|
|
13
|
+
hash = if hash then hash[0] else false
|
|
14
|
+
|
|
15
|
+
url = url.replace(hash, '') if hash
|
|
16
|
+
url = url + "?" if url.indexOf("?") == -1
|
|
17
|
+
|
|
18
|
+
url = "#{url}&#{params}"
|
|
19
|
+
|
|
20
|
+
url = url + hash if hash
|
|
21
|
+
|
|
22
|
+
return url
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
//<![CDATA[
|
|
3
|
+
if (Styxie.Initializers.<%=klass%> && Styxie.Initializers.<%=klass%>.initialize)
|
|
4
|
+
{
|
|
5
|
+
Styxie.Initializers.<%=klass%>.initialize(<%=data.to_json.html_safe%>);
|
|
6
|
+
}
|
|
7
|
+
if (Styxie.Initializers.<%=klass%> && Styxie.Initializers.<%=klass%>['<%=method%>'])
|
|
8
|
+
{
|
|
9
|
+
Styxie.Initializers.<%=klass%>['<%=method%>'](<%=data.to_json.html_safe%>);
|
|
10
|
+
}
|
|
11
|
+
//]]>
|
|
12
|
+
</script>
|
data/docker-compose.yml
ADDED
data/init.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Styxie
|
|
3
|
+
module Helpers
|
|
4
|
+
def this_page?(mask)
|
|
5
|
+
Array(mask).any? do |m|
|
|
6
|
+
c, a = m.to_s.split('#')
|
|
7
|
+
!(c.present? && c != controller_name || a.present? && a != action_name)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def this_namespace?(namespace)
|
|
12
|
+
# TODO: support nested namespaces?
|
|
13
|
+
namespace == controller_path.split('/').first
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module Styxie
|
|
3
|
+
module Initializer
|
|
4
|
+
def styxie_initialize_with(data)
|
|
5
|
+
styxie_configuration.merge! data
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def styxie_initialize(klass: styxie_class, method: action_name, data: styxie_configuration)
|
|
9
|
+
result = render_to_string partial: 'styxie/initializer', locals: {
|
|
10
|
+
klass: klass,
|
|
11
|
+
method: method,
|
|
12
|
+
data: data
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
result.html_safe
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def styxie_configuration
|
|
19
|
+
@styxie_initialize_with ||= {}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def styxie_class
|
|
23
|
+
controller_path.tr('/', '_').camelize
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/styxie.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe TestsController, type: :controller do
|
|
5
|
+
render_views
|
|
6
|
+
|
|
7
|
+
it 'index' do
|
|
8
|
+
get :index
|
|
9
|
+
response.body.should have_content('Styxie.Initializers.Tests.initialize({"data":"test"})')
|
|
10
|
+
response.body.should have_content('Styxie.Initializers.Tests[\'index\']({"data":"test"})')
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'styxie'
|
|
3
|
+
|
|
4
|
+
class TestsController < ActionController::Base
|
|
5
|
+
|
|
6
|
+
append_view_path Styxie::Engine.paths['app/views']
|
|
7
|
+
|
|
8
|
+
include Styxie::Initializer
|
|
9
|
+
helper_method :styxie_initialize
|
|
10
|
+
|
|
11
|
+
def index
|
|
12
|
+
styxie_initialize_with data: 'test'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= styxie_initialize %>
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.log
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe Styxie::Helpers do
|
|
5
|
+
let :controller do
|
|
6
|
+
controller = double('controller')
|
|
7
|
+
controller.class_eval do
|
|
8
|
+
include Styxie::Helpers
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
controller
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it '#this_page?' do
|
|
15
|
+
controller.stub(controller_name: 'tests')
|
|
16
|
+
controller.stub(action_name: 'index')
|
|
17
|
+
|
|
18
|
+
cases = [
|
|
19
|
+
[
|
|
20
|
+
be_truthy, [
|
|
21
|
+
'tests#index',
|
|
22
|
+
'#index'
|
|
23
|
+
]
|
|
24
|
+
], [
|
|
25
|
+
be_falsy, [
|
|
26
|
+
'fails#index',
|
|
27
|
+
'tests#show',
|
|
28
|
+
'#show'
|
|
29
|
+
]
|
|
30
|
+
]
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
cases.each do |group|
|
|
34
|
+
be_ok, examples = group
|
|
35
|
+
examples.each do |example|
|
|
36
|
+
expect(controller.this_page?(example)).to be_ok
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it '#this_namespace?' do
|
|
42
|
+
controller.stub(controller_path: 'module/tests')
|
|
43
|
+
|
|
44
|
+
cases = [
|
|
45
|
+
[
|
|
46
|
+
be_truthy, [
|
|
47
|
+
'module'
|
|
48
|
+
]
|
|
49
|
+
], [
|
|
50
|
+
be_falsy, [
|
|
51
|
+
'whatever'
|
|
52
|
+
]
|
|
53
|
+
]
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
cases.each do |group|
|
|
57
|
+
be_ok, examples = group
|
|
58
|
+
examples.each do |example|
|
|
59
|
+
expect(controller.this_namespace?(example)).to be_ok
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe Styxie::Initializer do
|
|
5
|
+
let :controller do
|
|
6
|
+
controller = double('controller')
|
|
7
|
+
controller.class_eval do
|
|
8
|
+
include Styxie::Initializer
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
controller
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it '#styxie_initialize_with' do
|
|
15
|
+
expect(controller.styxie_configuration).to eq({})
|
|
16
|
+
controller.styxie_initialize_with(test: 'data')
|
|
17
|
+
expect(controller.styxie_configuration).to eq({ test: 'data' })
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it '#styxie_initialize' do
|
|
21
|
+
controller.stub(controller_path: 'module/tests')
|
|
22
|
+
controller.stub(action_name: 'index')
|
|
23
|
+
controller.should_receive(:render_to_string).and_return('rendered template')
|
|
24
|
+
result = controller.styxie_initialize
|
|
25
|
+
expect(result).to eq 'rendered template'
|
|
26
|
+
expect(result.html_safe?).to be_truthy
|
|
27
|
+
end
|
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'bundler'
|
|
4
|
+
Bundler.require :development
|
|
5
|
+
require 'capybara/rspec'
|
|
6
|
+
Combustion.initialize! :action_controller, :action_view, :sprockets
|
|
7
|
+
Bundler.require :default
|
|
8
|
+
require 'rspec/rails'
|
|
9
|
+
require 'capybara/rails'
|
|
10
|
+
|
|
11
|
+
RSpec.configure do |config|
|
|
12
|
+
config.mock_with :rspec
|
|
13
|
+
end
|
data/styxie.gemspec
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
Gem::Specification.new do |s|
|
|
3
|
+
s.name = 'styxie'
|
|
4
|
+
s.version = '0.0.1'
|
|
5
|
+
s.platform = Gem::Platform::RUBY
|
|
6
|
+
s.summary = 'Set of helpers to maintain bridge between Server side and Client (JS) side'
|
|
7
|
+
s.email = 'dev@httplab.ru'
|
|
8
|
+
s.homepage = 'http://github.com/httplab/styxie'
|
|
9
|
+
s.description = s.summary
|
|
10
|
+
s.authors = ['Yury Kotov', 'Httplab']
|
|
11
|
+
|
|
12
|
+
s.has_rdoc = false # disable rdoc generation until we've got more
|
|
13
|
+
s.files = `git ls-files`.split("\n")
|
|
14
|
+
s.require_paths = ['lib']
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: styxie
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yury Kotov
|
|
8
|
+
- Httplab
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2016-09-03 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: Set of helpers to maintain bridge between Server side and Client (JS)
|
|
15
|
+
side
|
|
16
|
+
email: dev@httplab.ru
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- ".gitignore"
|
|
22
|
+
- ".rubocop.yml"
|
|
23
|
+
- ".travis.yml"
|
|
24
|
+
- Dockerfile
|
|
25
|
+
- Gemfile
|
|
26
|
+
- LICENSE
|
|
27
|
+
- README.md
|
|
28
|
+
- Rakefile
|
|
29
|
+
- app/assets/javascripts/styxie.js.coffee
|
|
30
|
+
- app/views/styxie/_initializer.html.erb
|
|
31
|
+
- docker-compose.yml
|
|
32
|
+
- init.rb
|
|
33
|
+
- lib/styxie.rb
|
|
34
|
+
- lib/styxie/engine.rb
|
|
35
|
+
- lib/styxie/helpers.rb
|
|
36
|
+
- lib/styxie/initializer.rb
|
|
37
|
+
- spec/controllers/tests_controller_spec.rb
|
|
38
|
+
- spec/internal/app/controllers/tests_controller.rb
|
|
39
|
+
- spec/internal/app/views/tests/index.html.erb
|
|
40
|
+
- spec/internal/config/routes.rb
|
|
41
|
+
- spec/internal/db/schema.rb
|
|
42
|
+
- spec/internal/log/.gitignore
|
|
43
|
+
- spec/lib/styxie_helpers_spec.rb
|
|
44
|
+
- spec/lib/styxie_initializer_spec.rb
|
|
45
|
+
- spec/spec_helper.rb
|
|
46
|
+
- styxie.gemspec
|
|
47
|
+
homepage: http://github.com/httplab/styxie
|
|
48
|
+
licenses: []
|
|
49
|
+
metadata: {}
|
|
50
|
+
post_install_message:
|
|
51
|
+
rdoc_options: []
|
|
52
|
+
require_paths:
|
|
53
|
+
- lib
|
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: '0'
|
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
requirements: []
|
|
65
|
+
rubyforge_project:
|
|
66
|
+
rubygems_version: 2.5.1
|
|
67
|
+
signing_key:
|
|
68
|
+
specification_version: 4
|
|
69
|
+
summary: Set of helpers to maintain bridge between Server side and Client (JS) side
|
|
70
|
+
test_files: []
|