kyubi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2c09a15e9feaa7d8c2f089c3680ed08b4fa2cf344d54b3e9fbdc4d48eb85ffcc
4
+ data.tar.gz: b8077cc28c47b078e65792977733876fd1732a16fd0ef250c393ec75aa9f339b
5
+ SHA512:
6
+ metadata.gz: 432e01a1e66392ea1c9155f783ee06ed67c72170a4483bbeca103dc66047f11bff8b9057ffd34c400e6f00183e62e15eba83878dbad2991cbb3e8d0b93f5db50
7
+ data.tar.gz: af8d84ba7ff10a2e949d90c1c5a16267146a5c54d83a68f579ae98a8a662aa4d26ff926a756171874149ad0ac55449c56271dbd0300867c1d0519394f410cfc2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 yiyenene
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,54 @@
1
+ # Kyubi
2
+ Supports settings of page specified assets load and precompile at Ruby on Rails.
3
+
4
+ ## Usage
5
+ In `config/application.rb`
6
+ ```ruby
7
+ require "kyubi/railtie"
8
+ ```
9
+
10
+ In `app/views/layout/application.html.erb`
11
+ ```
12
+ <%= kyubi_stylesheet_link_tag media: 'all' %>
13
+ <%= kyubi_javascript_include_tag 'data-turbolinks-track' => 'reload' %>
14
+ ```
15
+
16
+ ### Assets
17
+ Kyubi expects `app/assets/views` directory has same structures with `app/views` directory.
18
+ ```
19
+ app
20
+ +-- assets
21
+ +-- stylesheets
22
+ +-- javascripts
23
+ +-- views
24
+ +-- top
25
+ +-- shared.css
26
+ +-- index.css
27
+ +-- index.js
28
+ +-- views
29
+ +-- top
30
+ +-- index.html.erb
31
+ ```
32
+
33
+ when top/index view rendering, index.css and index.js are loaded by kyubi tag helper.
34
+ ※ `shared` is also loaded when execute same controller action.
35
+
36
+ ## Installation
37
+ Add this line to your application's Gemfile:
38
+
39
+ ```ruby
40
+ gem 'kyubi'
41
+ ```
42
+
43
+ And then execute:
44
+ ```bash
45
+ $ bundle
46
+ ```
47
+
48
+ Or install it yourself as:
49
+ ```bash
50
+ $ gem install kyubi
51
+ ```
52
+
53
+ ## License
54
+ 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,33 @@
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 = 'Kyubi'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
@@ -0,0 +1,36 @@
1
+ module Kyubi
2
+ module Catalog
3
+ class << self
4
+ def stylesheet_exist?(controller, action)
5
+ exist = @stylesheets[controller].include?(action)
6
+ return exist if exist || !Rails.env.development?
7
+ load # reload
8
+ @stylesheets[controller].include?(action)
9
+ end
10
+
11
+ def javascript_exist?(controller, action)
12
+ exist = @javascripts[controller].include?(action)
13
+ return exist if exist || !Rails.env.development?
14
+ load
15
+ @javascripts[controller].include?(action)
16
+ end
17
+
18
+ def load
19
+ @stylesheets = {}
20
+ @javascripts = {}
21
+ root = Rails.root.join(Rails.application.config.kyubi.asset_root)
22
+ Dir.glob("#{root}/*").each do |d|
23
+ dir_name = d.split("/").last
24
+ @stylesheets[dir_name] = []
25
+ @javascripts[dir_name] = []
26
+ Dir.entries(d).each do |f|
27
+ next if [".", ".."].include?(f)
28
+ file, ext = f.split(".") # TOOD: better method
29
+ @stylesheets[dir_name] << file if Rails.application.config.kyubi.stylesheet_ext.include?(ext)
30
+ @javascripts[dir_name] << file if Rails.application.config.kyubi.javascript_ext.include?(ext)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,26 @@
1
+ module Kyubi
2
+ class Railtie < Rails::Railtie
3
+ config.kyubi = ActiveSupport::OrderedOptions.new
4
+
5
+ config.kyubi.asset_root = "app/assets/views"
6
+
7
+ config.kyubi.stylesheet_ext = %w[css less sass scss]
8
+ config.kyubi.javascript_ext = %w[js coffee]
9
+
10
+ initializer :kyubi_append_assets_path, after: :append_assets_path do |app|
11
+ app.config.assets.paths += Dir.glob(Rails.root.join("#{app.config.kyubi.asset_root}/*"))
12
+ end
13
+
14
+ initializer :kyubi_append_precompile, after: :set_default_precompile do |app|
15
+ app.config.assets.precompile << ->(_path, file) { file.start_with?(Rails.root.join(app.config.kyubi.asset_root).to_s) }
16
+ end
17
+
18
+ config.after_initialize do |_app|
19
+ ActiveSupport.on_load(:action_view) do
20
+ include Kyubi::TagHelper
21
+ end
22
+
23
+ Kyubi::Catalog.load
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ module Kyubi
2
+ module TagHelper
3
+ extend ActiveSupport::Concern
4
+
5
+ def kyubi_stylesheet_link_tag(options = {})
6
+ sources = []
7
+ controller_name = options[:controller] || controller.controller_name
8
+ action_name = options[:action] || controller.action_name
9
+ sources << "#{controller_name}/shared" if Catalog.stylesheet_exist?(controller_name, "shared")
10
+ sources << "#{controller_name}/#{action_name}" if Catalog.stylesheet_exist?(controller_name, action_name)
11
+ return if sources.empty?
12
+
13
+ sources << options.except(:controller, :action)
14
+ stylesheet_link_tag(*sources)
15
+ end
16
+
17
+ def kyubi_javascript_include_tag(options = {})
18
+ sources = []
19
+ controller_name = options[:controller] || controller.controller_name
20
+ action_name = options[:action] || controller.action_name
21
+ sources << "#{controller_name}/shared" if Catalog.javascript_exist?(controller_name, "shared")
22
+ sources << "#{controller_name}/#{action_name}" if Catalog.javascript_exist?(controller_name, action_name)
23
+ return if sources.empty?
24
+
25
+ sources << options.except(:controller, :action)
26
+ javascript_include_tag(*sources)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Kyubi
2
+ VERSION = '0.1.0'
3
+ end
data/lib/kyubi.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "kyubi/catalog"
2
+ require "kyubi/tag_helper"
3
+
4
+ module Kyubi
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :kyubi do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kyubi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yiyenene
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-15 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.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: can load stylesheet and javascript file from assets/views folder that
42
+ have same structures with app/views folder.
43
+ email:
44
+ - goodbyeboredworld@aol.jp
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - lib/kyubi.rb
53
+ - lib/kyubi/catalog.rb
54
+ - lib/kyubi/railtie.rb
55
+ - lib/kyubi/tag_helper.rb
56
+ - lib/kyubi/version.rb
57
+ - lib/tasks/kyubi_tasks.rake
58
+ homepage: https://github.com/yiyenene/kyubi
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.7.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Supports settings of page specified assets load and precompile.
82
+ test_files: []