├── .gitignore ├── .rspec ├── .travis.yml ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── lib ├── tawk_rails.rb └── tawk_rails │ ├── chatbox.rb │ ├── configuration.rb │ ├── rails │ ├── railtie.rb │ └── view_helpers.rb │ └── version.rb ├── spec ├── spec_helper.rb └── tawk_rails │ ├── chatbox_spec.rb │ ├── configuration_spec.rb │ └── version_spec.rb └── tawk_rails.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | vendor 7 | Gemfile.lock 8 | InstalledFiles 9 | _yardoc 10 | coverage 11 | doc/ 12 | lib/bundler/man 13 | pkg 14 | rdoc 15 | spec/reports 16 | test/tmp 17 | test/version_tmp 18 | tmp 19 | *.DS_Store -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in tawk_rails.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Wittawas Wisarnkanchana 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TawkRails 2 | 3 | [![Gem Version](https://badge.fury.io/rb/tawk_rails.svg)](http://badge.fury.io/rb/tawk_rails) 4 | [![Build Status](https://travis-ci.org/luizpicolo/tawk-rails.svg?branch=master)](https://travis-ci.org/luizpicolo/tawk-rails) 5 | 6 | Rails simple helper for [Tawk](https://www.tawk.to/) live chat script. Work rails >= 4 7 | 8 | ## Installation 9 | 10 | Add this line to your application's Gemfile: 11 | 12 | ```ruby 13 | gem 'tawk_rails' 14 | ``` 15 | 16 | And then execute: 17 | 18 | $ bundle 19 | 20 | Or install it yourself as: 21 | 22 | $ gem install tawk_rails 23 | 24 | ## Usage 25 | 26 | Create file `tawk.rb` in `config/initializers/tawk.rb` and add 27 | 28 | ```ruby 29 | TawkRails.configure do |config| 30 | config.id_site = 'replace-me-with-your-id_site' 31 | end 32 | ``` 33 | 34 | Place render method where you want in view. 35 | 36 | <%= tawk_init %> 37 | 38 | Make sure to put `tawk_init` into HTML body if you use Turbolinks. 39 | 40 | You can pass js methods as string to the helper https://www.tawk.to/javascript-api/ 41 | 42 | <%= tawk_init "Tawk_API.onStatusChange = function(status){console.log(status);}; Tawk_API.visitor = {name : 'Name', email : 'email@email.com'};" %> 43 | 44 | ## Contributing 45 | 46 | 1. Fork it ( https://github.com/luizpicolo/tawk_rails/fork ) 47 | 2. Create your feature branch (`git checkout -b my-new-feature`) 48 | 3. Commit your changes (`git commit -am 'Add some feature'`) 49 | 4. Push to the branch (`git push origin my-new-feature`) 50 | 5. Create new Pull Request 51 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rspec/core/rake_task" 3 | 4 | RSpec::Core::RakeTask.new 5 | 6 | task :default => :spec 7 | task :test => :spec 8 | -------------------------------------------------------------------------------- /lib/tawk_rails.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | require 'tawk_rails/chatbox' 3 | require 'tawk_rails/configuration' 4 | require 'tawk_rails/rails/railtie' 5 | require "tawk_rails/version" 6 | 7 | module TawkRails 8 | end 9 | -------------------------------------------------------------------------------- /lib/tawk_rails/chatbox.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | module TawkRails 3 | class Chatbox 4 | def initialize(params = nil) 5 | @params = params 6 | end 7 | 8 | def render_script 9 | <<-JAVASCRIPT 10 | 11 | JAVASCRIPT 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/tawk_rails/configuration.rb: -------------------------------------------------------------------------------- 1 | require_relative 'version' 2 | 3 | module TawkRails 4 | class << self 5 | attr_accessor :configuration 6 | end 7 | 8 | def self.configure 9 | self.configuration ||= Configuration.new 10 | yield(configuration) 11 | end 12 | 13 | class Configuration 14 | attr_accessor :id_site 15 | attr_reader :version 16 | 17 | def initialize 18 | @version = VERSION 19 | @id_site = 'replace-me-with-id_site' 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/tawk_rails/rails/railtie.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | require 'tawk_rails/rails/view_helpers' 4 | 5 | module TawkRails::Rails 6 | # @private 7 | class Railtie < ::Rails::Railtie 8 | initializer "tawk_rails" do 9 | ActionView::Base.send :include, ViewHelpers 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/tawk_rails/rails/view_helpers.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | require 'active_support/core_ext/string/output_safety' 3 | require 'active_support/core_ext/object/blank' 4 | 5 | module TawkRails::Rails 6 | module ViewHelpers 7 | def tawk_init(params = nil) 8 | queue = TawkRails::Chatbox.new(params) 9 | queue.render_script.html_safe 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/tawk_rails/version.rb: -------------------------------------------------------------------------------- 1 | module TawkRails 2 | VERSION = "1.2.0" 3 | end 4 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rspec --init` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause 4 | # this file to always be loaded, without a need to explicitly require it in any 5 | # files. 6 | # 7 | # Given that it is always loaded, you are encouraged to keep this file as 8 | # light-weight as possible. Requiring heavyweight dependencies from this file 9 | # will add to the boot time of your test suite on EVERY test run, even for an 10 | # individual file that may not need all of that loaded. Instead, consider making 11 | # a separate helper file that requires the additional dependencies and performs 12 | # the additional setup, and require it from the spec files that actually need 13 | # it. 14 | # 15 | # The `.rspec` file also contains a few flags that are not defaults but that 16 | # users commonly want. 17 | # 18 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 19 | RSpec.configure do |config| 20 | # rspec-expectations config goes here. You can use an alternate 21 | # assertion/expectation library such as wrong or the stdlib/minitest 22 | # assertions if you prefer. 23 | config.expect_with :rspec do |expectations| 24 | # This option will default to `true` in RSpec 4. It makes the `description` 25 | # and `failure_message` of custom matchers include text for helper methods 26 | # defined using `chain`, e.g.: 27 | # be_bigger_than(2).and_smaller_than(4).description 28 | # # => "be bigger than 2 and smaller than 4" 29 | # ...rather than: 30 | # # => "be bigger than 2" 31 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 32 | end 33 | 34 | # rspec-mocks config goes here. You can use an alternate test double 35 | # library (such as bogus or mocha) by changing the `mock_with` option here. 36 | config.mock_with :rspec do |mocks| 37 | # Prevents you from mocking or stubbing a method that does not exist on 38 | # a real object. This is generally recommended, and will default to 39 | # `true` in RSpec 4. 40 | mocks.verify_partial_doubles = true 41 | end 42 | 43 | # The settings below are suggested to provide a good initial experience 44 | # with RSpec, but feel free to customize to your heart's content. 45 | =begin 46 | # These two settings work together to allow you to limit a spec run 47 | # to individual examples or groups you care about by tagging them with 48 | # `:focus` metadata. When nothing is tagged with `:focus`, all examples 49 | # get run. 50 | config.filter_run :focus 51 | config.run_all_when_everything_filtered = true 52 | 53 | # Limits the available syntax to the non-monkey patched syntax that is 54 | # recommended. For more details, see: 55 | # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax 56 | # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 57 | # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching 58 | config.disable_monkey_patching! 59 | 60 | # This setting enables warnings. It's recommended, but in some cases may 61 | # be too noisy due to issues in dependencies. 62 | config.warnings = true 63 | 64 | # Many RSpec users commonly either run the entire suite or an individual 65 | # file, and it's useful to allow more verbose output when running an 66 | # individual spec file. 67 | if config.files_to_run.one? 68 | # Use the documentation formatter for detailed output, 69 | # unless a formatter has already been configured 70 | # (e.g. via a command-line flag). 71 | config.default_formatter = 'doc' 72 | end 73 | 74 | # Print the 10 slowest examples and example groups at the 75 | # end of the spec run, to help surface which specs are running 76 | # particularly slow. 77 | config.profile_examples = 10 78 | 79 | # Run specs in random order to surface order dependencies. If you find an 80 | # order dependency and want to debug it, you can fix the order by providing 81 | # the seed, which is printed after each run. 82 | # --seed 1234 83 | config.order = :random 84 | 85 | # Seed global randomization in this process using the `--seed` CLI option. 86 | # Setting this allows you to use `--seed` to deterministically reproduce 87 | # test failures related to randomization by passing the same `--seed` value 88 | # as the one that triggered the failure. 89 | Kernel.srand config.seed 90 | =end 91 | end 92 | -------------------------------------------------------------------------------- /spec/tawk_rails/chatbox_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require_relative '../../lib/tawk_rails/chatbox' 3 | 4 | describe TawkRails::Chatbox do 5 | 6 | before do 7 | TawkRails.configure do |config| 8 | config.id_site = 'replace-me-with-your-id_site' 9 | end 10 | end 11 | 12 | it "should return javascript correctly within params" do 13 | chatbox = TawkRails::Chatbox.new() 14 | expect(chatbox.render_script).to be_a_kind_of(String) 15 | end 16 | 17 | it "should return javascript correctly with params" do 18 | params = "Tawk_API.onStatusChange = function(status){console.log(status);}; Tawk_API.visitor = {name : 'Name', email : 'email@email.com'};" 19 | chatbox = TawkRails::Chatbox.new(params) 20 | expect(chatbox.render_script).to be_a_kind_of(String) 21 | expect(chatbox.render_script).to include(params) 22 | end 23 | 24 | it "should return JS within version" do 25 | chatbox = TawkRails::Chatbox.new() 26 | expect(chatbox.render_script).to include('replace-me-with-your-id_site') 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /spec/tawk_rails/configuration_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require_relative '../../lib/tawk_rails/configuration' 3 | 4 | describe TawkRails::Configuration do 5 | before do 6 | TawkRails.configure do |config| 7 | config.id_site = 'replace-me-with-your-id_site' 8 | end 9 | end 10 | 11 | it "should return id_site correctly" do 12 | expect(TawkRails.configuration.id_site).to be_a_kind_of(String) 13 | expect(TawkRails.configuration.id_site).to eq 'replace-me-with-your-id_site' 14 | end 15 | 16 | it "should return version correctly" do 17 | expect(TawkRails.configuration.version).to be_a_kind_of(String) 18 | expect(TawkRails.configuration.version).to eq '1.2.0' 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /spec/tawk_rails/version_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require_relative '../../lib/tawk_rails/version' 3 | 4 | describe TawkRails do 5 | 6 | it "should return version correctly" do 7 | expect(TawkRails::VERSION).to be_a_kind_of(String) 8 | expect(TawkRails::VERSION).to eq '1.2.0' 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /tawk_rails.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'tawk_rails/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "tawk_rails" 8 | spec.version = TawkRails::VERSION 9 | spec.authors = ["Luiz Picolo"] 10 | spec.email = ["luizpicolo@gmail.com"] 11 | spec.summary = %q{Rails helper for Tawk.to live chat script.} 12 | spec.description = %q{Rails helper for Tawk.to live chat.} 13 | spec.homepage = "https://github.com/luizpicolo/tawk-rails" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files -z`.split("\x0") 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ["lib"] 20 | 21 | spec.add_development_dependency "bundler", "~> 1.5" 22 | spec.add_development_dependency 'rake', '~> 0' 23 | spec.add_development_dependency 'rspec', '~> 3.0' 24 | end 25 | --------------------------------------------------------------------------------