kamiflex 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/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +27 -0
- data/lib/kamiflex/railtie.rb +4 -0
- data/lib/kamiflex/version.rb +3 -0
- data/lib/kamiflex.rb +164 -0
- data/lib/tasks/kamiflex_tasks.rake +4 -0
- metadata +67 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: f17268df0c41a86c2bcbe263ee1afb9da8817dd7ea2fff66a542d4eb79e908bc
         | 
| 4 | 
            +
              data.tar.gz: 38864bcae3bacba2fcd7ee32085f69ed5b05992aef2a56cf5e404cdf700c3a05
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 3c60c9c1731877dab32564d86ae6523634a9997f81a53a93f130d93688d906239eabc0c6380f64431e96662299ae64111228436b9e83755e7f6c3e7a6ca3e9fe
         | 
| 7 | 
            +
              data.tar.gz: 457c9f06cc3ef215fe6f03e6211e58a6367a698e27dbeb8047144bc872d9f390df8d1aa8f467a315449c4e348629deeb6398dc5f4624de965497a22ce7db85b4
         | 
    
        data/MIT-LICENSE
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            Copyright 2019 etrex kuo
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 4 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 5 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 6 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 7 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 8 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 9 | 
            +
            the following conditions:
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 12 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 15 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 16 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 17 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 18 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 19 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 20 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            # Kamiflex
         | 
| 2 | 
            +
            Short description and motivation.
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            ## Usage
         | 
| 5 | 
            +
            How to use my plugin.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ## Installation
         | 
| 8 | 
            +
            Add this line to your application's Gemfile:
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            ```ruby
         | 
| 11 | 
            +
            gem 'kamiflex'
         | 
| 12 | 
            +
            ```
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            And then execute:
         | 
| 15 | 
            +
            ```bash
         | 
| 16 | 
            +
            $ bundle
         | 
| 17 | 
            +
            ```
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            Or install it yourself as:
         | 
| 20 | 
            +
            ```bash
         | 
| 21 | 
            +
            $ gem install kamiflex
         | 
| 22 | 
            +
            ```
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            ## Contributing
         | 
| 25 | 
            +
            Contribution directions go here.
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            ## License
         | 
| 28 | 
            +
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            begin
         | 
| 2 | 
            +
              require 'bundler/setup'
         | 
| 3 | 
            +
            rescue LoadError
         | 
| 4 | 
            +
              puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
         | 
| 5 | 
            +
            end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            require 'rdoc/task'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            RDoc::Task.new(:rdoc) do |rdoc|
         | 
| 10 | 
            +
              rdoc.rdoc_dir = 'rdoc'
         | 
| 11 | 
            +
              rdoc.title    = 'Kamiflex'
         | 
| 12 | 
            +
              rdoc.options << '--line-numbers'
         | 
| 13 | 
            +
              rdoc.rdoc_files.include('README.md')
         | 
| 14 | 
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            require 'bundler/gem_tasks'
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            require 'rake/testtask'
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            Rake::TestTask.new(:test) do |t|
         | 
| 22 | 
            +
              t.libs << 'test'
         | 
| 23 | 
            +
              t.pattern = 'test/**/*_test.rb'
         | 
| 24 | 
            +
              t.verbose = false
         | 
| 25 | 
            +
            end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            task default: :test
         | 
    
        data/lib/kamiflex.rb
    ADDED
    
    | @@ -0,0 +1,164 @@ | |
| 1 | 
            +
            require "kamiflex/railtie"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KamiflexModule
         | 
| 4 | 
            +
              def bubble
         | 
| 5 | 
            +
                attributes, _contents = flex_scope{ yield }
         | 
| 6 | 
            +
                {
         | 
| 7 | 
            +
                  type: "flex",
         | 
| 8 | 
            +
                  altText: "this is a flex message",
         | 
| 9 | 
            +
                  contents: {
         | 
| 10 | 
            +
                    type: "bubble"
         | 
| 11 | 
            +
                  }.merge(attributes)
         | 
| 12 | 
            +
                }
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              # bubble attributes
         | 
| 16 | 
            +
              def header(**params)
         | 
| 17 | 
            +
                _attributes, contents = flex_scope{ yield }
         | 
| 18 | 
            +
                @flex_attributes[:header] = {
         | 
| 19 | 
            +
                  type: "box",
         | 
| 20 | 
            +
                  layout: "vertical",
         | 
| 21 | 
            +
                  contents: contents
         | 
| 22 | 
            +
                }.merge(params)
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def hero(image_url, **params)
         | 
| 26 | 
            +
                _attributes, _contents = flex_scope{ yield }
         | 
| 27 | 
            +
                @flex_attributes[:hero] = {}
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              def body(**params)
         | 
| 31 | 
            +
                _attributes, contents = flex_scope{ yield }
         | 
| 32 | 
            +
                @flex_attributes[:body] = {
         | 
| 33 | 
            +
                  type: "box",
         | 
| 34 | 
            +
                  layout: "vertical",
         | 
| 35 | 
            +
                  contents: contents
         | 
| 36 | 
            +
                }.merge(params)
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              def footer(**params)
         | 
| 40 | 
            +
                _attributes, contents = flex_scope{ yield }
         | 
| 41 | 
            +
                @flex_attributes[:footer] = {
         | 
| 42 | 
            +
                  type: "box",
         | 
| 43 | 
            +
                  layout: "vertical",
         | 
| 44 | 
            +
                  contents: contents
         | 
| 45 | 
            +
                }.merge(params)
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              # container
         | 
| 49 | 
            +
              def horizontal_box(resources = [nil], **params)
         | 
| 50 | 
            +
                resources.each do |resource|
         | 
| 51 | 
            +
                  _attributes, contents = flex_scope{ yield resource }
         | 
| 52 | 
            +
                  @flex_contents << {
         | 
| 53 | 
            +
                    type: "box",
         | 
| 54 | 
            +
                    layout: "horizontal",
         | 
| 55 | 
            +
                    contents: contents
         | 
| 56 | 
            +
                  }.merge(params)
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              def vertical_box(resources = [nil], **params, &block)
         | 
| 61 | 
            +
                horizontal_box(resources, layout: "vertical", **params, &block)
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              def baseline_box(resources = [nil], **params, &block)
         | 
| 65 | 
            +
                horizontal_box(resources, layout: "baseline", **params, &block)
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              # elements
         | 
| 69 | 
            +
              def text(message, **params)
         | 
| 70 | 
            +
                @flex_contents << {
         | 
| 71 | 
            +
                  "type": "text",
         | 
| 72 | 
            +
                  "text": message
         | 
| 73 | 
            +
                }.merge(params)
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              def image(url, **params)
         | 
| 77 | 
            +
                @flex_contents << {
         | 
| 78 | 
            +
                  "type": "image",
         | 
| 79 | 
            +
                  "url": url
         | 
| 80 | 
            +
                }.merge(params)
         | 
| 81 | 
            +
              end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
              def icon(url, **params)
         | 
| 84 | 
            +
                @flex_contents << {
         | 
| 85 | 
            +
                  "type": "image",
         | 
| 86 | 
            +
                  "url": url
         | 
| 87 | 
            +
                }.merge(params)
         | 
| 88 | 
            +
              end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
              def separator(**params)
         | 
| 91 | 
            +
                @flex_contents << {
         | 
| 92 | 
            +
                  "type": "separator",
         | 
| 93 | 
            +
                  "margin": "md",
         | 
| 94 | 
            +
                  "color": "#000000",
         | 
| 95 | 
            +
                }.merge(params)
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              def spacer(**params)
         | 
| 99 | 
            +
                @flex_contents << {
         | 
| 100 | 
            +
                  "type": "spacer",
         | 
| 101 | 
            +
                  "size": "md",
         | 
| 102 | 
            +
                }.merge(params)
         | 
| 103 | 
            +
              end
         | 
| 104 | 
            +
             | 
| 105 | 
            +
              def url_button(label, url, **params)
         | 
| 106 | 
            +
                @flex_contents << {
         | 
| 107 | 
            +
                  "type": "button",
         | 
| 108 | 
            +
                  "action": {
         | 
| 109 | 
            +
                    "type": "uri",
         | 
| 110 | 
            +
                    "label": label,
         | 
| 111 | 
            +
                    "uri": url
         | 
| 112 | 
            +
                  }
         | 
| 113 | 
            +
                }.merge(params)
         | 
| 114 | 
            +
              end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
              def message_button(label, message, **params)
         | 
| 117 | 
            +
                @flex_contents << {
         | 
| 118 | 
            +
                  "type": "button",
         | 
| 119 | 
            +
                  "action": {
         | 
| 120 | 
            +
                    "type": "message",
         | 
| 121 | 
            +
                    "label": label,
         | 
| 122 | 
            +
                    "text": message
         | 
| 123 | 
            +
                  }
         | 
| 124 | 
            +
                }.merge(params)
         | 
| 125 | 
            +
              end
         | 
| 126 | 
            +
             | 
| 127 | 
            +
              # actions
         | 
| 128 | 
            +
              def message_action(label, **params)
         | 
| 129 | 
            +
                {
         | 
| 130 | 
            +
                  type: "message",
         | 
| 131 | 
            +
                  label: label,
         | 
| 132 | 
            +
                  text: label
         | 
| 133 | 
            +
                }.merge(params)
         | 
| 134 | 
            +
              end
         | 
| 135 | 
            +
             | 
| 136 | 
            +
              def uri_action(uri, **params)
         | 
| 137 | 
            +
                {
         | 
| 138 | 
            +
                  type: "uri",
         | 
| 139 | 
            +
                  label: uri[0...40],
         | 
| 140 | 
            +
                  uri: uri,
         | 
| 141 | 
            +
                  # altUri: {
         | 
| 142 | 
            +
                  #   desktop: uri
         | 
| 143 | 
            +
                  # }
         | 
| 144 | 
            +
                }
         | 
| 145 | 
            +
              end
         | 
| 146 | 
            +
             | 
| 147 | 
            +
              private
         | 
| 148 | 
            +
             | 
| 149 | 
            +
              def flex_scope
         | 
| 150 | 
            +
                parent_attributes, parent_contents = @flex_attributes, @flex_contents
         | 
| 151 | 
            +
                @flex_attributes, @flex_contents = {}, []
         | 
| 152 | 
            +
                yield self
         | 
| 153 | 
            +
                [@flex_attributes, @flex_contents]
         | 
| 154 | 
            +
              ensure
         | 
| 155 | 
            +
                @flex_attributes, @flex_contents = parent_attributes, parent_contents
         | 
| 156 | 
            +
              end
         | 
| 157 | 
            +
            end
         | 
| 158 | 
            +
             | 
| 159 | 
            +
            class Kamiflex
         | 
| 160 | 
            +
              def self.build(parent)
         | 
| 161 | 
            +
                parent.class.include KamiflexModule
         | 
| 162 | 
            +
                yield
         | 
| 163 | 
            +
              end
         | 
| 164 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,67 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: kamiflex
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - etrex kuo
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2019-03-20 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: rails
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 5.2.2
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: 5.2.2
         | 
| 27 | 
            +
            description: Kamiflex provide you a clear way to manage your flex message. It's easy
         | 
| 28 | 
            +
              to build an complex flex message with conditionals and loops.
         | 
| 29 | 
            +
            email:
         | 
| 30 | 
            +
            - et284vu065k3@gmail.com
         | 
| 31 | 
            +
            executables: []
         | 
| 32 | 
            +
            extensions: []
         | 
| 33 | 
            +
            extra_rdoc_files: []
         | 
| 34 | 
            +
            files:
         | 
| 35 | 
            +
            - MIT-LICENSE
         | 
| 36 | 
            +
            - README.md
         | 
| 37 | 
            +
            - Rakefile
         | 
| 38 | 
            +
            - lib/kamiflex.rb
         | 
| 39 | 
            +
            - lib/kamiflex/railtie.rb
         | 
| 40 | 
            +
            - lib/kamiflex/version.rb
         | 
| 41 | 
            +
            - lib/tasks/kamiflex_tasks.rake
         | 
| 42 | 
            +
            homepage: https://github.com/etrex/kamiflex
         | 
| 43 | 
            +
            licenses:
         | 
| 44 | 
            +
            - MIT
         | 
| 45 | 
            +
            metadata:
         | 
| 46 | 
            +
              allowed_push_host: https://rubygems.org
         | 
| 47 | 
            +
            post_install_message: 
         | 
| 48 | 
            +
            rdoc_options: []
         | 
| 49 | 
            +
            require_paths:
         | 
| 50 | 
            +
            - lib
         | 
| 51 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 52 | 
            +
              requirements:
         | 
| 53 | 
            +
              - - ">="
         | 
| 54 | 
            +
                - !ruby/object:Gem::Version
         | 
| 55 | 
            +
                  version: '0'
         | 
| 56 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 57 | 
            +
              requirements:
         | 
| 58 | 
            +
              - - ">="
         | 
| 59 | 
            +
                - !ruby/object:Gem::Version
         | 
| 60 | 
            +
                  version: '0'
         | 
| 61 | 
            +
            requirements: []
         | 
| 62 | 
            +
            rubygems_version: 3.0.3
         | 
| 63 | 
            +
            signing_key: 
         | 
| 64 | 
            +
            specification_version: 4
         | 
| 65 | 
            +
            summary: 'Kamiflex: generate JSON objects for Line flex message with a Builder-style
         | 
| 66 | 
            +
              DSL'
         | 
| 67 | 
            +
            test_files: []
         |