josean 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +54 -0
- data/.gitignore +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +39 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bitbucket-pipelines.yml +20 -0
- data/josean.gemspec +32 -0
- data/lib/josean.rb +201 -0
- data/lib/josean/objects.rb +199 -0
- data/lib/josean/version.rb +3 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c857ec0a981c6b993f4b6445a9f31c8c344f5c74
|
4
|
+
data.tar.gz: 70f18636cf4a926bac69791c0f7b581e8bf29876
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75396d0f6392aee9c28d220adb9f72eab9ae4edea9724fbc935124255630430f644825646c7e13847ec011230200645160ac56fd37f9b3b7bf575d3b559f7081
|
7
|
+
data.tar.gz: 6e8462915d4df4b9417b11ec18b90b6267f474c9e5d3cf2806ae23756973733a71775105f45a88de5fb05e91715a960539d6381bfa585592e2268d9c5f725d04
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
version: 2
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
docker:
|
8
|
+
# specify the version you desire here
|
9
|
+
- image: circleci/ruby:2.4.1-node-browsers
|
10
|
+
|
11
|
+
# Specify service dependencies here if necessary
|
12
|
+
# CircleCI maintains a library of pre-built images
|
13
|
+
# documented at https://circleci.com/docs/2.0/circleci-images/
|
14
|
+
# - image: circleci/postgres:9.4
|
15
|
+
|
16
|
+
working_directory: ~/repo
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- checkout
|
20
|
+
|
21
|
+
# Download and cache dependencies
|
22
|
+
- restore_cache:
|
23
|
+
keys:
|
24
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
25
|
+
# fallback to using the latest cache if no exact match is found
|
26
|
+
- v1-dependencies-
|
27
|
+
|
28
|
+
- run:
|
29
|
+
name: install dependencies
|
30
|
+
command: |
|
31
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
32
|
+
|
33
|
+
- save_cache:
|
34
|
+
paths:
|
35
|
+
- ./vendor/bundle
|
36
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
37
|
+
|
38
|
+
# Run the tests
|
39
|
+
- run:
|
40
|
+
name: run tests
|
41
|
+
command: |
|
42
|
+
bundle exec rake test
|
43
|
+
|
44
|
+
# Build the gem
|
45
|
+
- run:
|
46
|
+
name: build the gem
|
47
|
+
command: |
|
48
|
+
gem build josean.gemspec
|
49
|
+
|
50
|
+
# Push the gem to the rubygems repo
|
51
|
+
- run:
|
52
|
+
name: push to rubygems
|
53
|
+
command: |
|
54
|
+
gem push *.gem -k $GEM_HOST_API_KEY
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at nachootal@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
josean (0.1.11)
|
5
|
+
json
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
byebug (11.0.1)
|
11
|
+
concurrent-ruby (1.1.5)
|
12
|
+
docile (1.3.2)
|
13
|
+
faker (1.9.6)
|
14
|
+
i18n (>= 0.7)
|
15
|
+
i18n (1.6.0)
|
16
|
+
concurrent-ruby (~> 1.0)
|
17
|
+
json (2.2.0)
|
18
|
+
minitest (5.11.3)
|
19
|
+
rake (12.3.2)
|
20
|
+
simplecov (0.17.0)
|
21
|
+
docile (~> 1.1)
|
22
|
+
json (>= 1.8, < 3)
|
23
|
+
simplecov-html (~> 0.10.0)
|
24
|
+
simplecov-html (0.10.2)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler
|
31
|
+
byebug
|
32
|
+
faker
|
33
|
+
josean!
|
34
|
+
minitest
|
35
|
+
rake
|
36
|
+
simplecov
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 nacho
|
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,43 @@
|
|
1
|
+
# Josean
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/josean`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'josean'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install josean
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/josean. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Josean project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/josean/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "josean"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This is a sample build configuration for Ruby.
|
2
|
+
# Check our guides at https://confluence.atlassian.com/x/8r-5Mw for more examples.
|
3
|
+
# Only use spaces to indent your .yml configuration.
|
4
|
+
# -----
|
5
|
+
# You can specify a custom docker image from Docker Hub as your build environment.
|
6
|
+
image: ruby:2.4.6
|
7
|
+
|
8
|
+
pipelines:
|
9
|
+
default:
|
10
|
+
- step:
|
11
|
+
caches:
|
12
|
+
- bundler
|
13
|
+
script: # Modify the commands below to build your repository.
|
14
|
+
- bundle install
|
15
|
+
- rake test
|
16
|
+
- gem build josean.gemspec
|
17
|
+
|
18
|
+
definitions:
|
19
|
+
caches:
|
20
|
+
bundler: ./vendor
|
data/josean.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "josean/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "josean"
|
8
|
+
spec.version = Josean::VERSION
|
9
|
+
spec.authors = ["Nacho"]
|
10
|
+
spec.email = ["nachootal@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Implements the JSON layouts for Jasonette https://docs.jasonette.com.}
|
13
|
+
spec.description = %q{Implements the JSON layouts for Jasonette https://docs.jasonette.com.}
|
14
|
+
spec.homepage = "https://bitbucket.org/nachootal/josean"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
|
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 "bundler"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency 'minitest'
|
28
|
+
spec.add_development_dependency 'byebug'
|
29
|
+
spec.add_development_dependency 'faker'
|
30
|
+
spec.add_development_dependency 'simplecov'
|
31
|
+
spec.add_runtime_dependency 'json'
|
32
|
+
end
|
data/lib/josean.rb
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
require "josean/version"
|
2
|
+
require "josean/objects"
|
3
|
+
|
4
|
+
module Josean
|
5
|
+
|
6
|
+
class Application
|
7
|
+
def initialize application_url
|
8
|
+
@application_url = application_url
|
9
|
+
@total_configuration = {}
|
10
|
+
@total_configuration[:head] = {}
|
11
|
+
@total_configuration[:body] = {}
|
12
|
+
@total_configuration[:body][:sections] = []
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Sets the head of the application
|
17
|
+
# title Title of the application
|
18
|
+
# description Description of the application
|
19
|
+
# icon URL to the icon image
|
20
|
+
# style Hash containing the CSS style
|
21
|
+
def head title, description, icon, style
|
22
|
+
@total_configuration[:head] = {title: title,
|
23
|
+
description: description,
|
24
|
+
icon: icon,
|
25
|
+
style: style}
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Sets the body header of the application
|
30
|
+
# image URL to the image
|
31
|
+
# style_image Hash containing the CSS style of the image
|
32
|
+
# style Hash containing the CSS style of the frame
|
33
|
+
def body_header image, style_image, style
|
34
|
+
@total_configuration[:body][:header] = {
|
35
|
+
title: {
|
36
|
+
type: 'image',
|
37
|
+
url: image,
|
38
|
+
style: style_image
|
39
|
+
},
|
40
|
+
style: style
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Add a body style section
|
46
|
+
# style Hash containing the CSS style of the frame
|
47
|
+
def body_style style
|
48
|
+
@total_configuration[:body][:style] = style
|
49
|
+
end
|
50
|
+
|
51
|
+
# Add a body section and return a handler for it
|
52
|
+
def section
|
53
|
+
@total_configuration[:body][:sections] << {items: []}
|
54
|
+
@total_configuration[:body][:sections].last[:items]
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Add a body section that can scroll components and return a handler for it
|
59
|
+
def scrolled_section type, style
|
60
|
+
if valid_type?(type) and style.is_a? Hash
|
61
|
+
@total_configuration[:body][:sections] << {items: []}
|
62
|
+
@total_configuration[:body][:sections].last[:items] << {type: type, style: style, components: []}
|
63
|
+
@total_configuration[:body][:sections].last[:items]
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Add an item to a given section
|
71
|
+
# section handler to which section
|
72
|
+
# item Item to be added. It needs to be a Jasonette object
|
73
|
+
def section_item section, item
|
74
|
+
section << item if section.is_a? Array
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Add a component to a given scrolled section
|
79
|
+
# section handler to which section
|
80
|
+
# component Component to be added. It needs to be a Jasonette object
|
81
|
+
def scrolled_section_component section, component
|
82
|
+
section.last[:components] << component if section.is_a? Array and section.last.keys.include? :components
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Add a get call with a given action name
|
87
|
+
# name_of_resource Name of the resource that this request will be attached to
|
88
|
+
# url URL to which the request will be issued
|
89
|
+
# view View to which the application will be transitioned on success
|
90
|
+
def get_request_action name_of_resource, url, view
|
91
|
+
create_network_request 'get', name_of_resource, url, nil, view
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Add a post call with a given action name
|
96
|
+
# name_of_resource Name of the resource that this request will be attached to
|
97
|
+
# url URL to which the request will be issued
|
98
|
+
# view View to which the application will be transitioned on success
|
99
|
+
def post_request_action name_of_resource, url, data_hash, view
|
100
|
+
create_network_request 'post', name_of_resource, url, data_hash, view
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Add a put call with a given action name
|
105
|
+
# name_of_resource Name of the resource that this request will be attached to
|
106
|
+
# url URL to which the request will be issued
|
107
|
+
# view View to which the application will be transitioned on success
|
108
|
+
def put_request_action name_of_resource, url, data_hash, view
|
109
|
+
create_network_request 'put', name_of_resource, url, data_hash, view
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# Returns the json so that it can be served
|
114
|
+
def to_json
|
115
|
+
if valid?
|
116
|
+
'{"$jason":' + JSON.unparse(@total_configuration) + '}'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
##
|
122
|
+
# Checks whether the configuration is correct
|
123
|
+
def valid?
|
124
|
+
return_value = false
|
125
|
+
unless @total_configuration.keys.length != 2 and @total_configuration[:head].empty? or @total_configuration[:body].empty?
|
126
|
+
return_value = valid_header? and valid_body?
|
127
|
+
end
|
128
|
+
return_value
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# Checks wether the header is valid
|
133
|
+
def valid_header?
|
134
|
+
check_content [[:title, String], [:description, String], [:icon, String], [:offline, String], [:styles, Hash], [:actions, Hash], [:templates, Hash], [:data, Hash], [:agents, Hash]], :head
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# Checks wether the body is valid
|
139
|
+
def valid_body?
|
140
|
+
check_content [[:header, Hash], [:sections, Array], [:layers, Array], [:footer, Hash]], :body
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Checks wether the type of a section is valid
|
145
|
+
def valid_type? type
|
146
|
+
['vertical', 'horizontal'].include? type
|
147
|
+
end
|
148
|
+
|
149
|
+
##
|
150
|
+
# Checks that the array of tags and content is correct
|
151
|
+
def check_content list, region_of_configuration
|
152
|
+
list.map do |k|
|
153
|
+
@total_configuration[region_of_configuration].keys.include?(k.first) ? (@total_configuration[region_of_configuration][k.first].is_a?(k.last)) : true
|
154
|
+
end.include?(false) ? false : true
|
155
|
+
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# Checks whether the actions hash is created on the current jason and creates it in case not
|
159
|
+
def check_if_actions_is_created
|
160
|
+
unless @total_configuration[:head][:actions].is_a? Hash
|
161
|
+
@total_configuration[:head][:actions] = {}
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Creates a network request as an action and returns the hash
|
167
|
+
# verb : HTTP verb (supported: get, put, post, patch
|
168
|
+
# name_of_resource: Action name
|
169
|
+
# url: URL to which it will be requested
|
170
|
+
# data_hash: data sent to server
|
171
|
+
# view: view to which it'll transition
|
172
|
+
def create_network_request verb, name_of_resource, url, data_hash, view
|
173
|
+
check_if_actions_is_created
|
174
|
+
@total_configuration[:head][:actions]["#{name_of_resource}"] = if ['get', 'put', 'post', 'patch'].include? verb.downcase
|
175
|
+
{
|
176
|
+
type: "$network.request",
|
177
|
+
options: {
|
178
|
+
url: url,
|
179
|
+
method: verb.downcase,
|
180
|
+
data: data_hash
|
181
|
+
},
|
182
|
+
success: {
|
183
|
+
type: "href",
|
184
|
+
options: {
|
185
|
+
url: @application_url + '/' + view,
|
186
|
+
transtion: 'replace'
|
187
|
+
}
|
188
|
+
},
|
189
|
+
error: {
|
190
|
+
type: "$util.toast",
|
191
|
+
options: {
|
192
|
+
text: "Something went wrong when #{verb.upcase} on #{url}.",
|
193
|
+
type: "Error"
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
module Josean::Objects
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
## Creates a switch
|
5
|
+
def self.switch name, value, action, style
|
6
|
+
if valid_name(name) and valid_value_switch(value) and valid_action(action) and valid_style(style)
|
7
|
+
{
|
8
|
+
type: 'switch',
|
9
|
+
name: name,
|
10
|
+
value: value,
|
11
|
+
action: {
|
12
|
+
trigger: action,
|
13
|
+
options: {
|
14
|
+
item: "Name of the switch #{name}"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
else
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
## Creates a label item for the section[:items]
|
23
|
+
# name Name of the label
|
24
|
+
# style Hash containing the style
|
25
|
+
def self.label name, style
|
26
|
+
if valid_name(name) and valid_style(style)
|
27
|
+
{
|
28
|
+
type: 'label',
|
29
|
+
text: name,
|
30
|
+
style: style,
|
31
|
+
}
|
32
|
+
else
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
## Creates a textfield item for the section[:items]
|
38
|
+
# name Name of the label
|
39
|
+
# style Hash containing the style
|
40
|
+
def self.textfield name, style
|
41
|
+
if valid_name(name) and valid_style(style)
|
42
|
+
{
|
43
|
+
type: 'textfield',
|
44
|
+
name: name,
|
45
|
+
keyboard: 'email',
|
46
|
+
placeholder: "Enter #{name.downcase}",
|
47
|
+
style: style
|
48
|
+
}
|
49
|
+
else
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
## Creates a button item for the section[:items]
|
55
|
+
# name Name of the label
|
56
|
+
# action action name that will be triggered
|
57
|
+
# style Hash containing the style
|
58
|
+
def self.button name, url, style
|
59
|
+
if valid_name(name) and valid_url(url) and valid_style(style)
|
60
|
+
{
|
61
|
+
type: 'label',
|
62
|
+
text: name,
|
63
|
+
style: style,
|
64
|
+
href: {
|
65
|
+
url: url
|
66
|
+
}
|
67
|
+
}
|
68
|
+
else
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
## Creates an image item for the section[:items]
|
74
|
+
# url Url to which it points
|
75
|
+
# style Hash containing the style
|
76
|
+
def self.image url, style
|
77
|
+
if valid_url(url) and valid_style(style)
|
78
|
+
{
|
79
|
+
type: "image",
|
80
|
+
url: url,
|
81
|
+
style: style
|
82
|
+
}
|
83
|
+
else
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
## Creates an image item for the section[:items]
|
89
|
+
# url Url to which it points
|
90
|
+
# style Hash containing the style
|
91
|
+
def self.slider name, value, action, style
|
92
|
+
if valid_name(name) and valid_value_slider(value) and valid_action(action) and valid_style(style)
|
93
|
+
{
|
94
|
+
type: "slider",
|
95
|
+
name: name,
|
96
|
+
value: value.to_s,
|
97
|
+
action: {
|
98
|
+
"trigger": action
|
99
|
+
}
|
100
|
+
}
|
101
|
+
else
|
102
|
+
nil
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
## Creates a space item for the section[:items]
|
107
|
+
# style Hash containing the style
|
108
|
+
def self.space style
|
109
|
+
if valid_style(style)
|
110
|
+
{
|
111
|
+
type: "space",
|
112
|
+
style: style
|
113
|
+
}
|
114
|
+
else
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
## Creates a map item for the section[:items]
|
120
|
+
# style Hash containing the style
|
121
|
+
def self.map coordinates, width, height, pins, style
|
122
|
+
if valid_coordinates(coordinates) and valid_radio(width) and valid_radio(height) and valid_pins(pins) and valid_style(style)
|
123
|
+
|
124
|
+
output = {
|
125
|
+
type: "map",
|
126
|
+
region: {
|
127
|
+
coord: coordinates.join(','),
|
128
|
+
width: width.to_s,
|
129
|
+
height: height.to_s
|
130
|
+
},
|
131
|
+
style: style
|
132
|
+
}
|
133
|
+
if pins.any?
|
134
|
+
output[:pins] = pins.map do |p|
|
135
|
+
pin p[:title], p[:description], p[:coord], p[:style]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
output
|
139
|
+
else
|
140
|
+
nil
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
## Creates a pin item for a map for the section[:items]
|
145
|
+
# style Hash containing the style
|
146
|
+
def self.pin name, description, coordinates, style
|
147
|
+
if valid_name(name) and valid_name(description) and valid_coordinates(coordinates) and valid_style(style)
|
148
|
+
{
|
149
|
+
title: name,
|
150
|
+
description: description,
|
151
|
+
coord: coordinates.join(','),
|
152
|
+
style: style
|
153
|
+
}
|
154
|
+
else
|
155
|
+
nil
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
def self.valid_name name
|
161
|
+
name.is_a? String
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.valid_style style
|
165
|
+
style.is_a? Hash
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.valid_action action
|
169
|
+
action.is_a? Hash
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.valid_url url
|
173
|
+
url =~ URI::Parser.new.make_regexp
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.valid_value_switch value
|
177
|
+
value.is_a? TrueClass
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.valid_value_slider value
|
181
|
+
(value.is_a? Float or value.is_a? Integer) and (value >= 0) and (value <= 1)
|
182
|
+
end
|
183
|
+
|
184
|
+
def self.valid_coordinates coordinates
|
185
|
+
coordinates.is_a? Array and coordinates.length == 2 and (coordinates.first.is_a? Float or coordinates.first.is_a? Integer) and (coordinates.last.is_a? Float or coordinates.last_is_a? Integer)
|
186
|
+
end
|
187
|
+
|
188
|
+
def self.valid_radio radio
|
189
|
+
(radio.is_a? Integer or radio.is_a? Float) and radio >= 0 and radio <= 100000
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.valid_pins pins
|
193
|
+
pins.is_a? Array and (not pins.map{ |p| valid_pin(p)}.include?(false))
|
194
|
+
end
|
195
|
+
|
196
|
+
def self.valid_pin pin
|
197
|
+
pin.is_a? Hash and pin.keys.sort == [:coord, :title, :description, :style].sort
|
198
|
+
end
|
199
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: josean
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.11
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nacho
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
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: faker
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: json
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Implements the JSON layouts for Jasonette https://docs.jasonette.com.
|
112
|
+
email:
|
113
|
+
- nachootal@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".circleci/config.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- CODE_OF_CONDUCT.md
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/console
|
127
|
+
- bin/setup
|
128
|
+
- bitbucket-pipelines.yml
|
129
|
+
- josean.gemspec
|
130
|
+
- lib/josean.rb
|
131
|
+
- lib/josean/objects.rb
|
132
|
+
- lib/josean/version.rb
|
133
|
+
homepage: https://bitbucket.org/nachootal/josean
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.5.2.3
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Implements the JSON layouts for Jasonette https://docs.jasonette.com.
|
157
|
+
test_files: []
|