assets_helper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p448@assets_helper"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.23.12 (stable)" # 1.10.1 seems like a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
+ do
28
+ if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
+ then \. "${__hook}" || true
30
+ fi
31
+ done
32
+ unset __hook
33
+ if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
34
+ then
35
+ if [[ $- == *i* ]] # check for interactive shells
36
+ then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
37
+ " # show the user the ruby and gemset they are using in green
38
+ else printf "%b" "Using: $GEM_HOME
39
+ " # don't use colors in non-interactive shells
40
+ fi
41
+ fi
42
+ else
43
+ # If the environment file has not yet been created, use the RVM CLI to select.
44
+ rvm --create "$environment_id" || {
45
+ echo "Failed to create RVM environment '${environment_id}'."
46
+ return 1
47
+ }
48
+ fi
49
+
50
+ # If you use bundler, this might be useful to you:
51
+ # if [[ -s Gemfile ]] && {
52
+ # ! builtin command -v bundle >/dev/null ||
53
+ # builtin command -v bundle | GREP_OPTIONS="" \grep $rvm_path/bin/bundle >/dev/null
54
+ # }
55
+ # then
56
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
57
+ # gem install bundler
58
+ # fi
59
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
60
+ # then
61
+ # bundle install | GREP_OPTIONS="" \grep -vE '^Using|Your bundle is complete'
62
+ # fi
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AssetsHelper
2
2
 
3
- TODO: Write a gem description
3
+ assets helper is the helper that use to include css and javascript by controller name automatically, it mean that it include only css and javascript file in the controller that you are standing.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,12 +18,27 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Step1: Add before_filter :include_css, :include_javascript in application_controller.rb
22
22
 
23
- ## Contributing
23
+ class ApplicationController < ActionController::Base
24
+ protect_from_forgery
24
25
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
26
+ before_filter :include_css, :include_javascript
27
+ end
28
+
29
+ Step2: Add = yield :asset in your layout file (example: application.html.haml)
30
+
31
+ !!!
32
+ %html
33
+ %head
34
+ %title JongEat
35
+ = stylesheet_link_tag "application", :media => "all"
36
+ = javascript_include_tag "application"
37
+ = yield :asset
38
+ = csrf_meta_tags
39
+
40
+ Step3: If you create a controller name: homes, so go to app/assets/javascripts create a folder name: homes (app/assets/javascripts/homes) and go to app/assets/css create a folder name homes (app/assets/css/homes). And input javascripts files and css files that you use in homes controllers.
41
+
42
+ So when you go to the Browser and type http://localhost:3000/homes it include only javascripts files and css files that you use for homes controller.
43
+
44
+ For any question pls email me: bunlong.van@gmail.com
@@ -20,5 +20,4 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "content_for_in_controllers"
24
23
  end
@@ -1,6 +1,28 @@
1
1
  require "assets_helper/version"
2
2
 
3
3
  module AssetsHelper
4
+
5
+ def view_context
6
+ super.tap do |view|
7
+ (@_content_for || {}).each do |name,content|
8
+ view.content_for name, content
9
+ end
10
+ end
11
+ end
12
+
13
+ def content_for(name, content)
14
+ @_content_for ||= {}
15
+ if @_content_for[name].respond_to?(:<<)
16
+ @_content_for[name] << content
17
+ else
18
+ @_content_for[name] = content
19
+ end
20
+ end
21
+
22
+ def content_for?(name)
23
+ @_content_for[name].present?
24
+ end
25
+
4
26
  def include_css
5
27
  files = Dir.entries("app/assets/stylesheets/#{params[:controller]}")
6
28
 
@@ -22,6 +44,7 @@ module AssetsHelper
22
44
  end
23
45
  end
24
46
  end
47
+
25
48
  end
26
49
 
27
50
  ActionController::Base.send :include, AssetsHelper
@@ -1,3 +1,3 @@
1
1
  module AssetsHelper
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assets_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-18 00:00:00.000000000 Z
12
+ date: 2013-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: content_for_in_controllers
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
46
  description: assets helper is the helper that use to include css and javascript by
63
47
  controller name automatically
64
48
  email:
@@ -68,6 +52,7 @@ extensions: []
68
52
  extra_rdoc_files: []
69
53
  files:
70
54
  - .gitignore
55
+ - .rvmrc
71
56
  - Gemfile
72
57
  - LICENSE.txt
73
58
  - README.md