rails_blocks 0.5.4.pre.alpha.pre.2
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 +15 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +10 -0
- data/Guardfile +43 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +12 -0
- data/app/assets/javascripts/block.coffee +98 -0
- data/app/assets/javascripts/jblocks.coffee +95 -0
- data/app/assets/javascripts/jquery_bem.coffee +4 -0
- data/app/assets/javascripts/jquery_bem_copy.coffee +486 -0
- data/app/assets/javascripts/main.coffee +10 -0
- data/app/assets/javascripts/rails_blocks.js +5 -0
- data/app/assets/stylesheets/rails_blocks.sass +94 -0
- data/app/helpers/block_helper.rb +122 -0
- data/app/views/rails_blocks/element.slim +2 -0
- data/coffeelint.json +12 -0
- data/config/spring.rb +1 -0
- data/config.ru +7 -0
- data/lib/rails_blocks/blocks/block.rb +28 -0
- data/lib/rails_blocks/blocks/element.rb +6 -0
- data/lib/rails_blocks/blocks/renderer.rb +13 -0
- data/lib/rails_blocks/configuration.rb +27 -0
- data/lib/rails_blocks/engine.rb +29 -0
- data/lib/rails_blocks/exceptions.rb +4 -0
- data/lib/rails_blocks/initializers/rails_blocks.rb +0 -0
- data/lib/rails_blocks/levels.rb +7 -0
- data/lib/rails_blocks/names.rb +60 -0
- data/lib/rails_blocks/path.rb +108 -0
- data/lib/rails_blocks/version.rb +3 -0
- data/lib/rails_blocks.rb +24 -0
- data/lib/tasks/rails_blocks.rake +8 -0
- data/rails_blocks.gemspec +39 -0
- data/spec/helpers/block_helper_spec.rb +58 -0
- data/spec/internal/app/blocks/app/block3/_mod1.slim +0 -0
- data/spec/internal/app/blocks/app/block3/_mod2_value2.slim +0 -0
- data/spec/internal/app/blocks/app/block3/block3.slim +0 -0
- data/spec/internal/app/blocks/common/block1/_mod1.slim +0 -0
- data/spec/internal/app/blocks/common/block1/_mod2_value2.slim +0 -0
- data/spec/internal/app/blocks/common/block1/block1.slim +2 -0
- data/spec/internal/app/blocks/common/block2/__elem1.slim +0 -0
- data/spec/internal/app/blocks/common/block2/__elem1_mod1.slim +0 -0
- data/spec/internal/app/blocks/common/block2/__elem1_mod2_val2.slim +0 -0
- data/spec/internal/app/blocks/common/block2/block2.slim +0 -0
- data/spec/internal/app/blocks/common/block3/_mod1.slim +0 -0
- data/spec/internal/app/blocks/common/block3/_mod2_value2.slim +0 -0
- data/spec/internal/app/blocks/common/block3/block3.slim +0 -0
- data/spec/internal/app/controllers/admin/admin_test_controller.rb +2 -0
- data/spec/internal/app/controllers/admin_controller.rb +2 -0
- data/spec/internal/app/controllers/application_controller.rb +2 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/initializers/rails_blocks.rb +7 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/schema.rb +3 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/log/test.log +8 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/rails_blocks/blocks/block_spec.rb +11 -0
- data/spec/rails_blocks/configuration_spec.rb +29 -0
- data/spec/rails_blocks/names_spec.rb +66 -0
- data/spec/rails_blocks/path_spec.rb +70 -0
- data/spec/rails_blocks_spec.rb +104 -0
- data/spec/spec_helper.rb +112 -0
- metadata +368 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NThlOTJmNjMwMTEzYTJkODkwOWE0YzlhYjllMjkwNGFkNTU5YmQ2ZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzcwOTQxYzQ0ZTZhODExM2RjZDJmN2U3ZTE4YThmZGU3MTg3NmU3YQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGI5MmE4NTRjYTZiNTRjNjI5NDM0ZGYyMz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aW+VJwYmlNDt7m/H66zM0/IDlOp/e86/JnnNNs3aNfL1pDuPooos6dSNKWo2m0C4gu2yr2Xy+Ijz/nw+UMXTianrSDYUwa578Xu3k0d1Pnp7jWBWR7KUz2Wvv0tKQHHCkSU2cjArcZ7nxkVw5kKBEX9+6dp9CoREridrsVnL/9BU=
|
8
|
+
gem: rails_blocks
|
9
|
+
on:
|
10
|
+
repo: Sickphilosopher/rails_blocks
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: "rspec" do
|
28
|
+
# watch /lib/ files
|
29
|
+
watch(%r{^lib/(.+).rb$}) do |m|
|
30
|
+
puts m[1]
|
31
|
+
"spec/#{m[1]}_spec.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
watch(%r{^app/(.+).rb$}) do |m|
|
35
|
+
puts m[1]
|
36
|
+
"spec/#{m[1]}_spec.rb"
|
37
|
+
end
|
38
|
+
|
39
|
+
# watch /spec/ files
|
40
|
+
watch(%r{^spec/(.+).rb$}) do |m|
|
41
|
+
"spec/#{m[1]}.rb"
|
42
|
+
end
|
43
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Andrey Potetiurin
|
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
|
+
# RailsBlocks
|
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 'rails_blocks'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rails_blocks
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/sickphilosopher/rails_blocks/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,12 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'documentation']
|
8
|
+
end
|
9
|
+
|
10
|
+
Bundler::GemHelper.install_tasks
|
11
|
+
|
12
|
+
task :default => :spec
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class window.Block
|
2
|
+
constructor: ($b, options) ->
|
3
|
+
@$node = $b
|
4
|
+
@name = $$.getBlockName($b)
|
5
|
+
@$node.b_name = @name
|
6
|
+
@id = $$.guid()
|
7
|
+
@params = $.extend({}, $b.data('bem'), options)
|
8
|
+
#$.extend this, decl.methods
|
9
|
+
@_addEvents() if @events
|
10
|
+
# if @elements
|
11
|
+
# for element in @elements
|
12
|
+
# @_addEvents(element)
|
13
|
+
@init() if @init
|
14
|
+
|
15
|
+
elem: (e_name, mod_name, mod_value, context) ->
|
16
|
+
klass = ".b-#{@name}__#{e_name}"
|
17
|
+
$elem = $(klass, context || @$node)
|
18
|
+
if mod_name
|
19
|
+
$elem = $elem.filter("#{klass}--#{$$.makeMod(mod_name, mod_value)}")
|
20
|
+
|
21
|
+
$elem.e_name = e_name
|
22
|
+
$elem.b_name = @name
|
23
|
+
$elem
|
24
|
+
|
25
|
+
|
26
|
+
_addEvents: (element)->
|
27
|
+
for event_name, handler of @events
|
28
|
+
p = event_name.split(' ')
|
29
|
+
if typeof handler == 'string'
|
30
|
+
handler = decl.methods[handler]
|
31
|
+
@$node.on p[0], p[1], handler.bind(@)
|
32
|
+
|
33
|
+
_trigger: (event) ->
|
34
|
+
@$node.trigger event
|
35
|
+
|
36
|
+
addElem: (e_name, o, $parent) ->
|
37
|
+
o ||= {}
|
38
|
+
$elem = $$.makeElement($parent || @$node, @name, e_name, o)
|
39
|
+
$elem.e_name = e_name
|
40
|
+
$elem.b_name = @name
|
41
|
+
$elem
|
42
|
+
|
43
|
+
addMod: (mod, value) ->
|
44
|
+
@$node.addMod(mod, value)
|
45
|
+
|
46
|
+
delMod: (mod, value) ->
|
47
|
+
@$node.delMod(mod, value)
|
48
|
+
|
49
|
+
toggleMod: (mod, value) ->
|
50
|
+
if @hasMod(mod, value)
|
51
|
+
@$node.delMod(mod, value)
|
52
|
+
else
|
53
|
+
@$node.addMod(mod, value)
|
54
|
+
|
55
|
+
hasMod: (mod, value) ->
|
56
|
+
mod = $$.makeMod(mod, value)
|
57
|
+
@$node.hasClass("b-#{@name}--#{mod}")
|
58
|
+
|
59
|
+
# class window.Block
|
60
|
+
# constructor: ($b) ->
|
61
|
+
# name = $b.getBlockName()
|
62
|
+
# params = $b.data('bem')
|
63
|
+
# decl = RB.decls[name]
|
64
|
+
# if !decl
|
65
|
+
# throw new Error(name + ' block is not declared')
|
66
|
+
# @name = name
|
67
|
+
# @params = params
|
68
|
+
# @$node = $b
|
69
|
+
# @id = $$.guid()
|
70
|
+
#
|
71
|
+
# $.extend this, decl.methods
|
72
|
+
# @_addEvents()
|
73
|
+
# @_setInited()
|
74
|
+
# @_trigger 'b-inited'
|
75
|
+
# return
|
76
|
+
#
|
77
|
+
# _addEvents: ->
|
78
|
+
# decl = $$.decls[@name]
|
79
|
+
# events = decl.events
|
80
|
+
# for e of events
|
81
|
+
# if events.hasOwnProperty(e)
|
82
|
+
# p = e.split(' ')
|
83
|
+
# handler = events[e]
|
84
|
+
# if typeof handler == 'string'
|
85
|
+
# handler = decl.methods[handler]
|
86
|
+
# @$node.on p[0], p[1], handler.bind(@)
|
87
|
+
#
|
88
|
+
# _setInited:->
|
89
|
+
#
|
90
|
+
# setMod: (mod, value) ->
|
91
|
+
#
|
92
|
+
# _trigger: (event) ->
|
93
|
+
# @$node.trigger event
|
94
|
+
#
|
95
|
+
# destroy: ->
|
96
|
+
# $$.cache[@id] = null
|
97
|
+
# @$node.off()
|
98
|
+
# @_trigger 'b-destroyed'
|
@@ -0,0 +1,95 @@
|
|
1
|
+
camelCase = (input) ->
|
2
|
+
input.toLowerCase().replace /(^|-)(.)/g, (match, $1, $2) ->
|
3
|
+
$2.toUpperCase()
|
4
|
+
|
5
|
+
window.$$ =
|
6
|
+
decls: {}
|
7
|
+
cache: {}
|
8
|
+
utils: {}
|
9
|
+
_id: 0
|
10
|
+
bem_class: 'js_bem'
|
11
|
+
bem_class_selector: '.js_bem'
|
12
|
+
guid: () ->
|
13
|
+
return @_id++
|
14
|
+
|
15
|
+
processOptions: ($dom, b_name, o) ->
|
16
|
+
if o.attrs
|
17
|
+
for attr, attr_value of o.attrs
|
18
|
+
$dom.prop(attr, attr_value)
|
19
|
+
if o.content
|
20
|
+
$dom.html(o.content)
|
21
|
+
if o.mix
|
22
|
+
$dom.addClass($$.mixClass(o.mix))
|
23
|
+
if o.elements
|
24
|
+
for e_name, e_o of o.elements
|
25
|
+
$$.makeElement($dom, b_name, e_name, e_o)
|
26
|
+
|
27
|
+
makeElement: ($parent, b_name, e_name, o) ->
|
28
|
+
tag = o.tag || 'div'
|
29
|
+
$e = $("<#{tag} class='b-#{b_name}__#{e_name}'>")
|
30
|
+
$$.processOptions($e, b_name, o)
|
31
|
+
if o.prepend
|
32
|
+
$parent.prepend $e
|
33
|
+
else
|
34
|
+
$parent.append $e
|
35
|
+
$e
|
36
|
+
|
37
|
+
makeBlock: (b_name, o) ->
|
38
|
+
o ||= {}
|
39
|
+
tag = o.tag || 'div'
|
40
|
+
$b = $("<#{tag} class='b-#{b_name}'>")
|
41
|
+
$$.processOptions($b, b_name, o)
|
42
|
+
$b
|
43
|
+
|
44
|
+
init: ($context) ->
|
45
|
+
$$.getBlocks($context.find($$.bem_class_selector))
|
46
|
+
$$.getBlocks($context) if $context.hasClass $$.bem_class
|
47
|
+
|
48
|
+
getBlocks: ($context, options) ->
|
49
|
+
$context.map ->
|
50
|
+
$$.getBlock($(this), options)
|
51
|
+
|
52
|
+
getBlock: ($b, options)->
|
53
|
+
bid = $b.data('_bid')
|
54
|
+
if bid
|
55
|
+
return $$.cache[bid]
|
56
|
+
block = new $$.decls[camelCase($$.getBlockName($b))]($b, options)
|
57
|
+
bid = block.id
|
58
|
+
$b.data '_bid', bid
|
59
|
+
$$.cache[bid] = block
|
60
|
+
block
|
61
|
+
|
62
|
+
getBlockName: ($b) ->
|
63
|
+
regexp = /^b(-[a-zA-Z0-9]+)+$/
|
64
|
+
for klass in $b.attr('class').split(/\s+/)
|
65
|
+
return klass.replace('b-', '') if regexp.test(klass)
|
66
|
+
|
67
|
+
makeMod: (name, value) ->
|
68
|
+
mod = name
|
69
|
+
mod += "_#{value}" if value
|
70
|
+
mod
|
71
|
+
|
72
|
+
mixClass: (mix) ->
|
73
|
+
"b-#{mix.b}__#{mix.e}"
|
74
|
+
|
75
|
+
$.fn.destroyBlocks = ->
|
76
|
+
@find($$.bem_class_selector).getBlocks().each ->
|
77
|
+
@destroy()
|
78
|
+
|
79
|
+
$.fn.addMod = (name, value) ->
|
80
|
+
mod = $$.makeMod(name, value)
|
81
|
+
if @e_name
|
82
|
+
@addClass("b-#{@b_name}__#{@e_name}--#{mod}")
|
83
|
+
else
|
84
|
+
@addClass("b-#{@b_name}--#{mod}")
|
85
|
+
|
86
|
+
$.fn.delMod = (name, value) ->
|
87
|
+
mod = $$.makeMod(name, value)
|
88
|
+
if @e_name
|
89
|
+
@removeClass("b-#{@b_name}__#{@e_name}--#{mod}")
|
90
|
+
else
|
91
|
+
@removeClass("b-#{@b_name}--#{mod}")
|
92
|
+
|
93
|
+
$.fn.asBlock = (name, o) ->
|
94
|
+
@addClass("b-#{name}")
|
95
|
+
$$.getBlock(@, o)
|