is there a way to dynamically make array list of yaml in tmuxinator? - tmuxinator

I would like to use tmuxinator for my work.
I have a folder which has several files not more than 6-7 files.
I want tmuxinator to be configured such that tmux has a window with splitted panes all of which are assigned to a specific file in the folder.
tmuxinator project goes as follows:
name: case
root: <%= ENV["PWD"] %>
windows:
setup:
panes:
- < this list should change dynamically>
any ideas?

I found that it provides loop block as follows:
<%- `find . -maxdepth 1 -type f`.split("\n").each do |item| %>
- <%= item.chomp %>: vim <%= item %>
<%- end >
Thus, the previous my question would be
name: case
root: <%= ENV["PWD"] %>
windows:
setup:
panes:
<%- `find . -maxdepth 1 -type f`.split("\n").each do |item| %>
- <%= item.chomp %>: vim <%= item %>
<%- end >

Another, arguably more flexible option, would be to pass the list of files to tmuxinator using CLI args.
For example, you could change your project config file to the following:
name: case
windows:
- setup:
panes:
<%- args.each do |file| %>
- vim <%= file %>
<%- end %>
... and then start tmuxinator using: tmuxinator start case $(find . -maxdepth 1 -type f)

Related

How to include a variable inside <% include > in a template ejs file?

I have a list of files in a folder that I need to serve inside the parent as a child template. I would like to do something like this:
<% var noScriptBody = 'message-scriptless.ejs' %>
<% include noScriptBody %>
or <%include <%= noScriptBody %>/message-scriptless' %> where <%= noScriptBody %> are the specific child template to include.
For example, I want to include <% include carousel/message-scriptless %> and <% include modal/message-scriptless %> where the path is variable ['carousel', 'modal', etc]
You can include dynamic template like this
for ex. your array passed is pathArray = ['carousel', 'modal', etc]
<% for (const path in pathArray) { %>
<%- include(path +'/message-scriptless.ejs') %>
<% } %>
Here, we iterate through the pathArray & include message-scriptless.ejs from each folder as shown in code above
Please correct me if I misunderstood your requirements
For an example, you can look at this code below: index.ejs
<!-- Only show text -->
<% var noScriptBody = 'message-scriptless' %>
<%= noScriptBody %>
<!-- Show template -->
<% var noScript = 'message-scriptless' %>
<%- include(noScript) -%>
<!-- Show template `message-scriptless` from `carousel` directory -->
<% var carouselMessageSciptLess= 'carousel/message-scriptless' %>
<%- include(carouselMessageSciptLess) -%>
Make sure in the same directory, you've a file message-scriptless.ejs.
Updated: For mapping your variable, you can use this code below:
<% arrayPath.forEach(function(path){
include(path + '/message-scriptless');
}) %>;
From code above, this is an example directory structure:
src > app.js
views > index.ejs
views > message-scriptless.ejs
views > carousel > message-scriptless.ejs
package.json
For more information about this ejs, you can read this documentation.
For an example, you can look at my codeSandbox: https://codesandbox.io/s/example-ejs-app-mhgrh
I hope it can help you.

Varnish chef cookbook director erb file

How do I change the erb file to add first five nodes to director director1 and others to director2
My current erb file.
director director1 round-robin {
<%- if !(node['varnish']['backend_servers']).nil? -%>
<%- node['varnish']['backend_servers'].each do |server| -%>
{ .backend = <%= server[:hostname] %>; }
<%- end %>
<%- end %>
}

Rails 4 Manage File based Translations at Admin End

I am working on a rails website and I need to make it multilingual. I have created yml files for the languages needed for translation.
What I want is to provide the Admin access to files to edit them instead of browsing through the files, by a section in Admin panel. Is there any gem for managing translations through Admin end.
I have never implemented translations before.
By default Rails uses YAML files to store internationalization information. But we are not restricted to use YAML (that is only capable of reading translations but cannot dynamically store them). We can use any database as backend.
To start, you can use this gem: https://github.com/svenfuchs/i18n-active_record
You can change the default backend like that:
I18n.backend = Globalize::Backend::Static.new
You can also use Chan backend to chain multiple backends together.
# config/initializers/locale.rb
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::ActiveRecord.new, I18n.backend)
But, As the translations are accessed frequently in every request page, ActiveRecord is not the best approach. For these reason, a key-value store is the way to go.
You can use Redis database for this:
First install Redis
$ brew install redis
Install redis gem:
# Gemfile
source 'http://rubygems.org'
# ...
gem 'redis'
Now you can change the backend like that:
# config/initializers/locale.rb
I18n.backend = I18n::Backend::KeyValue.new(Redis.new)
Code to add translation:
# /app/views/admin/translations/index.html.erb
<%= form_tag admin_translations_path do %>
<p>
<%= label_tag :locale %><br>
<%= text_field_tag :locale %>
</p>
<p>
<%= label_tag :key %><br>
<%= text_field_tag :key %>
</p>
<p>
<%= label_tag :value %><br>
<%= text_field_tag :value %>
</p>
<p><%= submit_tag "Submit" %></p>
<% end %>
This form will POST to admin/TranslationsController's create action:
# /app/controllers/admin/translations_controller.rb
module Admin
class TranslationsController < ApplicationController
# ....
def create
I18n.backend.store_translations(params[:locale]), {params[:key] => params[:value]}, escape: false)
redirect_to admin_translations_path, notice: "Translation Added"
end
end
end
You can also use redis-i18n gem to do the same: https://github.com/redis-store/redis-i18n

rails chartkick google charts load times extremely long

I am trying to use chartkick to plot some charts with the google charts API. The problem is that the line to set everything up is taking 10-20 seconds to load. Here is the relevant line
<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
Has anyone else had this problem? If so how do you fix it?
I don't know why this is, but I managed to get it to go fast by adding http: in the url
<%= javascript_include_tag "http://www.google.com/jsapi", "chartkick" %>
I generally get around this by grabbing a local copy of the file and only using it in development mode.
<% if Rails.env == "development" %>
<%= #include the local file here %>
<% else %>
<%= javascript_include_tag "http://www.google.com/jsapi", "chartkick" %>
<% end %>
Generally seems ok in production mode.

Conditions in underscore.js templates

How can we check a condition in underscore and print accordingly?
Sample code.
<% if(status==1){ %>
<%= status %>
<% } %>
Is there a way to remove the overlapping %> and <%= ??
I am a php developer and the above code in php would be :
<?php
if($status==1){
echo $status;
}
?>
Is there a way to echo in underscore like "echo"?
yes, try with print();
like:
<% if(status===1) {
print(status);
} %>
docs: http://underscorejs.org/#template