wild-views 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58c42c53fa9cea1486246ca019ffa9c6d0abd397
4
+ data.tar.gz: b68e756e913e6fd37d670d82bbbaf065c78406a0
5
+ SHA512:
6
+ metadata.gz: 02eace4ff6d443d04d496e52338fd784a01a447041e9288aa10744fa8501f295eb4545fd7b0bf7b2b3dd36d1e6a782919082d85d2bf4c13810acfa0823a010b0
7
+ data.tar.gz: 0c20f49336fb4999b681fb3032f987a559816c1a41df5833238a567946f6677a13c140c5958180427dc7b9e9c046a4a538a7b29d100c2bdec7e74a2ad5f720ba
data/.gitignore ADDED
@@ -0,0 +1,51 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+ .byebug_history
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ sudo: false
2
+
3
+ language: ruby
4
+
5
+ rvm:
6
+ - 2.3.0
7
+ - 2.3.1
8
+ - ruby-head
9
+
10
+
11
+ gemfile:
12
+ - Gemfile
13
+ - gemfiles/Gemfile.rails-4.2-stable
14
+
15
+ cache: bundler
16
+
17
+ before_script: "bundle update"
18
+
19
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at emerson.almeida@youse.com.br. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 5.0.0'
6
+ gem 'bundler', '~> 1.12'
7
+ gem 'rake', '~> 10.0'
8
+
9
+ group :test do
10
+ gem 'minitest', '~> 5.0'
11
+ gem 'minitest-rails'
12
+ gem 'webmock'
13
+ gem 'byebug'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,139 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wild-views (0.1.0)
5
+ actionview (>= 4.2)
6
+ railties (>= 4.2.0, < 5.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (5.0.0.1)
12
+ actionpack (= 5.0.0.1)
13
+ nio4r (~> 1.2)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.0.0.1)
16
+ actionpack (= 5.0.0.1)
17
+ actionview (= 5.0.0.1)
18
+ activejob (= 5.0.0.1)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.0.0.1)
22
+ actionview (= 5.0.0.1)
23
+ activesupport (= 5.0.0.1)
24
+ rack (~> 2.0)
25
+ rack-test (~> 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.0.0.1)
29
+ activesupport (= 5.0.0.1)
30
+ builder (~> 3.1)
31
+ erubis (~> 2.7.0)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
34
+ activejob (5.0.0.1)
35
+ activesupport (= 5.0.0.1)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.0.0.1)
38
+ activesupport (= 5.0.0.1)
39
+ activerecord (5.0.0.1)
40
+ activemodel (= 5.0.0.1)
41
+ activesupport (= 5.0.0.1)
42
+ arel (~> 7.0)
43
+ activesupport (5.0.0.1)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ i18n (~> 0.7)
46
+ minitest (~> 5.1)
47
+ tzinfo (~> 1.1)
48
+ addressable (2.4.0)
49
+ arel (7.1.2)
50
+ builder (3.2.2)
51
+ byebug (9.0.5)
52
+ concurrent-ruby (1.0.2)
53
+ crack (0.4.3)
54
+ safe_yaml (~> 1.0.0)
55
+ erubis (2.7.0)
56
+ globalid (0.3.7)
57
+ activesupport (>= 4.1.0)
58
+ hashdiff (0.3.0)
59
+ i18n (0.7.0)
60
+ loofah (2.0.3)
61
+ nokogiri (>= 1.5.9)
62
+ mail (2.6.4)
63
+ mime-types (>= 1.16, < 4)
64
+ method_source (0.8.2)
65
+ mime-types (3.1)
66
+ mime-types-data (~> 3.2015)
67
+ mime-types-data (3.2016.0521)
68
+ mini_portile2 (2.1.0)
69
+ minitest (5.9.0)
70
+ minitest-rails (3.0.0)
71
+ minitest (~> 5.8)
72
+ railties (~> 5.0)
73
+ nio4r (1.2.1)
74
+ nokogiri (1.6.8)
75
+ mini_portile2 (~> 2.1.0)
76
+ pkg-config (~> 1.1.7)
77
+ pkg-config (1.1.7)
78
+ rack (2.0.1)
79
+ rack-test (0.6.3)
80
+ rack (>= 1.0)
81
+ rails (5.0.0.1)
82
+ actioncable (= 5.0.0.1)
83
+ actionmailer (= 5.0.0.1)
84
+ actionpack (= 5.0.0.1)
85
+ actionview (= 5.0.0.1)
86
+ activejob (= 5.0.0.1)
87
+ activemodel (= 5.0.0.1)
88
+ activerecord (= 5.0.0.1)
89
+ activesupport (= 5.0.0.1)
90
+ bundler (>= 1.3.0, < 2.0)
91
+ railties (= 5.0.0.1)
92
+ sprockets-rails (>= 2.0.0)
93
+ rails-dom-testing (2.0.1)
94
+ activesupport (>= 4.2.0, < 6.0)
95
+ nokogiri (~> 1.6.0)
96
+ rails-html-sanitizer (1.0.3)
97
+ loofah (~> 2.0)
98
+ railties (5.0.0.1)
99
+ actionpack (= 5.0.0.1)
100
+ activesupport (= 5.0.0.1)
101
+ method_source
102
+ rake (>= 0.8.7)
103
+ thor (>= 0.18.1, < 2.0)
104
+ rake (10.5.0)
105
+ safe_yaml (1.0.4)
106
+ sprockets (3.7.0)
107
+ concurrent-ruby (~> 1.0)
108
+ rack (> 1, < 3)
109
+ sprockets-rails (3.2.0)
110
+ actionpack (>= 4.0)
111
+ activesupport (>= 4.0)
112
+ sprockets (>= 3.0.0)
113
+ thor (0.19.1)
114
+ thread_safe (0.3.5)
115
+ tzinfo (1.2.2)
116
+ thread_safe (~> 0.1)
117
+ webmock (2.1.0)
118
+ addressable (>= 2.3.6)
119
+ crack (>= 0.3.2)
120
+ hashdiff
121
+ websocket-driver (0.6.4)
122
+ websocket-extensions (>= 0.1.0)
123
+ websocket-extensions (0.1.2)
124
+
125
+ PLATFORMS
126
+ ruby
127
+
128
+ DEPENDENCIES
129
+ bundler (~> 1.12)
130
+ byebug
131
+ minitest (~> 5.0)
132
+ minitest-rails
133
+ rails (~> 5.0.0)
134
+ rake (~> 10.0)
135
+ webmock
136
+ wild-views!
137
+
138
+ BUNDLED WITH
139
+ 1.12.5
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Wild::Views
2
+
3
+ Wild views allows you use easily your views from a remote server
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'wild-views'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ After the gem installed, execute:
18
+
19
+ $ rails g wild:views:install
20
+
21
+
22
+ ## Configuration
23
+
24
+ You should configure your views endpoint in `config/wild_views.yml`, by default
25
+ wild_views will use `VIEWS_ENDPOINT` environment:
26
+
27
+
28
+ ``` yaml
29
+ default: &default
30
+ endpoint: <%= ENV.fetch('VIEWS_ENDPOINT') %>
31
+
32
+ development:
33
+ <<: *default
34
+
35
+ test:
36
+ <<: *default
37
+
38
+ production:
39
+ <<: *default
40
+ ```
41
+
42
+ ### Being wild
43
+
44
+ Now on your view you can set `remote: true` to request the template from your
45
+ views service:
46
+
47
+
48
+ ``` erb
49
+ <%= render partial: 'components/loading', remote: true
50
+ ```
51
+
52
+ This code you make the follow http request, given the `Wild::View.endpoint` as
53
+ 'http://templates.myapp.com':
54
+
55
+ ```
56
+ GET "http://templates.myapp.com/components/loading"
57
+ ```
58
+
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ 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).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wild-views. 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.
69
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wild/views"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'rails', '~> 4.2'
6
+ gem 'bundler', '~> 1.12'
7
+ gem 'rake', '~> 10.0'
8
+
9
+ group :test do
10
+ gem 'minitest', '~> 5.0'
11
+ gem 'minitest-rails', '~> 2.2'
12
+ gem 'webmock'
13
+ gem 'byebug'
14
+ end
@@ -0,0 +1,134 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ wild-views (0.1.0)
5
+ actionview (>= 4.2)
6
+ railties (>= 4.2.0, < 5.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (4.2.7.1)
12
+ actionpack (= 4.2.7.1)
13
+ actionview (= 4.2.7.1)
14
+ activejob (= 4.2.7.1)
15
+ mail (~> 2.5, >= 2.5.4)
16
+ rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ actionpack (4.2.7.1)
18
+ actionview (= 4.2.7.1)
19
+ activesupport (= 4.2.7.1)
20
+ rack (~> 1.6)
21
+ rack-test (~> 0.6.2)
22
+ rails-dom-testing (~> 1.0, >= 1.0.5)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ actionview (4.2.7.1)
25
+ activesupport (= 4.2.7.1)
26
+ builder (~> 3.1)
27
+ erubis (~> 2.7.0)
28
+ rails-dom-testing (~> 1.0, >= 1.0.5)
29
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
+ activejob (4.2.7.1)
31
+ activesupport (= 4.2.7.1)
32
+ globalid (>= 0.3.0)
33
+ activemodel (4.2.7.1)
34
+ activesupport (= 4.2.7.1)
35
+ builder (~> 3.1)
36
+ activerecord (4.2.7.1)
37
+ activemodel (= 4.2.7.1)
38
+ activesupport (= 4.2.7.1)
39
+ arel (~> 6.0)
40
+ activesupport (4.2.7.1)
41
+ i18n (~> 0.7)
42
+ json (~> 1.7, >= 1.7.7)
43
+ minitest (~> 5.1)
44
+ thread_safe (~> 0.3, >= 0.3.4)
45
+ tzinfo (~> 1.1)
46
+ addressable (2.4.0)
47
+ arel (6.0.3)
48
+ builder (3.2.2)
49
+ byebug (9.0.5)
50
+ concurrent-ruby (1.0.2)
51
+ crack (0.4.3)
52
+ safe_yaml (~> 1.0.0)
53
+ erubis (2.7.0)
54
+ globalid (0.3.7)
55
+ activesupport (>= 4.1.0)
56
+ hashdiff (0.3.0)
57
+ i18n (0.7.0)
58
+ json (1.8.3)
59
+ loofah (2.0.3)
60
+ nokogiri (>= 1.5.9)
61
+ mail (2.6.4)
62
+ mime-types (>= 1.16, < 4)
63
+ mime-types (3.1)
64
+ mime-types-data (~> 3.2015)
65
+ mime-types-data (3.2016.0521)
66
+ mini_portile2 (2.1.0)
67
+ minitest (5.9.0)
68
+ minitest-rails (2.2.1)
69
+ minitest (~> 5.7)
70
+ railties (~> 4.1)
71
+ nokogiri (1.6.8)
72
+ mini_portile2 (~> 2.1.0)
73
+ pkg-config (~> 1.1.7)
74
+ pkg-config (1.1.7)
75
+ rack (1.6.4)
76
+ rack-test (0.6.3)
77
+ rack (>= 1.0)
78
+ rails (4.2.7.1)
79
+ actionmailer (= 4.2.7.1)
80
+ actionpack (= 4.2.7.1)
81
+ actionview (= 4.2.7.1)
82
+ activejob (= 4.2.7.1)
83
+ activemodel (= 4.2.7.1)
84
+ activerecord (= 4.2.7.1)
85
+ activesupport (= 4.2.7.1)
86
+ bundler (>= 1.3.0, < 2.0)
87
+ railties (= 4.2.7.1)
88
+ sprockets-rails
89
+ rails-deprecated_sanitizer (1.0.3)
90
+ activesupport (>= 4.2.0.alpha)
91
+ rails-dom-testing (1.0.7)
92
+ activesupport (>= 4.2.0.beta, < 5.0)
93
+ nokogiri (~> 1.6.0)
94
+ rails-deprecated_sanitizer (>= 1.0.1)
95
+ rails-html-sanitizer (1.0.3)
96
+ loofah (~> 2.0)
97
+ railties (4.2.7.1)
98
+ actionpack (= 4.2.7.1)
99
+ activesupport (= 4.2.7.1)
100
+ rake (>= 0.8.7)
101
+ thor (>= 0.18.1, < 2.0)
102
+ rake (10.5.0)
103
+ safe_yaml (1.0.4)
104
+ sprockets (3.7.0)
105
+ concurrent-ruby (~> 1.0)
106
+ rack (> 1, < 3)
107
+ sprockets-rails (3.2.0)
108
+ actionpack (>= 4.0)
109
+ activesupport (>= 4.0)
110
+ sprockets (>= 3.0.0)
111
+ thor (0.19.1)
112
+ thread_safe (0.3.5)
113
+ tzinfo (1.2.2)
114
+ thread_safe (~> 0.1)
115
+ webmock (2.1.0)
116
+ addressable (>= 2.3.6)
117
+ crack (>= 0.3.2)
118
+ hashdiff
119
+
120
+ PLATFORMS
121
+ ruby
122
+
123
+ DEPENDENCIES
124
+ bundler (~> 1.12)
125
+ byebug
126
+ minitest (~> 5.0)
127
+ minitest-rails (~> 2.2)
128
+ rails (~> 4.2)
129
+ rake (~> 10.0)
130
+ webmock
131
+ wild-views!
132
+
133
+ BUNDLED WITH
134
+ 1.12.5
@@ -0,0 +1,11 @@
1
+ default: &default
2
+ endpoint: <%= ENV.fetch('VIEWS_ENDPOINT') %>
3
+
4
+ development:
5
+ <<: *default
6
+
7
+ test:
8
+ <<: *default
9
+
10
+ production:
11
+ <<: *default
@@ -0,0 +1,13 @@
1
+ module Wild
2
+ module Views
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../templates', __FILE__)
6
+
7
+ def copy_config
8
+ copy_file 'config/wild_views.yml', 'config/wild_views.yml'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/wild/views.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "wild/views/version"
2
+ require "wild/views/railtie"
3
+ require "wild/views/remote_renderer"
4
+ require "wild/views/ext/action_view/renderer_ext.rb"
5
+
6
+ module Wild
7
+ module Views
8
+ mattr_accessor :config
9
+ mattr_accessor :root
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'action_view/renderer/renderer'
2
+
3
+ module ActionView
4
+ class Renderer
5
+ alias :old_render :render
6
+
7
+ def render(context, options)
8
+ if options[:remote]
9
+ render_remote(context, options)
10
+ else
11
+ old_render(context, options)
12
+ end
13
+ end
14
+
15
+ def render_remote(context, options)
16
+ Wild::View::RemoteRenderer.new(@lookup_context).render(context, options)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ require 'rails/railtie'
2
+ require 'action_view/railtie'
3
+
4
+ module Wild
5
+ module Views
6
+ # Configuring Wild::Views with rails
7
+ class Railtie < ::Rails::Railtie
8
+ railtie_name :wild_views
9
+
10
+ initializer 'wild_views.setup_config' do
11
+ begin
12
+ Wild::Views.config = Rails.application.config_for(:wild_views)
13
+ rescue RuntimeError
14
+ end
15
+ end
16
+
17
+ initializer 'wild_views.add_view_paths', after: :add_view_paths do |app|
18
+ Wild::Views.root = app.root.join('tmp', 'remote-views')
19
+
20
+ ActiveSupport.on_load(:action_controller) do
21
+ append_view_path Wild::Views.root
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,79 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ module Wild
5
+ module View
6
+ # RemoteRenderer
7
+ #
8
+ # This class extend ActionView::Renderer and overwriten the render methods
9
+ # to download views from configure endpoint
10
+ class RemoteRenderer < ActionView::Renderer
11
+ def render(context, options)
12
+ options.delete(:remote)
13
+ super(context, options)
14
+ end
15
+
16
+ # def render_body(context, options)
17
+ # super(context, options)
18
+ # end
19
+ #
20
+ # def render_template(context, options)
21
+ # super(context, options)
22
+ # end
23
+
24
+ def render_partial(context, options, &block) #:nodoc:
25
+ download_and_save_view(options[:partial])
26
+ super(context, options)
27
+ end
28
+
29
+ private
30
+
31
+ def download_and_save_view(view_name)
32
+ view_data = download_view(view_name)
33
+ save_view(view_name, view_data)
34
+ end
35
+
36
+ def download_view(view_name)
37
+ response = http.get endpoint_path(view_name)
38
+ response.value
39
+ response.body
40
+ end
41
+
42
+ def save_view(view_name, view_data)
43
+ view_path = build_view_path(view_name)
44
+ ensure_directory_exists(view_path)
45
+ write_view(view_path, view_data)
46
+ end
47
+
48
+ def build_view_path(view_name)
49
+ path = view_name.split('/')
50
+ path[-1] = view_file_name(path.last)
51
+ Wild::Views.root.join(*path)
52
+ end
53
+
54
+ def view_file_name(view_name)
55
+ "_#{view_name}.html.erb"
56
+ end
57
+
58
+ def endpoint_path(view_name)
59
+ "/#{view_name}"
60
+ end
61
+
62
+
63
+ def http
64
+ @http ||= begin
65
+ uri = URI(Wild::Views.config['endpoint'])
66
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https')
67
+ end
68
+ end
69
+
70
+ def ensure_directory_exists(view_name)
71
+ FileUtils.mkdir_p(File.dirname(view_name))
72
+ end
73
+
74
+ def write_view(view_path, view_data)
75
+ File.open(view_path, 'w') { |f| f.write(view_data) }
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ module Wild
2
+ module Views
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class RendererTest < Minitest::Test
4
+ def test_should_call_render_template_when_no_options
5
+ renderer = ActionView::Renderer.new Minitest::Mock.new
6
+ renderer.stub(:render_template, 'rendering template') do
7
+ result = renderer.render('test', {})
8
+ assert_equal result, 'rendering template'
9
+ end
10
+ end
11
+
12
+ def test_should_call_render_partial_when_has_options_partial
13
+ renderer = ActionView::Renderer.new Minitest::Mock.new
14
+
15
+ renderer.stub(:render_partial, 'rendering partial') do
16
+ result = renderer.render('test', { partial: 'test' })
17
+ assert_equal result, 'rendering partial'
18
+ end
19
+ end
20
+
21
+ def test_should_call_render_remote_partial_when_remote_is_true
22
+ renderer = ActionView::Renderer.new Minitest::Mock.new
23
+
24
+ renderer.stub(:render_remote, 'rendering remote') do
25
+ result = renderer.render('test', { remote: true })
26
+ assert_equal result, 'rendering remote'
27
+ end
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ Hello <%= name %>
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'wild/views'
3
+ require 'minitest/mock'
4
+ require 'minitest/autorun'
5
+ require 'webmock/minitest'
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+ require 'byebug'
3
+
4
+ module Wild
5
+ # Testing Wild::RemoteRendererTest
6
+ class RemoteRendererTest < Minitest::Test
7
+ def setup
8
+ Wild::Views.root = Pathname.new 'test/fixtures-remote/views'
9
+ Wild::Views.config = { 'endpoint' => 'http://myendpoint.com' }
10
+ end
11
+
12
+ def teardown
13
+ FileUtils.rm_rf Wild::Views.root.parent
14
+ end
15
+
16
+ def lookup_context
17
+ @lookup_context ||= begin
18
+ ActionView::LookupContext.new ['test/fixtures/views', Wild::Views.root]
19
+ end
20
+ end
21
+
22
+ def view
23
+ OpenStruct.new lookup_context: lookup_context
24
+ end
25
+
26
+ def test_render_normal_partial
27
+ renderer = ActionView::Renderer.new lookup_context
28
+ locals = { name: 'test' }
29
+
30
+ result = renderer.render view, partial: 'partial_test', locals: locals
31
+ assert_equal result, "Hello test\n"
32
+ end
33
+
34
+ def test_render_partial_from_remote_server
35
+ stub_request(:get, 'http://myendpoint.com/partial_remote')
36
+ .to_return(status: 200,
37
+ body: 'Hello <%= name %> from remote server'
38
+ )
39
+
40
+ renderer = ActionView::Renderer.new lookup_context
41
+ locals = { name: 'test' }
42
+
43
+ result = renderer.render view, partial: 'partial_remote',
44
+ remote: true,
45
+ locals: locals
46
+ assert_equal result, 'Hello test from remote server'
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ module Wild
4
+ # Testing Wild::Views
5
+ class ViewsTest < Minitest::Test
6
+ def test_that_it_has_a_version_number
7
+ refute_nil ::Wild::Views::VERSION
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wild/views/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'wild-views'
8
+ spec.version = Wild::Views::VERSION
9
+ spec.authors = ['Duke']
10
+ spec.email = ['emerson.almeida@youse.com.br']
11
+ spec.summary = 'Render views on rails from a remote service'
12
+ spec.description = 'Render views on rails from a remote service'
13
+ spec.homepage = 'http://github.com/youse-seguradora/wild_views'
14
+ spec.licenses = ['MIT']
15
+
16
+ spec.files = `git ls-files`.split("\n")
17
+ spec.test_files = `git ls-files -- test/*`.split("\n")
18
+
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'actionview', '>= 4.2'
24
+ spec.add_dependency 'railties', '>= 4.2.0', '< 5.1'
25
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wild-views
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Duke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.2.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '5.1'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 4.2.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.1'
47
+ description: Render views on rails from a remote service
48
+ email:
49
+ - emerson.almeida@youse.com.br
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".gitignore"
55
+ - ".travis.yml"
56
+ - CODE_OF_CONDUCT.md
57
+ - Gemfile
58
+ - Gemfile.lock
59
+ - README.md
60
+ - Rakefile
61
+ - bin/console
62
+ - bin/setup
63
+ - gemfiles/Gemfile.rails-4.2-stable
64
+ - gemfiles/Gemfile.rails-4.2-stable.lock
65
+ - lib/generators/templates/config/wild_views.yml
66
+ - lib/generators/wild/views/install_generator.rb
67
+ - lib/wild/views.rb
68
+ - lib/wild/views/ext/action_view/renderer_ext.rb
69
+ - lib/wild/views/railtie.rb
70
+ - lib/wild/views/remote_renderer.rb
71
+ - lib/wild/views/version.rb
72
+ - test/action_view/renderer/renderer_ext_test.rb
73
+ - test/fixtures/views/_partial_test.html.erb
74
+ - test/test_helper.rb
75
+ - test/wild/remote_renderer_test.rb
76
+ - test/wild/views_test.rb
77
+ - wild-views.gemspec
78
+ homepage: http://github.com/youse-seguradora/wild_views
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Render views on rails from a remote service
102
+ test_files:
103
+ - test/action_view/renderer/renderer_ext_test.rb
104
+ - test/fixtures/views/_partial_test.html.erb
105
+ - test/test_helper.rb
106
+ - test/wild/remote_renderer_test.rb
107
+ - test/wild/views_test.rb