smart_blocks 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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smart_blocks.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ivan Teplyakov
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,72 @@
1
+ # SmartBlocks
2
+
3
+ Generators and helpers written by <i class='icon-provider-github'></i> [verybigman](https://github.com/verybigman)</i> for convenient views, css and js organization.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'smart_blocks'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install smart_blocks
18
+
19
+ Then add to css manifest (application.css):
20
+
21
+ *= require_tree ./_blocks
22
+
23
+ And to js manifest (application.js):
24
+
25
+ //= require_tree ./_blocks
26
+
27
+ ## Usage
28
+
29
+ #### Create block
30
+ ```
31
+ $ rails g smart_blocks:block header_main
32
+ # create -> app/views/_blocks/headers/_header_main.html.haml
33
+ # create -> app/assets/stylesheets/_blocks/headers/header_main.css.sass
34
+ # create -> app/assets/javascripts/_blocks/headers/header_main.js.coffee
35
+ ```
36
+
37
+ #### Create element (parts of block)
38
+
39
+ ```
40
+ $ rails g smart_blocks:element header_logged_in
41
+ # create -> app/views/_blocks/headers/elements/_header_logged_in.html.haml
42
+ # create -> app/assets/stylesheets/_blocks/headers/elements/header_logged_in.css.sass
43
+ # create -> app/assets/javascripts/_blocks/headers/elements/header_logged_in.js.coffee
44
+ ```
45
+
46
+ #### Views
47
+
48
+ (layout/application.html.haml):
49
+ ```
50
+ = block 'header_main'
51
+ ```
52
+ Show in this block elements depends on logged in user or not
53
+ ``` ruby
54
+ - if current_user
55
+ = element 'header_logged_in'
56
+ - else
57
+ = element 'header_guest'
58
+ ```
59
+
60
+ Also you can pass variables:
61
+ ``` ruby
62
+ = block 'menu_main', some_var: value
63
+ = element 'button_submit', other_var: value
64
+ ```
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Generate new block for views
3
+
4
+ Example:
5
+ rails generate block menu_footer
6
+
7
+ This will create:
8
+ views/_blocks/menus/_menu_footer.html.haml
9
+ stylesheets/_blocks/menus/_menu_footer.css.sass
10
+ javascripts/_blocks/menus/_menu_footer.js.coffee
@@ -0,0 +1,34 @@
1
+ module SmartBlocks
2
+ class BlockGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ class_option :no_js, type: :boolean, default: false, desc: 'Without coffee script file'
6
+ class_option :no_css, type: :boolean, default: false, desc: 'Without sass file'
7
+
8
+ def create_block_files
9
+ haml = 'app/views/_blocks/'
10
+ sass = 'app/assets/stylesheets/_blocks/'
11
+ coffee = 'app/assets/javascripts/_blocks/'
12
+
13
+ directory = file_name.split('_')[0].pluralize + '/'
14
+
15
+ block_haml_name = '_' + file_name + '.html.haml'
16
+
17
+ @css_class_name = "." + file_name.gsub('_', '-')
18
+
19
+ if File.exist?(haml + directory + block_haml_name)
20
+ puts "\e[0;31m Block with this name is already exists. Try 'thor blocks:list' or 'thor blocks:usage #{file_name}'\e[0m"
21
+ else
22
+ template "haml_template.tt", haml + directory + block_haml_name
23
+ unless options.no_css
24
+ block_sass_name = file_name + '.css.sass'
25
+ template "sass_template.tt", sass + directory + block_sass_name
26
+ end
27
+ unless options.no_js
28
+ block_coffee_name = file_name + '.js.coffee'
29
+ template "coffee_template.tt", coffee + directory + block_coffee_name
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ # CoffeeScript for block <%= file_name %>
2
+ # Example:
3
+ # $('<%= @css_class_name %>').click ->
4
+ # # Your script here
@@ -0,0 +1,7 @@
1
+ -# Block: Write description for this block here
2
+ -# Params:
3
+ -# param1 [string] - description and variants
4
+ -# param2 [string] - description and variants
5
+
6
+ <%= @css_class_name %>
7
+ -# Your block here
@@ -0,0 +1,2 @@
1
+ <%= @css_class_name %>
2
+ // Css for <%= file_name %> block here
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Generate new elements for blocks and views
3
+
4
+ Example:
5
+ rails generate element menu_link
6
+
7
+ This will create:
8
+ views/_blocks/menus/elements/_menu_link.html.haml
9
+ stylesheets/_blocks/menus/elements/_menu_link.css.sass
10
+ javascripts/_blocks/menus/elements/_menu_link.js.coffee
@@ -0,0 +1,30 @@
1
+ module SmartBlocks
2
+ class ElementGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ class_option :no_js, type: :boolean, default: false, desc: 'Without coffee script file'
6
+ class_option :no_css, type: :boolean, default: false, desc: 'Without sass file'
7
+
8
+ def create_element_files
9
+ haml = 'app/views/_blocks/'
10
+ sass = 'app/assets/stylesheets/_blocks/'
11
+ coffee = 'app/assets/javascripts/_blocks/'
12
+
13
+ directory = file_name.split('_')[0].pluralize + '/elements/'
14
+
15
+ block_haml_name = '_' + file_name + '.html.haml'
16
+
17
+ @css_class_name = "." + file_name.gsub('_', '-')
18
+
19
+ template "haml_template.tt", haml + directory + block_haml_name
20
+ unless options.no_css
21
+ block_sass_name = file_name + '.css.sass'
22
+ template "sass_template.tt", sass + directory + block_sass_name
23
+ end
24
+ unless options.no_js
25
+ block_coffee_name = file_name + '.js.coffee'
26
+ template "coffee_template.tt", coffee + directory + block_coffee_name
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ # CoffeeScript for element <%= file_name %>
2
+ # Example:
3
+ # $('<%= @css_class_name %>').click ->
4
+ # # Your script here
@@ -0,0 +1,7 @@
1
+ -# Element: Write description for this element here
2
+ -# Params:
3
+ -# param1 [string] - description and variants
4
+ -# param2 [string] - description and variants
5
+
6
+ <%= @css_class_name %>
7
+ -# Your element here
@@ -0,0 +1,2 @@
1
+ <%= @css_class_name %>
2
+ // Css for <%= file_name %> element here
data/lib/railtie.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'smart_blocks/view_helpers'
2
+
3
+ module SmartBlocks
4
+ class Railtie < Rails::Railtie
5
+ initializer "smart_blocks.view_helpers" do
6
+ ActionView::Base.send :include, SmartBlocks::ViewHelpers
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ require 'smart_blocks/version'
2
+ require 'smart_blocks/view_helpers'
3
+ require 'smart_blocks/railtie' if defined?(Rails)
4
+
5
+ module SmartBlocks
6
+ end
@@ -0,0 +1,7 @@
1
+ module SmartBlocks
2
+ class Railtie < Rails::Railtie
3
+ initializer "smart_blocks.view_helpers" do
4
+ ActionView::Base.send :include, SmartBlocks::ViewHelpers
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SmartBlocks
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ module SmartBlocks
2
+ module ViewHelpers
3
+ def block(block_name, options={})
4
+ render "_blocks/#{block_name.split('_')[0].pluralize}/#{block_name}", options
5
+ end
6
+ alias :b :block
7
+
8
+ def element(block_element_name, options={})
9
+ render "_blocks/#{block_element_name.split('_')[0].pluralize}/elements/#{block_element_name}", options
10
+ end
11
+ alias :e :element
12
+ end
13
+ 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 'smart_blocks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smart_blocks"
8
+ spec.version = SmartBlocks::VERSION
9
+ spec.authors = ["Ivan Teplyakov"]
10
+ spec.email = ["exreanimator@gmail.com"]
11
+ spec.description = %q{Useful concept for views, css and js organization}
12
+ spec.summary = %q{Useful concept for views, css and js organization}
13
+ spec.homepage = "https://github.com/ExReanimator/smart_blocks"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_blocks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ivan Teplyakov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Useful concept for views, css and js organization
47
+ email:
48
+ - exreanimator@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/generators/smart_blocks/block/USAGE
59
+ - lib/generators/smart_blocks/block/block_generator.rb
60
+ - lib/generators/smart_blocks/block/templates/coffee_template.tt
61
+ - lib/generators/smart_blocks/block/templates/haml_template.tt
62
+ - lib/generators/smart_blocks/block/templates/sass_template.tt
63
+ - lib/generators/smart_blocks/element/USAGE
64
+ - lib/generators/smart_blocks/element/element_generator.rb
65
+ - lib/generators/smart_blocks/element/templates/coffee_template.tt
66
+ - lib/generators/smart_blocks/element/templates/haml_template.tt
67
+ - lib/generators/smart_blocks/element/templates/sass_template.tt
68
+ - lib/railtie.rb
69
+ - lib/smart_blocks.rb
70
+ - lib/smart_blocks/railtie.rb
71
+ - lib/smart_blocks/version.rb
72
+ - lib/smart_blocks/view_helpers.rb
73
+ - smart_blocks.gemspec
74
+ homepage: https://github.com/ExReanimator/smart_blocks
75
+ licenses:
76
+ - MIT
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ segments:
88
+ - 0
89
+ hash: -4146651941715711040
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -4146651941715711040
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.25
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Useful concept for views, css and js organization
105
+ test_files: []