cosme 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: 5c0a868eae57159db0661c677f25c4ad43a3060f
4
+ data.tar.gz: 2c13fd13c5c6e8d580d08413552f7dc3acaf8a20
5
+ SHA512:
6
+ metadata.gz: b05cd5de35d6efecc32da9c1f41507433475e579efd7d2fd724c52ad981b8239ebdbeb9617c1160eaf313254ffde731e57f2152cf939a4ec57ce2cc3b852cc4b
7
+ data.tar.gz: 28219543ff89679d31340d03d04d482870bf1d719c1f5628eb1b7c30aa2c6fb780c1e0f6d3967fe93dbaeec23daa52a50ebbe1c52d67f5368b7fb0862cf5ea2f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cosme.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 YOSHIDA Hiroki
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,98 @@
1
+ # Cosme
2
+
3
+ [![Build Status](https://img.shields.io/travis/appirits/cosme.svg?style=flat-square)](http://travis-ci.org/appirits/cosme)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/appirits/cosme.svg?style=flat-square)](https://codeclimate.com/github/appirits/cosme)
5
+ [![Dependency Status](https://img.shields.io/gemnasium/appirits/cosme.svg?style=flat-square)](https://gemnasium.com/appirits/cosme)
6
+ [![Gem Version](https://img.shields.io/gem/v/cosme.svg?style=flat-square)](https://rubygems.org/gems/cosme)
7
+
8
+ Cosme is a simple solution to customize views of any template engine in your Ruby on Rails application.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'cosme'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install cosme
25
+
26
+ ## Usage
27
+
28
+ 1. Require a script in your `app/assets/javascripts/application.coffee`:
29
+
30
+ ```coffee
31
+ #= require cosme
32
+ ```
33
+
34
+ 2. Use the helper method in your views.
35
+
36
+ ```erb
37
+ <%= cosmeticize %>
38
+ ```
39
+
40
+ 3. Create a cosmetic file into `app/cosmetics`.
41
+
42
+
43
+ ## Example
44
+
45
+ Inserts html to all elements of .example:
46
+
47
+ ```ruby
48
+ # app/cosmetics/after_example.rb
49
+ Cosme.define(
50
+ target: '.example',
51
+ action: :after
52
+ )
53
+ ```
54
+
55
+ ```erb
56
+ <%# app/cosmetics/after_example.html.erb %>
57
+ <h2>After Example</h2>
58
+ ```
59
+
60
+ ```erb
61
+ <%# app/views/layouts/application.html.erb %>
62
+ <html>
63
+ <head>
64
+ <title>Example</title>
65
+ <%= stylesheet_link_tag 'application', media: 'all' %>
66
+ <%= javascript_include_tag 'application'%>
67
+ </head>
68
+ <body>
69
+ <%= cosmeticize %>
70
+ <div class="example">
71
+ <h1>Example</h1>
72
+ </div>
73
+ </body>
74
+ </html>
75
+ ```
76
+
77
+ The result of the above:
78
+
79
+ ```html
80
+ <div class="example">
81
+ <h1>Example</h1>
82
+ </div>
83
+ <h2>After Example</h2>
84
+ ```
85
+
86
+ ## Development
87
+
88
+ 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.
89
+
90
+ 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).
91
+
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on GitHub at https://github.com/appirits/cosme.
95
+
96
+ ## License
97
+
98
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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
@@ -0,0 +1,29 @@
1
+ $( ->
2
+ new Cosme
3
+ )
4
+
5
+ class Cosme
6
+ constructor: ->
7
+ _this = @
8
+ $('.cosmetic').each( ->
9
+ _this.create($(this))
10
+ )
11
+
12
+ create: ($cosmetic) ->
13
+ content = $cosmetic.data('content')
14
+ return false if content.length <= 0
15
+
16
+ target = $cosmetic.data('target')
17
+ $target = $(target)
18
+ return false if $target.length <= 0
19
+
20
+ action = $cosmetic.data('action')
21
+ switch action
22
+ when 'before'
23
+ $target.before(content)
24
+ when 'after'
25
+ $target.after(content)
26
+ when 'replace'
27
+ $target.html(content)
28
+ else
29
+ false
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'cosme'
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/cosme.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cosme/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cosme'
8
+ spec.version = Cosme::VERSION
9
+ spec.authors = ['YOSHIDA Hiroki']
10
+ spec.email = ['hyoshida@appirits.com']
11
+
12
+ spec.summary = 'A simple solution to customize views in your Ruby on Rails application.'
13
+ spec.description = 'Cosme is a simple solution to customize views of any template engine in your Ruby on Rails application.'
14
+ spec.homepage = 'https://github.com/appirits/cosme#cosme'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'actionview', '>= 4.0.0', '< 5'
23
+ spec.add_dependency 'coffee-rails', '>= 3.2.2', '< 4.2'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.10'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'minitest'
28
+ end
@@ -0,0 +1,13 @@
1
+ module Cosme
2
+ class Engine < ::Rails::Engine
3
+ config.to_prepare do
4
+ Dir.glob(Rails.root.join('app/cosmetics/**/*.rb')).each do |c|
5
+ require_dependency(c)
6
+ end
7
+ end
8
+
9
+ ActiveSupport.on_load(:action_view) do
10
+ ActionView::Base.send(:include, Cosme::Helpers)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module Cosme
2
+ module Helpers
3
+ def cosmeticize
4
+ Cosme.all.map do |cosmetic|
5
+ content = cosmetic[:render] ? render(cosmetic[:render]) : render
6
+ content_tag(:div, nil, class: 'cosmetic', data: cosmetic.except(:render).merge(content: content))
7
+ end.join.html_safe
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Cosme
2
+ VERSION = '0.1.0'
3
+ end
data/lib/cosme.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'action_view'
2
+ require 'coffee-rails'
3
+
4
+ require 'cosme/version'
5
+ require 'cosme/helpers'
6
+ require 'cosme/engine'
7
+
8
+ module Cosme
9
+ class << self
10
+ def define(cosmetic)
11
+ caller_path = caller_locations(1, 1)[0].path
12
+
13
+ render_options = cosmetic[:render] || {}
14
+ render_options[:file] ||= default_file_path_for(caller_path) if render_options
15
+ cosmetic[:render] = render_options
16
+
17
+ @cosmetics ||= {}
18
+ @cosmetics[caller_path] = cosmetic
19
+ end
20
+
21
+ def default_file_path_for(caller_path)
22
+ File.join(File.dirname(caller_path), File.basename(caller_path, '.*'))
23
+ end
24
+
25
+ def all
26
+ return [] unless @cosmetics
27
+ @cosmetics.values
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cosme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - YOSHIDA Hiroki
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-29 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.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: coffee-rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.2.2
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '4.2'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.2.2
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '4.2'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.10'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.10'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '10.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '10.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: minitest
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ description: Cosme is a simple solution to customize views of any template engine
96
+ in your Ruby on Rails application.
97
+ email:
98
+ - hyoshida@appirits.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".travis.yml"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - app/assets/javascripts/cosme.coffee
110
+ - bin/console
111
+ - bin/setup
112
+ - cosme.gemspec
113
+ - lib/cosme.rb
114
+ - lib/cosme/engine.rb
115
+ - lib/cosme/helpers.rb
116
+ - lib/cosme/version.rb
117
+ homepage: https://github.com/appirits/cosme#cosme
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.5
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: A simple solution to customize views in your Ruby on Rails application.
141
+ test_files: []