frendms-rails 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
+ SHA1:
3
+ metadata.gz: 7fa8eb3368bc807fbf368b087a7ccdcda1d616b9
4
+ data.tar.gz: 3c4723051cca5750cb487c9492e12f57df158b44
5
+ SHA512:
6
+ metadata.gz: 0e65eeec3ff6f68da76ba971ee77a25438d2a8d3e494845d582f5737c76bb662c419b5c34595ea0ff6168b640ec0afb55d651e362318a60cac12499f7341fc19
7
+ data.tar.gz: 2cc25abb35556c456b37be3e37c575624359554e85437a89a7ac0ace397006024fa15c4c07bafe3c0cdab5eabbfe8f93f4d6fcb5df3dfaaaed106e5406c3a7b9
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in frendms-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tyson Holub
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Frendms
2
+
3
+ The Rails Frond End Management System.
4
+
5
+ Use this gem to modify the front end of any website on the fly via ajax.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'frendms-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install frendms-rails
22
+
23
+ ## Usage
24
+
25
+ After installation execute:
26
+
27
+ $ rails g frendms
28
+
29
+ This will generate the migration for the elements table used to store element values. Use with Devise authentication to update front end elements on the fly via ajax. When logged in, any child elements of class "frender" with the class "frend" will be editable.
30
+
31
+ Add to the bottom of your layout file
32
+
33
+ ```ruby
34
+ <% if user_signed_in? %>
35
+ <script>
36
+ $(document).ready(function(){
37
+ $('.frend').addClass('enabled')
38
+ })
39
+ </script>
40
+ <% end %>
41
+ ```
42
+
43
+ Example of an editable layout:
44
+
45
+ ```html
46
+ <html>
47
+ <body>
48
+ <section class="frender" id="header">
49
+ <header class="frend">I'm an editable header</header>
50
+ </section>
51
+
52
+ <section class="frender" id="<%= "#{controller_name}-#{action_name}" %>">
53
+ <%= yield %> <!-- yield frend class elements per controller action -->
54
+ </section>
55
+
56
+ <section class="frender" id="footer">
57
+ <footer class="frend">I'm an editable footer</footer>
58
+ </section>
59
+ </body>
60
+
61
+ <% if user_signed_in? %>
62
+ <script>
63
+ $(document).ready(function(){
64
+ $('.frend').addClass('enabled')
65
+ })
66
+ </script>
67
+ <% end %>
68
+
69
+ </html>
70
+ ```
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/frendms-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
75
+
76
+
77
+ ## License
78
+
79
+ 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 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,47 @@
1
+ module Frendms
2
+ class ElementController < ::ApplicationController
3
+
4
+ def get_elements
5
+ e = Element.where('frender = ?', params[:frender])
6
+ respond_to do |format|
7
+ format.json { render :json => e.to_json(:only => [:elementId, :text]) }
8
+ end
9
+ end
10
+
11
+ def update_element
12
+ if user_signed_in?
13
+ e = Element.find_by(:elementId => params[:id], :frender => params[:frender])
14
+
15
+ if(params[:text].length > 0)
16
+ if e.nil?
17
+ e = Element.new
18
+ e.frender = params[:frender]
19
+ e.elementId = params[:id]
20
+ end
21
+ e.text = params[:text]
22
+ e.save
23
+
24
+ respond_to do |format|
25
+ format.json { render :json => e.to_json }
26
+ end
27
+ else
28
+ if not e.nil?
29
+ e.delete
30
+ respond_to do |format|
31
+ format.json { render :json => { 'resp' => "deleted element record for element id '#{params[:id]}'" } }
32
+ end
33
+ else
34
+ respond_to do |format|
35
+ format.json { render :json => { 'resp' => 'nothing to do' } }
36
+ end
37
+ end
38
+ end
39
+ else
40
+ respond_to do |format|
41
+ format.json { render :json => { 'error' => 'you must be logged in to commit changes' } }
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,4 @@
1
+ module Frendms
2
+ class Element < ActiveRecord::Base
3
+ end
4
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "frendms/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ get '/element/all' => 'frendms/element#get_elements'
3
+ put '/element/update' => 'frendms/element#update_element'
4
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: frendms-rails 0.1.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "frendms-rails"
6
+ s.version = "0.1.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ # s.metadata = { "allowed_push_host" => "TODO: Set to 'http://mygemserver.com'" } if s.respond_to? :metadata=
10
+ s.require_paths = ["lib"]
11
+ s.authors = ["Tyson Holub"]
12
+ s.bindir = "exe"
13
+ s.date = "2016-10-10"
14
+ s.description = "Click a html element to make it an editable textarea. Changes are saved to the database via ajax. When the page is loaded the changes will be injected into that element."
15
+ s.email = ["tyson@tysonholub.com"]
16
+ s.files = [".gitignore", ".travis.yml", "CODE_OF_CONDUCT.md", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "app/controllers/frendms/element_controller.rb", "app/models/frendms/element.rb", "bin/console", "bin/setup", "config/routes.rb", "frendms-rails.gemspec", "lib/frendms/rails.rb", "lib/frendms/rails/version.rb", "lib/generators/frendms/frendms_generator.rb", "lib/generators/frendms/templates/migration.rb", "vendor/assets/javascripts/dompath.js", "vendor/assets/javascripts/frendms.js", "vendor/assets/stylesheets/frendms.css"]
17
+ s.homepage = "http://frendms.tysonholub.com"
18
+ s.licenses = ["MIT"]
19
+ s.rubygems_version = "2.2.2"
20
+ s.summary = "The Front End Management System"
21
+
22
+ if s.respond_to? :specification_version then
23
+ s.specification_version = 4
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ s.add_development_dependency(%q<bundler>, ["~> 1.10"])
27
+ s.add_development_dependency(%q<rake>, ["~> 10.0"])
28
+ else
29
+ s.add_dependency(%q<bundler>, ["~> 1.10"])
30
+ s.add_dependency(%q<rake>, ["~> 10.0"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<bundler>, ["~> 1.10"])
34
+ s.add_dependency(%q<rake>, ["~> 10.0"])
35
+ end
36
+ end
@@ -0,0 +1,8 @@
1
+ require "frendms/rails/version"
2
+
3
+ module Frendms
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Frendms
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class FrendmsGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+ def self.source_root
7
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
8
+ end
9
+
10
+ def self.next_migration_number(dirname)
11
+ if ActiveRecord::Base.timestamped_migrations
12
+ Time.new.utc.strftime("%Y%m%d%H%M%S")
13
+ else
14
+ "%.3d" % (current_migration_number(dirname) + 1)
15
+ end
16
+ end
17
+
18
+ def create_migration_file
19
+ migration_template 'migration.rb', 'db/migrate/create_elements_table.rb'
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ class CreateElementsTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :elements do |t|
4
+ t.string :elementId
5
+ t.string :frender
6
+ t.text :text
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :elements
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ ;(function($) {
2
+ $.fn.dompath = function(config) {
3
+ var dompath = [],
4
+ node,
5
+ sender = $(this)[0],
6
+ tag;
7
+
8
+ // dompath.push(_buildTag(sender))
9
+
10
+ for (node = sender.parentNode; node; node = node.parentNode) {
11
+ if(node.tagName.toLowerCase() == "html") break;
12
+ dompath.push(_buildTag(node))
13
+ }
14
+
15
+ function _buildTag(node) {
16
+ tag = node.tagName.toLowerCase();
17
+
18
+ if (node.id) {
19
+ tag += "#" + node.id.replace(/ /g, '#');
20
+ }
21
+ else if (node.className) {
22
+ tag += "." + node.className.replace(/ /g, '.');
23
+ }
24
+
25
+ return tag;
26
+ }
27
+
28
+ return dompath.reverse().join(" ");
29
+ }
30
+ })(jQuery);
@@ -0,0 +1,98 @@
1
+ function getElements(frender){
2
+ $.ajax({
3
+ url : '/element/all',
4
+ type : 'GET',
5
+ data : { frender : frender },
6
+ dataType : 'json',
7
+ beforeSend : function() {
8
+
9
+ },
10
+ success : function(data) {
11
+ console.log(data);
12
+ $.each(data, function(i, element){
13
+ if(element['elementId'].length > 1){
14
+ $.each($(element['elementId']), function(j, inner){
15
+ if($(inner).dompath().split(' ').length + 1 == element['elementId'].split(' ').length){
16
+ $(inner).html(element['text'])
17
+ }
18
+ })
19
+ } else {
20
+ $(element['elementId']).html(element['text'])
21
+ }
22
+ })
23
+ $('.frend').show()
24
+ },
25
+ complete : function(data) {
26
+ if (location.hash) {
27
+ location.href = location.hash;
28
+ }
29
+ },
30
+ error : function(XMLHttpRequest, textStatus, errorThrown){
31
+ }
32
+ })
33
+ }
34
+
35
+ function updateElement(element){
36
+ element.parent().toggleClass('focused');
37
+ var id = element.dompath().replace('.enabled', '');
38
+ var text = element.val().trim();
39
+ var frender = element.closest('.frender').attr('id');
40
+
41
+ $.ajax({
42
+ url : '/element/update',
43
+ data : { frender : frender, text : text, id : id },
44
+ type : 'PUT',
45
+ dataType : 'json',
46
+ success : function(data) {
47
+ $.notify('Successfully updated element', 'success')
48
+ },
49
+ error : function(XMLHttpRequest, textStatus, errorThrown){
50
+ $.notify('Failed to update element', 'error')
51
+ }
52
+ });
53
+ }
54
+
55
+ $(window).load(function(){
56
+
57
+ $('.frender').each(function(index, frender){
58
+ getElements(frender.id);
59
+ });
60
+
61
+ var value = '';
62
+ $('.frend.enabled').on('click', function(){
63
+ if(($(this).find('textarea').prop('tagName')) != 'TEXTAREA'){
64
+ var height = $(this).height()
65
+ var width = $(this).width()
66
+ $(this).toggleClass('focused')
67
+ var content = $(this).text()
68
+ value = content
69
+ $(this).html('<textarea id="box-in-frend" class="frend-input-box" />')
70
+ $('#box-in-frend').val(content.trim())
71
+ $(this).find('.frend-input-box').css({
72
+ 'height' : height + 'px',
73
+ 'width' : width + 'px'
74
+ }).select()
75
+ }
76
+ })
77
+
78
+ $('.frend.enabled').on('blur', 'textarea', function(){
79
+ if($(this).val() != value){
80
+ updateElement($(this))
81
+ }
82
+
83
+ if($(this).val().length < 1){
84
+ $(this).parent().html($(this).parent().dompath().replace('.enabled', ''))
85
+ } else {
86
+ $(this).parent().html($(this).val())
87
+ }
88
+ $('.frend').removeClass('focused')
89
+ })
90
+
91
+ $('.frend.enabled').on('keyup', 'textarea', function(){
92
+ var h = $(this).height()
93
+ $(this).css('height', '0px')
94
+ var sh = $(this).prop('scrollHeight')
95
+ var minh = $(this).css('min-height').replace('px', '')
96
+ $(this).css('height', Math.max(sh,minh)+'px')
97
+ })
98
+ })
@@ -0,0 +1,34 @@
1
+ .frend{
2
+ display:none;
3
+ white-space:pre-wrap;
4
+ }
5
+
6
+ .frend-input-box{
7
+ background-color: transparent;
8
+ border: none;
9
+ outline:none;
10
+ font:inherit;
11
+ color:inherit;
12
+ text-align:inherit;
13
+ text-transform:inherit;
14
+ line-height:1em;
15
+ letter-spacing:inherit;
16
+ white-space:inherit;
17
+ vertical-align:inherit;
18
+ padding:0;
19
+ margin:0;
20
+ resize:none;
21
+ }
22
+
23
+ .frend.enabled{
24
+ word-wrap:break-word;
25
+ }
26
+
27
+ .frend.enabled.focused{
28
+ outline:1px dotted green;
29
+ }
30
+
31
+ .frend.enabled:hover{
32
+ cursor:pointer;
33
+ outline:1px dotted green;
34
+ }
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frendms-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyson Holub
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Click a html element to make it an editable textarea. Changes are saved
42
+ to the database via ajax. When the page is loaded the changes will be injected into
43
+ that element.
44
+ email:
45
+ - tyson@tysonholub.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".travis.yml"
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - app/controllers/frendms/element_controller.rb
58
+ - app/models/frendms/element.rb
59
+ - bin/console
60
+ - bin/setup
61
+ - config/routes.rb
62
+ - frendms-rails.gemspec
63
+ - lib/frendms/rails.rb
64
+ - lib/frendms/rails/version.rb
65
+ - lib/generators/frendms/frendms_generator.rb
66
+ - lib/generators/frendms/templates/migration.rb
67
+ - vendor/assets/javascripts/dompath.js
68
+ - vendor/assets/javascripts/frendms.js
69
+ - vendor/assets/stylesheets/frendms.css
70
+ homepage: http://frendms.tysonholub.com
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.2.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: The Front End Management System
94
+ test_files: []