work_in_progress 0.0.1

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: 3a394d2958769130db0b532c19da62011bc28c9a
4
+ data.tar.gz: 09af8601837c7130b54e8daf9def5d3d872cf5ed
5
+ SHA512:
6
+ metadata.gz: 7cd841e6af08fa976098427aafd71238033265d3514caacbc858766c1aa611950cb38f74b3d423b30b5fe4954c23465c67de563de986d60fea9cac37e4b1dec2
7
+ data.tar.gz: 011f2504e0f2efea3a551dadbc323ca0df4c1e9176f0dec51143c00ae654927f0e80d40e926f5617d33f1b47f8bd57ca2a0235d8c9637081db20b03d8f7db6a6
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in work_in_progress.gemspec
4
+ gemspec
5
+
6
+ gem "rails", "4.2.1"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Michał Krajewski
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.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # WorkInProgress
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'work_in_progress'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install work_in_progress
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/work_in_progress/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.pattern = "test/**/*_test.rb"
8
+ end
@@ -0,0 +1,4 @@
1
+ WorkInProgress.setup do |config|
2
+ config.framework = :rails
3
+ config.permited_users = []
4
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/generators/base'
2
+
3
+ module WorkInProgress
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("../../templates", __FILE__)
7
+
8
+ desc "Creates a Devise initializer and copy locale files to your application."
9
+ def copy_initializer
10
+ template "work_in_progress.rb", "config/initializers/work_in_progress.rb"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ require "work_in_progress/version"
2
+ require "work_in_progress/view_helpers"
3
+
4
+ if defined?(Rails)
5
+ require "work_in_progress/railtie"
6
+ end
7
+
8
+ module WorkInProgress
9
+
10
+ # Choose framework solution
11
+ mattr_accessor :framework
12
+ @@framework = nil
13
+
14
+ # List permited users emails
15
+ mattr_accessor :permited_users
16
+ @@permited_users = []
17
+
18
+ # Default way to setup Work in Progress.
19
+ def self.setup
20
+ yield self
21
+ end
22
+
23
+ end
@@ -0,0 +1,7 @@
1
+ module WorkInProgress
2
+ class Railtie < Rails::Railtie
3
+ initializer 'work_in_progress.view_helpers' do
4
+ ActionView::Base.send :include, ViewHelpers
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module WorkInProgress
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'action_view'
2
+
3
+ include ActionView::Helpers::TagHelper
4
+ include ActionView::Context
5
+
6
+ module WorkInProgress
7
+ module ViewHelpers
8
+ def work_in_progress(opts={}, &block)
9
+ if user_is_permited?(opts)
10
+ case WorkInProgress.framework
11
+ when :rails
12
+ rails_content(&block)
13
+ end
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def rails_content(&block)
20
+ content_tag(:div, capture(&block), style: "background-color: #ccc;")
21
+ end
22
+
23
+ def user_is_permited?(opts={})
24
+ if defined?(current_user)
25
+ WorkInProgress.permited_users.include?(current_user.email)
26
+ elsif opts[:user]
27
+ WorkInProgress.permited_users.include?(opts[:user].email)
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ require "test_helper"
2
+
3
+ class InstallGeneratorTest < Rails::Generators::TestCase
4
+ tests WorkInProgress::Generators::InstallGenerator
5
+ destination File.expand_path("../../tmp", __FILE__)
6
+ setup :prepare_destination
7
+
8
+ test "Assert all files are properly created" do
9
+ run_generator
10
+ assert_file "config/initializers/work_in_progress.rb"
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require 'minitest/autorun'
2
+ require 'rails'
3
+
4
+ if ActiveSupport.respond_to?(:test_order)
5
+ ActiveSupport.test_order = :random
6
+ end
7
+
8
+ require "rails/generators/test_case"
9
+ require "generators/work_in_progress/install_generator"
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+ require 'work_in_progress'
3
+
4
+ class ViewHelpersTest < Minitest::Test
5
+ def setup
6
+ @object = Object.new
7
+ @object.extend(WorkInProgress::ViewHelpers)
8
+ end
9
+
10
+ def content
11
+ "<div style=\"background-color: #ccc;\">hello!</div>"
12
+ end
13
+
14
+ User = Struct.new(:email)
15
+
16
+ # Test Rails
17
+ def test_rails_for_all
18
+ WorkInProgress.setup do |config|
19
+ config.framework = :rails
20
+ end
21
+
22
+ assert_nil(@object.work_in_progress { "hello!" })
23
+ end
24
+
25
+ def test_rails_for_unpermitted_users
26
+ WorkInProgress.setup do |config|
27
+ config.framework = :rails
28
+ config.permited_users = ["permited@example.com"]
29
+ end
30
+
31
+ user = User.new("notpermited@example.com")
32
+ assert_nil(@object.work_in_progress(user: user) { "hello!" })
33
+ end
34
+
35
+ def test_rails_for_permitted_users
36
+ WorkInProgress.setup do |config|
37
+ config.framework = :rails
38
+ config.permited_users = ["permited@example.com"]
39
+ end
40
+
41
+ user = User.new("permited@example.com")
42
+ assert_equal(content, @object.work_in_progress(user: user) { "hello!" })
43
+ end
44
+
45
+ # Test other frameworks
46
+ def test_sinatra
47
+ WorkInProgress.setup do |config|
48
+ config.framework = :sinatra
49
+ end
50
+
51
+ assert_nil(@object.work_in_progress { "hello!" })
52
+ end
53
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'work_in_progress/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "work_in_progress"
8
+ spec.version = WorkInProgress::VERSION
9
+ spec.authors = ["Michał Krajewski"]
10
+ spec.email = ["contact@mkrajewski.net"]
11
+ spec.summary = %q{Work in Progress.}
12
+ spec.description = %q{Gem that helps you hide and show work in progress.}
13
+ spec.homepage = ""
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: work_in_progress
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michał Krajewski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-11 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: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Gem that helps you hide and show work in progress.
42
+ email:
43
+ - contact@mkrajewski.net
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/generators/templates/work_in_progress.rb
54
+ - lib/generators/work_in_progress/install_generator.rb
55
+ - lib/work_in_progress.rb
56
+ - lib/work_in_progress/railtie.rb
57
+ - lib/work_in_progress/version.rb
58
+ - lib/work_in_progress/view_helpers.rb
59
+ - test/generators/install_generator_test.rb
60
+ - test/test_helper.rb
61
+ - test/view_helpers_test.rb
62
+ - work_in_progress.gemspec
63
+ homepage: ''
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Work in Progress.
87
+ test_files:
88
+ - test/generators/install_generator_test.rb
89
+ - test/test_helper.rb
90
+ - test/view_helpers_test.rb