jsimple 0.4.0 → 0.5.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 +4 -4
- data/README.md +62 -7
- data/lib/jsimple.rb +22 -0
- data/lib/jsimple/builder.rb +9 -2
- data/lib/jsimple/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9db9fc244323efa03873ab9863a0cb57d1a70294
|
4
|
+
data.tar.gz: a32b112f272b8cf74500860dfd0b9c00a4f0a7af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1de33604c8219a3f22f9171dc865c38307c4dda41bb8e09f19d887bc58888d21bbb730e5e10b404d954e6a4badddfd21c1beec620f6025cad09d550af0fac3ee
|
7
|
+
data.tar.gz: 2a0488e34f7c3ae0bb2f33bd6ab29dcd6037f0883237c94eb18abb925c1b39a60e75468fe90e28067a03c99c6c8f70a8627cbece9dd69304a7b6198b8d993b28
|
data/README.md
CHANGED
@@ -22,31 +22,86 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
In order to have this make sense with your current setup you probably want to configure some of the defaults.
|
24
24
|
|
25
|
-
|
25
|
+
Below are all of the available configuration values and their defaults.
|
26
|
+
|
27
|
+
__Host__:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Jsimple.host = 'localhost'
|
31
|
+
```
|
26
32
|
Server host for the JS client (usually Node) in development mode. Default is localhost.
|
27
33
|
|
28
|
-
__Port__:
|
34
|
+
__Port__:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Jsimple.port = '3100'
|
38
|
+
```
|
29
39
|
Server port for the JS client (usually Node) in development mode. Default is 3100.
|
30
40
|
|
31
|
-
__Development__:
|
32
|
-
|
41
|
+
__Development__:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Jsimple.development = false
|
45
|
+
```
|
46
|
+
Whether to start Jsimple in development mode. The default is false unless your running Rails then `Rails.env.development?` is the default.
|
33
47
|
|
34
|
-
|
48
|
+
__JS start command__:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
Jsimple.js_start_command = 'start'
|
52
|
+
```
|
35
53
|
JS function name the legacy app will call to initialize the JS app.
|
36
54
|
|
55
|
+
__JS path prefix__:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
Jsimple.js_path_prefix = 'jsimple'
|
59
|
+
```
|
60
|
+
JS path prefix to prepend to the app name in production.
|
61
|
+
|
62
|
+
__JS dev path prefix__:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
Jsimple.js_dev_path_prefix = ''
|
66
|
+
```
|
67
|
+
JS path prefix to prepend to the app name in development.
|
68
|
+
|
69
|
+
|
37
70
|
## Usage
|
38
71
|
|
39
72
|
```ruby
|
40
73
|
data = {name: 'Alice', age: 26}
|
41
74
|
app = Jsimple.app('ContactList', props: data, id: 'contact-list-id')
|
42
75
|
app.path
|
43
|
-
#
|
76
|
+
# In production
|
77
|
+
# => jsimple/test_app.min.js
|
78
|
+
# In development
|
79
|
+
# => http://localhost:3100/test_app.min.js
|
44
80
|
app.init
|
45
81
|
# => <script>
|
46
82
|
# test_app.start(document.getElementById('contact-list-id'), JSON.parse('{"name": "Alice", "age": 26}'));
|
47
83
|
# </script>
|
48
84
|
```
|
49
85
|
|
86
|
+
:warning: _Security note_: XSS is possible if a user is allowed to set arbitrary values to `name` and `id`. `props` is serialized to JSON and should therefore be safe.
|
87
|
+
|
88
|
+
#### Rails integration
|
89
|
+
|
90
|
+
If your using Rails you get a couple of helper methods are included.
|
91
|
+
|
92
|
+
Example
|
93
|
+
```
|
94
|
+
<%= javascript_indlude_tag jsimple_js_path('js_app_name') %>
|
95
|
+
<%= jsimle_js_init('js_app_name') %>
|
96
|
+
```
|
97
|
+
|
98
|
+
You will need to add the production js bundles to your path.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
# config/initializers/assets.rb
|
102
|
+
Rails.application.config.assets.precompile += %w( jsimple/* )
|
103
|
+
```
|
104
|
+
|
50
105
|
## Development
|
51
106
|
|
52
107
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -55,7 +110,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
55
110
|
|
56
111
|
## Contributing
|
57
112
|
|
58
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
113
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/buren/jsimple. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
59
114
|
|
60
115
|
## License
|
61
116
|
|
data/lib/jsimple.rb
CHANGED
@@ -23,10 +23,14 @@ module Jsimple
|
|
23
23
|
DEFAULT_PORT = '3100'
|
24
24
|
DEFAULT_DEVELOPMENT = defined?(Rails) ? Rails.env.development? : false
|
25
25
|
DEFAULT_JS_START_COMMAND = 'start'
|
26
|
+
DEFAULT_JS_PATH_PREFIX = 'jsimple'
|
27
|
+
DEFAULT_JS_DEV_PATH_PREFIX = ''
|
26
28
|
@host = DEFAULT_HOST
|
27
29
|
@port = DEFAULT_PORT
|
28
30
|
@development = DEFAULT_DEVELOPMENT
|
29
31
|
@js_start_command = DEFAULT_JS_START_COMMAND
|
32
|
+
@js_path_prefix = DEFAULT_JS_PATH_PREFIX
|
33
|
+
@js_dev_path_prefix = DEFAULT_JS_DEV_PATH_PREFIX
|
30
34
|
|
31
35
|
def self.host=(host)
|
32
36
|
HotReloadProxy::Config.host = host
|
@@ -46,6 +50,14 @@ module Jsimple
|
|
46
50
|
@js_start_command = js_start_command
|
47
51
|
end
|
48
52
|
|
53
|
+
def self.js_path_prefix=(js_path_prefix)
|
54
|
+
@js_path_prefix = js_path_prefix
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.js_dev_path_prefix=(js_dev_path_prefix)
|
58
|
+
@js_dev_path_prefix = js_dev_path_prefix
|
59
|
+
end
|
60
|
+
|
49
61
|
def self.host
|
50
62
|
@host
|
51
63
|
end
|
@@ -62,10 +74,20 @@ module Jsimple
|
|
62
74
|
@js_start_command
|
63
75
|
end
|
64
76
|
|
77
|
+
def self.js_path_prefix
|
78
|
+
@js_path_prefix
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.js_dev_path_prefix
|
82
|
+
@js_dev_path_prefix
|
83
|
+
end
|
84
|
+
|
65
85
|
def self.reset!
|
66
86
|
@host = DEFAULT_HOST
|
67
87
|
@port = DEFAULT_PORT
|
68
88
|
@development = DEFAULT_DEVELOPMENT
|
69
89
|
@js_start_command = DEFAULT_JS_START_COMMAND
|
90
|
+
@js_path_prefix = DEFAULT_JS_PATH_PREFIX
|
91
|
+
@js_dev_path_prefix = DEFAULT_JS_DEV_PATH_PREFIX
|
70
92
|
end
|
71
93
|
end
|
data/lib/jsimple/builder.rb
CHANGED
@@ -30,12 +30,19 @@ module Jsimple
|
|
30
30
|
|
31
31
|
# Path for JS bundle in production
|
32
32
|
def self.js_production_path(name)
|
33
|
-
"
|
33
|
+
_path_join(Jsimple.js_path_prefix, "#{name}.min.js")
|
34
34
|
end
|
35
35
|
|
36
36
|
# Path for JS in development
|
37
37
|
def self.js_development_path(name, host, port)
|
38
|
-
"
|
38
|
+
path = _path_join(Jsimple.js_dev_path_prefix, "#{name}.js")
|
39
|
+
"http://#{host}:#{port}/#{path}"
|
40
|
+
end
|
41
|
+
|
42
|
+
# private
|
43
|
+
|
44
|
+
def self._path_join(path, file_name)
|
45
|
+
[path, file_name].reject(&:empty?).join('/')
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
data/lib/jsimple/version.rb
CHANGED