logo
down
shadow

Local data (JSON) in Middleman inside a different path than /data


Local data (JSON) in Middleman inside a different path than /data

By : user2955304
Date : November 22 2020, 10:38 AM
will help you You could try writing a helper method that locates, loads and parses de JSON data for the current page. I haven't actually tested this, but I guess it would look something like this:
code :
# config.rb

helpers do
  def json_data(filename = "data.json")
    container_dir = File.split(current_resource.path).first.split(File::SEPARATOR).first
    json_path = File.join(source, container_dir, filename)
    ActiveSupport::JSON.decode(IO.read(json_path))
  end
end


Share : facebook icon twitter icon
Error building a theme with middleman (can't convert nil into String), /usr/local/bin/middleman:23:in `load'

Error building a theme with middleman (can't convert nil into String), /usr/local/bin/middleman:23:in `load'


By : Angel
Date : March 29 2020, 07:55 AM
I wish this helpful for you J03w is right. It looks like it has something to do with the @ variable you're passing to options in the select_tag.
I couldn't figure it out but came up with an alternative that worked fine using a ruby each loop to create the select lists options.
code :
<ul>
    <li>
        <label>Dropdown with search:</label>
        <select name="color-search" id="color-search" class="chzn-select">
            <% @colorList.shuffle.each do |color| %>
                <option value="<%= color %>"><%= color %></option>
            <% end %>
        </select>
    </li>

    <li>
        <label>Dropdown menu:</label>
        <select name="colors" id="colors" class="uniform">
            <% @colorList.shuffle.each do |color| %>
                <option value="<%= color %>"><%= color %></option>
            <% end %>
        </select>
    </li>
</ul>
path to generated contenful middleman data file

path to generated contenful middleman data file


By : sohailbutt12
Date : March 29 2020, 07:55 AM
To fix this issue 'universal_meganav' is the name of my contentful space. My data folder looks like: , You can access the content as a list:
code :
<% data.universal_meganav.homepage.each do |_, item| %>
  <h1><%= item.pageTitle %></h1>
  <!-- ... etc ... -->
<% end %>
Make a json data on PHP from the name of local folders, and the data inside of text files

Make a json data on PHP from the name of local folders, and the data inside of text files


By : Sean Ran
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I would like to output the jason data which looks like a picture below on PHP. folder is the name of the folder, and title is located at the firstline of info.txt. There are three lines in each info.txt, and those lines are separated just by making new lines (not commas). folder books, and my php file is located under the same folder. How can I write a PHP code? . MY PHP code is here; , To loop over all folders you can use this:
code :
$dirs = array_filter(glob('*'), 'is_dir');
$books = array();
foreach($dirs as $dir){
   $books[$dir] = file($dir)[0];
}
Why is JSON data from local path shows incorrectly in the UITableView?

Why is JSON data from local path shows incorrectly in the UITableView?


By : Nitsan Goren
Date : March 29 2020, 07:55 AM
Any of those help Please check my code :
Changed lookArrayModel type NSMutableArray to [LookModelData]. Like those I did some changes. Please check.
code :
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
     var lookArrayModel = [LookModelData]()

    @IBOutlet weak var myTableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        guard let Path = Bundle.main.path(forResource: "ColorShade", ofType: "json") else { return }

        let url = URL(fileURLWithPath: Path)

        do {
            let data = try Data(contentsOf: url)
            let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers)

            myTableView.dataSource = self
            myTableView.delegate = self

            //Calling the function for adding look
            createLooks(dictionary: json as! NSArray)
            myTableView.reloadData()
        }  catch {
            print(error)
        }
    }

    func createLooks(dictionary:NSArray) {
        for item in dictionary {
            let item1 = item as! NSDictionary
            let lookModal = LookModelData()
            lookModal.Lookname = item1.value(forKey: "Lookname") as? String
            lookModal.LookId = item1.value(forKey: "LookId") as? String
            lookModal.Lookdetails = item1.value(forKey: "Lookdetails") as? String
            lookModal.shadeModel = createshade(shades: item1.value(forKey: "shades") as! NSArray)
            lookArrayModel.append(lookModal)
        }
    }

    func createshade(shades: NSArray) -> [ShadeDescription] {
        var arrayShade = [ShadeDescription]()
        for item in shades
        {
            let item1 = item as! NSDictionary
            let shadeModal = ShadeDescription()
            shadeModal.comboID = item1.value(forKey: "comboID") as? String
            shadeModal.shadeName = item1.value(forKey: "shadeName") as? String
            shadeModal.ShadeType = item1.value(forKey: "ShadeType") as? String
            shadeModal.ShadeCode = item1.value(forKey: "shadeCode") as? String
            arrayShade.append(shadeModal)
        }
        return arrayShade
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return lookArrayModel.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cells = myTableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

        let displayData = lookArrayModel[indexPath.row]

        // You will get like this 
        // print(displayData.LookId!)
        // print(displayData.Lookname!)
        // print(displayData.Lookdetails!)
        // print(displayData.shadeModel!)
        // This is the way to get shade model data
        if let shadeModels = displayData.shadeModel {
            for var shadeModel in shadeModels {
                print(shadeModel.comboID)
                print(shadeModel.ShadeType)
                print(shadeModel.shadeName)
                print(shadeModel.ShadeCode)
            }
        }
        cells.textLabel?.text = String(describing: displayData.Lookname!)

        return cells
    } 
}

class LookModelData
{
    var Lookname:String?
    var LookId:String?
    var Lookdetails:String?
    //Shades Array
    var shadeModel : [ShadeDescription]?
}

class ShadeDescription {
    var ShadeType:String?
    var shadeName:String?
    var comboID:String?
    var ShadeCode:String?
}
Middleman JSON local data

Middleman JSON local data


By : Jose Caramello
Date : March 29 2020, 07:55 AM
this will help ActiveSupport is a Rails module which you don't get with Middleman. Assuming you've installed the JSON gem, you can do something like this:
Related Posts Related Posts :
  • In Ruby on Rails, After send_file method delete the file from server
  • An error occurred while installing nokogiri (1.6.6.2), and Bundler cannot continue
  • How to setup nested routing for a self referencing controller in Rails 4
  • middleman app it is possible to create a contact form?
  • How to refactor this piece of code
  • How can I know if a user has access to all or just some resources with Cancan?
  • How can I run a ruby class from rake file?
  • Send JSON data as post method from rails controller to a web service
  • How to test Controllers under different namespaces and why this test fails?
  • rspec expect condition OR condition
  • Page loads unnecessary queries Ruby On Rails
  • Why "bundle install" try to install outdated version of gems?
  • Rails - Customize model validation error messages but without a database
  • When to switch from cucumber to rspec in the BDD cycle for a login procedure
  • Multipart response for web service
  • How to hide Add new option in Rails Admin
  • Override CollectionProxy find method
  • Rails 4 simple_form has_many through check boxes not saving
  • ruby on rails authentication using devise gem
  • Rails iteration over arrays and hashes
  • Creating inline date_select dropdowns using simple_form and zurb foundation
  • NameError in SongsController#index uninitialized constant Song::FriendlyId
  • Rails how to improve if record exists?
  • omniauth custom request phase form
  • Rails 5 - Saving the absolute current url via a button to a cookie?
  • How can / should I override the `build` method for a my model?
  • Install Rails Failed on OSX 10.8.4
  • ruby on rails - undefined method valid?
  • Users Registration on POST
  • Rails application variables in carrierwave store_dir
  • How to customize simple_form for json nested hash
  • Couldn't find file 'jquery', Sprockets::FileNotFound in StaticPages#home error
  • How should I use the alias_method_chain for the build method?
  • how to create two custom registration forms in devise?
  • Rails 4 link_to Destroy not working in Getting Started tutorial
  • How does ruby on rails dynamically define `find_by_id`, `find_by_name` methods?
  • JBuilder dynamic keys for model attributes
  • `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app
  • What is the Ruby equivalent of Node.js' socket.io?
  • Where rails store standard helpers?
  • how to check expected result matches any of give values in rspec?
  • Form submission to create multiple objects
  • Simple Twitter Login with Rails and Email confirmation
  • Where should helpful functions for my controller go in Rails?
  • Using session variable in the Model or the other way
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • How to pass user attributes to action mailer
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org