html_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,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in html_blocks.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sergey Kucher
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,44 @@
1
+ # HtmlBlocks
2
+
3
+ Generator for creating html-blocks functionality. So you can create blocks of html-code
4
+ and use them in head or body of html-page. Works only with playmo gem.
5
+ Controller and views will be created only on russian.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'html_blocks'
12
+
13
+ And execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install html_blocks
20
+
21
+ ## Usage
22
+
23
+ First generate scaffold:
24
+
25
+ rails generate html_blocks NAME --ru --playmo
26
+
27
+ Then execute database migration:
28
+
29
+ rake db:migrate
30
+
31
+ Now you can include blocks in head or body of html-pages by using helpers:
32
+
33
+ <name>_head_blocks
34
+ <name>_body_blocks
35
+
36
+ Done.
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'html_blocks/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "html_blocks"
8
+ gem.version = HtmlBlocks::VERSION
9
+ gem.authors = ["Sergey Kucher"]
10
+ gem.email = ["s.e.kucher@gmail.com"]
11
+ gem.description = <<eos
12
+ Generator for creating html-blocks functionality. So you can create blocks of html-code
13
+ and use them in head or body of html-page. Works only with playmo gem.
14
+ Controller and views generates only on russian.
15
+ eos
16
+ gem.summary = "Generator for adding blocks into html-pages"
17
+ gem.homepage = "https://github.com/sergey-kucher/html_blocks"
18
+
19
+ gem.files = `git ls-files`.split($/)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.require_paths = ["lib"]
23
+
24
+ gem.add_dependency 'rails'
25
+ end
@@ -0,0 +1,21 @@
1
+ Description:
2
+ Generator for creating html-blocks functionality. So you can create blocks of html-code
3
+ and use them in head or body of html-page. Works only with playmo gem.
4
+ Controller and views generates only on russian.
5
+
6
+ Examples:
7
+ rails generate html_blocks statistics
8
+
9
+ Model: app/models/statistic.rb
10
+ Migration: db/migrate/NOW_DATETIME_create_statistics.rb
11
+
12
+ Views:
13
+ app/views/statistics/_form.html.erb
14
+ app/views/statistics/new.html.erb
15
+ app/views/statistics/edit.html.erb
16
+ app/views/statistics/index.html.erb
17
+
18
+ Helper: app/helpers/statistics_helper.rb
19
+ Gem: truncate_html
20
+ Controller: app/controllers/statistics_controller.rb
21
+ Route: 'resource :statistics
@@ -0,0 +1,47 @@
1
+ class HtmlBlocksGenerator < Rails::Generators::NamedBase
2
+ include Rails::Generators::Migration
3
+
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ class_option :playmo, desc: 'To use playmo views', type: :boolean
7
+ class_option :ru, desc: 'To generate controller and views on russian', type: :boolean
8
+
9
+ def self.next_migration_number(path)
10
+ if ActiveRecord::Base.timestamped_migrations
11
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
12
+ else
13
+ "%.3d" % (current_migration_number(dirname) + 1)
14
+ end
15
+ end
16
+
17
+ def add_model
18
+ template 'model.rb', "app/models/#{singular_table_name}.rb"
19
+ end
20
+
21
+ def add_migration
22
+ migration_template 'migration.rb', "db/migrate/create_#{table_name}"
23
+ end
24
+
25
+ def add_views
26
+ if options.playmo? && options.ru?
27
+ %w{_form new edit index}.each do |name|
28
+ template "views-playmo-ru/#{name}.html.erb", "app/views/#{plural_file_name}/#{name}.html.erb"
29
+ end
30
+ gem "truncate_html"
31
+ #copy_file 'gray.css', 'app/assets/stylesheets/basic/gray.css'
32
+ end
33
+ end
34
+
35
+ def add_helper
36
+ template 'helper.rb', "app/helpers/#{plural_file_name}_helper.rb"
37
+ end
38
+
39
+ def add_controller
40
+ template 'controller.rb', "app/controllers/#{plural_file_name}_controller.rb" if options.ru?
41
+ end
42
+
43
+ def add_route
44
+ route "resources :#{plural_name}"
45
+ end
46
+
47
+ end
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ class <%= plural_name.camelize %>Controller < ApplicationController
4
+ before_filter :find_<%= singular_table_name %>, :except => [:index, :new, :create]
5
+ respond_to :html
6
+
7
+ def index
8
+ @<%= plural_name %> = <%= singular_table_name.camelize %>.all
9
+ respond_with(@<%= plural_name %>)
10
+ end
11
+
12
+ def new
13
+ @<%= singular_table_name %> = <%= singular_table_name.camelize %>.new
14
+ respond_with(@<%= singular_table_name %>)
15
+ end
16
+
17
+ def edit
18
+ respond_with(@<%= singular_table_name %>)
19
+ end
20
+
21
+ def create
22
+ @<%= singular_table_name %> = <%= singular_table_name.camelize %>.new(params[:<%= singular_table_name %>])
23
+
24
+ if @<%= singular_table_name %>.save
25
+ flash[:notice] = "Блок успешно добавлен."
26
+ redirect_to <%= plural_name %>_path
27
+ else
28
+ flash[:alert] = "При сохранении блока произошли ошибки."
29
+ render :new
30
+ end
31
+ end
32
+
33
+ def update
34
+ if @<%= singular_table_name %>.update_attributes(params[:<%= singular_table_name %>])
35
+ flash[:notice] = "Блок успешно обновлен."
36
+ redirect_to <%= plural_name %>_path
37
+ else
38
+ flash[:alert] = "При сохранении блока произошли ошибки."
39
+ render :edit
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ @<%= singular_table_name %>.destroy
45
+ redirect_to <%= plural_name %>_path
46
+ end
47
+
48
+ protected
49
+
50
+ def find_<%= singular_table_name %>
51
+ @<%= singular_table_name %> = <%= singular_table_name.camelize %>.find(params[:id])
52
+ end
53
+
54
+ end
@@ -0,0 +1,51 @@
1
+ a.clean-gray
2
+ {
3
+ background-image:-webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #eeeeee), color-stop(100%, #cccccc));
4
+ background-image:-webkit-linear-gradient(top, #eeeeee,#cccccc);
5
+ background-image:-moz-linear-gradient(top, #eeeeee,#cccccc);
6
+ background-image:-o-linear-gradient(top, #eeeeee,#cccccc);
7
+ background-image:-ms-linear-gradient(top, #eeeeee,#cccccc);
8
+ background-image:linear-gradient(top, #eeeeee,#cccccc);
9
+ display:-moz-inline-box;
10
+ -moz-box-orient:vertical;
11
+ display:inline-block;
12
+ vertical-align:middle;
13
+ *vertical-align:auto;border:1px solid #ccc;
14
+ border-bottom:1px solid #bbb;
15
+ -webkit-border-radius:3px;
16
+ -moz-border-radius:3px;
17
+ -ms-border-radius:3px;
18
+ -o-border-radius:3px;
19
+ border-radius:3px;
20
+ color:#333;
21
+ font:bold 100% "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
22
+ line-height:1;
23
+ padding:8px 20px;
24
+ text-align:center;
25
+ text-shadow:0 1px 0 #eee;
26
+ text-decoration:none
27
+ }
28
+ button.clean-gray,a.clean-gray
29
+ {
30
+ display:inline;
31
+ }
32
+ button.clean-gray:hover,a.clean-gray:hover{
33
+ background-image:-webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #dddddd), color-stop(100%, #bbbbbb));
34
+ background-image:-webkit-linear-gradient(top, #dddddd,#bbbbbb);
35
+ background-image:-moz-linear-gradient(top, #dddddd,#bbbbbb);
36
+ background-image:-o-linear-gradient(top, #dddddd,#bbbbbb);
37
+ background-image:-ms-linear-gradient(top, #dddddd,#bbbbbb);
38
+ background-image:linear-gradient(top, #dddddd,#bbbbbb);
39
+ border:1px solid #bbb;
40
+ border-bottom:1px solid #999;
41
+ cursor:pointer;
42
+ text-shadow:0 1px 0 #ddd;
43
+ }
44
+ button.clean-gray:active,a.clean-gray:active
45
+ {
46
+ border:1px solid #aaa;
47
+ border-bottom:1px solid #888;
48
+ -webkit-box-shadow:0 1px 0 0 #eee 0px 5px inset 0 0 5px 2px #aaa;
49
+ -moz-box-shadow:0 1px 0 0 #eee 0px 5px inset 0 0 5px 2px #aaa;
50
+ box-shadow:0 1px 0 0 #eee 0px 5px inset 0 0 5px 2px #aaa;
51
+ }
@@ -0,0 +1,24 @@
1
+ module <%= plural_name.camelize %>Helper
2
+
3
+ def <%= plural_name %>_head_block
4
+ @<%= plural_name %>_head_block ||= <%= plural_name %>_concat(<%= singular_table_name.camelize %>.head).html_safe
5
+ end
6
+
7
+ def <%= plural_name %>_body_block
8
+ @<%= plural_name %>_body_block ||= <%= plural_name %>_concat(<%= singular_table_name.camelize %>.body).html_safe
9
+ end
10
+
11
+ def <%= plural_name %>_short_desc(text, length=255, omission=' ...')
12
+ truncate_html(text, :length => length, :omission => omission)
13
+ end
14
+
15
+ private
16
+ def <%= plural_name %>_concat(<%= plural_name %>)
17
+ string = String.new
18
+ if <%= plural_name %>.present?
19
+ <%= plural_name %>.each {|s| string << s.block }
20
+ end
21
+ string
22
+ end
23
+
24
+ end
@@ -0,0 +1,11 @@
1
+ class Create<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :<%= table_name %> do |t|
4
+ t.string :name
5
+ t.text :block
6
+ t.boolean :in_body, :default => false
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ class <%= singular_table_name.camelize %> < ActiveRecord::Base
4
+ attr_accessible :name, :block, :in_body
5
+
6
+ validates :name, :presence => true, :length => { :maximum => 255 }
7
+ validates :block, :presence => true
8
+
9
+ scope :head, where(:in_body => false)
10
+ scope :body, where(:in_body => true)
11
+ end
@@ -0,0 +1,13 @@
1
+ <%%= simple_form_for(@<%= singular_table_name %>, :html => { :class => "playmo"}) do |f| %>
2
+ <%%= f.error_notification %>
3
+
4
+ <div class="form-inputs">
5
+ <%%= f.input :name %>
6
+ <%%= f.input :block %>
7
+ <%%= f.input :in_body %>
8
+ </div>
9
+
10
+ <div class="form-actions">
11
+ <%%= f.button :submit %>
12
+ </div>
13
+ <%% end %>
@@ -0,0 +1,10 @@
1
+ <%%= heading_with_title "Изменить html-блок" %>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= private_area true do %>
6
+ <ul>
7
+ <li><%%= link_to "Список html-блоков", <%= plural_name %>_path %></li>
8
+ <li><%%= link_to "Удалить", @<%= singular_table_name %>, confirm: 'Вы уверены?', method: :delete %></li>
9
+ </ul>
10
+ <%% end %>
@@ -0,0 +1,41 @@
1
+ <%%= heading_with_title "Html-блоки" %>
2
+
3
+ <%% if @<%= plural_name %>.any? %>
4
+
5
+ <table class="zebra">
6
+ <thead>
7
+ <tr>
8
+ <th>#</th>
9
+ <th>Название</th>
10
+ <th>Действия</th>
11
+
12
+ </tr>
13
+ </thead>
14
+ <tfoot>
15
+ <tr>
16
+ <td>&nbsp;</td>
17
+ <td></td>
18
+ <td></td>
19
+ </tr>
20
+ </tfoot>
21
+
22
+ <tbody>
23
+ <%% @<%= plural_name %>.each do |s| %>
24
+ <tr>
25
+ <td><%%= @<%= plural_name %>.index(s) + 1 %></td>
26
+ <td><%%= <%= plural_name %>_short_desc(s.name, 32) %></td>
27
+ <td>
28
+ <%%= link_to('Изменить', edit_<%= singular_table_name %>_path(s), :class => 'clean-gray') %>
29
+ </td>
30
+ </tr>
31
+ <%% end %>
32
+ </tbody>
33
+ </table>
34
+
35
+ <%% end %>
36
+
37
+ <%%= private_area true do %>
38
+ <ul>
39
+ <li><%%= link_to 'Новый html-блок', new_<%= singular_table_name %>_path %></li>
40
+ </ul>
41
+ <%% end %>
@@ -0,0 +1,9 @@
1
+ <%%= heading_with_title "Добавить html-блок" %>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= private_area true do %>
6
+ <ul>
7
+ <li><%%= link_to 'Список html-блоков', <%= plural_name %>_path %></li>
8
+ </ul>
9
+ <%% end %>
@@ -0,0 +1,5 @@
1
+ require "html_blocks/version"
2
+
3
+ module HtmlBlocks
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module HtmlBlocks
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html_blocks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sergey Kucher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: ! 'Generator for creating html-blocks functionality. So you can create
31
+ blocks of html-code
32
+
33
+ and use them in head or body of html-page. Works only with playmo gem.
34
+
35
+ Controller and views generates only on russian.
36
+
37
+ '
38
+ email:
39
+ - s.e.kucher@gmail.com
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - html_blocks.gemspec
50
+ - lib/generators/USAGE
51
+ - lib/generators/html_blocks_generator.rb
52
+ - lib/generators/templates/controller.rb
53
+ - lib/generators/templates/gray.css
54
+ - lib/generators/templates/helper.rb
55
+ - lib/generators/templates/migration.rb
56
+ - lib/generators/templates/model.rb
57
+ - lib/generators/templates/views-playmo-ru/_form.html.erb
58
+ - lib/generators/templates/views-playmo-ru/edit.html.erb
59
+ - lib/generators/templates/views-playmo-ru/index.html.erb
60
+ - lib/generators/templates/views-playmo-ru/new.html.erb
61
+ - lib/html_blocks.rb
62
+ - lib/html_blocks/version.rb
63
+ homepage: https://github.com/sergey-kucher/html_blocks
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ segments:
76
+ - 0
77
+ hash: -4103007830998498639
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ segments:
85
+ - 0
86
+ hash: -4103007830998498639
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.25
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Generator for adding blocks into html-pages
93
+ test_files: []